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

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

问题描述

好吧,我尝试了解 VBScriptConst expressions 的限制.除了文字,我无法使用任何东西.文档说是:

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:

字面量或其他常量,或包含所有算术或逻辑运算符,除了 Is.

所以,如果包括所有算术或逻辑运算符",那么逻辑上我希望我可以做这样的事情:

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

Const X = (1 + 2)

但这会带来错误预期的文字常量".我在here找到了一个有趣的答案,它允许在某种程度上作弊,因此可以通过以下方式完成上述操作:

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 在 Remarks 部分中有以下内容:

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天全站免登陆