IDL 可以将字符串作为代码进行评估吗?

发布于 2024-09-02 16:24:00 字数 222 浏览 6 评论 0原文

IDL 中是否有任何功能可以允许将字符串作为代码进行计算?

或者,如果做不到这一点,是否有一种很好的动态方式在函数中包含 /KEYWORD ?例如,如果我想询问用户想要什么类型的地图投影,有没有办法可以很好地做到这一点,而无需使用 /Projection_Type 关键字的大量 if/case 语句?

即使用户选项数量很少,这些组合也会导致 if/case 语句很快失控,无法处理所有可能的选项。

Is there any functionality in IDL that will allow it to evaluate a a string as code?

Or, failing that, is there a nice, dynamic way of including /KEYWORD in functions? For example, if I wanted to ask them for what type of map projection the user wants, is there a way to do it nicely, without large if/case statements for the /Projection_Type keyword it needs?

With even a small number of user options, the combinations would cause if/case statements to get out of hand very quickly to handle all the possible options.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

jJeQQOZ5 2024-09-09 16:24:01

最好的选择是使用 case 语句,因为您不能相信您的用户会为 Projection_Type 输入与您期望的关键字相同的字符串。

不过,如果您打算执行类似的操作,则可以使用 EXECUTE 函数将字符串视为 IDL 语句:

Result = EXECUTE(String [, QuietCompile] [, QuietExecution])

编辑后添加,还有 CALL_FUNCTION 和 CALL_PROCEDURE 速度更快,但灵活性可能较差。在 IDL 帮助中查找所有内容,看看哪些对您有用。

The best bet is to use a case statement because you can't trust that your user is going to type in the same string for Projection_Type that you're expecting as in the keyword.

Though if you are set on doing something like this, there is the EXECUTE function that treats a string as an IDL statement:

Result = EXECUTE(String [, QuietCompile] [, QuietExecution])

Edited to add, there's also CALL_FUNCTION and CALL_PROCEDURE that are faster but maybe less flexible. Look them all up in the IDL help and see what works for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文