了解VBScript中的Const表达式 [英] Understanding Const expression in VBScript

查看:114
本文介绍了了解VBScript中的Const表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我尝试理解 VBScript 中的 Const 表达式中的限制。除文字外,我什么也不能使用。 文档说是:

Well, I try to understand limitations in Const expressions in VBScript. I was not able to use anything except literals. What the docs say is:


文字或其他常数,或包含所有
算术或逻辑运算符的组合,除了

因此,如果包括所有算术或逻辑运算符,那么从逻辑上讲我可以像这样的东西:

So, if "that includes all arithmetic or logical operators" then logically I expect I can do something like this:

Const X = (1 + 2)

但这带来了错误预期文字常量。我在此处找到了一个有趣的答案,该答案可以使某人在某种程度上作弊,因此可以使用以下方法来完成:

But that brings the error "Expected literal constant". I found an interesting answer here that allows one to cheat, at some level, so the above can be done with:

Execute "Const X = " & (1 + 2)

但是我的问题是关于标准常量声明的。如果文档偶然地说了表达式只能是文字之类的东西,那我就不会问。

那么我还能使用什么(文字之外)?

But my question is about standard constant declaration. If by chance the docs said something like "expression could be ONLY literal", then I would never ask.
So what Else I can use (besides literal)?

推荐答案

Script56.chm在备注部分中说明以下内容:

Script56.chm says the following in the Remarks section:


默认情况下常量是公共的。在过程中,常量始终是私有的。他们的可见度无法更改。在脚本内,可以使用Private关键字更改脚本级常量的默认可见性。

Constants are public by default. Within procedures, constants are always private; their visibility can't be changed. Within a script, the default visibility of a script-level constant can be changed using the Private keyword.

要在同一行上合并多个常量声明,请用逗号分隔每个常量分配。当以这种方式组合常量声明时,如果使用Public或Private关键字,则将它们全部应用。

To combine several constant declarations on the same line, separate each constant assignment with a comma. When constant declarations are combined in this way, the Public or Private keyword, if used, applies to all of them.

您不能使用变量,用户定义的函数或内部VBScript常量声明中的函数(例如Chr)。根据定义,它们不能为常数。 您也不能从任何涉及运算符的表达式中创建常量,也就是说,只允许使用简单常量。在Sub或Function过程中声明的常量是该过程的局部变量。在过程外部声明的常量是在声明该脚本的整个脚本中定义的。您可以在可以使用表达式的任何位置使用常量。

You can't use variables, user-defined functions, or intrinsic VBScript functions (such as Chr) in constant declarations. By definition, they can't be constants. You also can't create a constant from any expression that involves an operator, that is, only simple constants are allowed. Constants declared in a Sub or Function procedure are local to that procedure. A constant declared outside a procedure is defined throughout the script in which it is declared. You can use constants anywhere you can use an expression.

上面的斜体字使或任何包含所有算术或逻辑运算符( Is除外)索赔。

The bit in italics above makes a nonsense of the "or any combination that includes all arithmetic or logical operators except Is" claim.

这篇关于了解VBScript中的Const表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆