2013-03-20 6 views
5

まあ、Constの式VBScriptの制限を理解しようとしています。私はリテラル以外何も使用できませんでした。論理的に私はこのような何かを行うことができます期待し、「それはすべての算術演算や論理演算子が含まれる」場合、だから、VBScriptでConst式を理解する

Literal or other constant, or any combination that includes all arithmetic or logical operators exceptIs.

:何the docs sayある

Const X = (1 + 2) 

しかし、それはリテラル定数予想される」エラーをもたらします"

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

しかし、私の質問は、標準定数の宣言についてです:上記で行うことができますので、私は、いくつかのレベルでは、1がカンニングすることができます面白い答えhereを見つけました。偶然、ドキュメントが "表現が文字通りのみである"と言った場合、私は決して尋ねません。
他にも(リテラル以外に)何が使えますか?

+0

Microsoftのあいまいさがあります。あなたがカッコなしで最初のものをやると、どうなるでしょうか? – bugmagnet

+0

test.vbs(1,16)Microsoft VBScriptコンパイルエラー:予想されるリテラル定数 – bugmagnet

+0

迅速な返信をありがとう。カッコが切れても、違いはなく、同じエラー – seeker

答えて

3

Script56.chm備考セクションに次の言葉:

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.

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.

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.

上記斜体のビットが主張される「を除くすべての算術演算または論理演算子を含むか、または任意の組合せ」のナンセンスを行います。

+0

ああ、公然と矛盾:)だから、あなたが示唆しているのは、備考のセクションは正しいものですよね? – seeker

+0

それは私のそれを取るだろう、はい。たぶん2人(あるいはそれ以上の人)の人がドキュメントを書いていて、コミュニケーションがうまくやっていなかったか、Const記法がもっ​​と強力になるだろうが、終わりには決してそこにたどり着くことはなかったかもしれない。いずれにしても、私たちは矛盾しており、VBScriptでの私の経験は「備考」の読み方を支持しています。 – bugmagnet

+0

私はあなたの経験に頼り、これを答えとして受け入れます、ありがとう。 – seeker

関連する問題