3.10.2011

Enumerated type emulation in VBScript

VBScript: enum(列挙型)のエミュレート

VBScriptで列挙型のようなものを作ってみる。

   1: Function SetEnum(names)
   2:   Dim name, count: count = 0
   3:   For Each name In names
   4:     Call Execute("Const " & name & " = " & count)
   5:     count = count + 1
   6:   Next
   7: End Function

使い方

   1: Option Explicit
   2:  
   3: Call SetEnum(Array("kFirst", "kSecond", "kThird", "kFourth"))
   4: '// Same as ...
   5: '//     Const kFirst = 0
   6: '//     Const kSecond = 1
   7: '//     Const kThird = 2
   8: '//     Const kFourth = 3
   9:  
  10: WScript.Echo kThird  '// Value is 2.

0 件のコメント:

コメントを投稿