2011-10-01から1ヶ月間の記事一覧

VBScript のステートメント、Property Get, Let ステートメント

Class Foo Private m_x Public Property Let x(val) m_x = val End Property Public Property Get x x = m_x Exit Property MsgBox "foo" End Property End Class Set x = new Foo x.x = 1 MsgBox x.x 引数のリストはどう使う?(特に Get の場合は?Let の場…

VBScript のステートメント、Private ステートメント

Option Explicit Private x Function foo MsgBox x End Function x = 1 foo 「Class ブロックで宣言します。」となっていたが、そうでもない??? トップ階層も何かの Class 内なのか???

VBScript のステートメント、Option Explicit ステートメント

Option Explicit Dim x Function foo MsgBox x End Function x = 1 foo Option Explicit Dim x Function foo Dim x MsgBox x End Function x = 1 foo

VBScript のステートメント、On Error ステートメント

まんま On Error Resume Next Err.Raise 6 ' オーバーフロー エラーを発生させます。 MsgBox ("エラー番号 " & CStr(Err.Number) & " " & Err.Description) Err.Clear ' エラーのクリア。 ページでは、MsgBox の最後の括弧が抜けていた

VBScript のステートメント、If...Then...Else ステートメント

If 1=1 Then MsgBox "1=1" Else MsgBox "1<>1" If 1=1 Then MsgBox "1=1" : MsgBox "1=1" Else MsgBox "1<>1"

VBScript のステートメント、Function ステートメント

ByRef の挙動確認 Function foo(ByRef x) x = 10 End Function x = 1 MsgBox x ' 1 foo(x) MsgBox x ' 1 foo x MsgBox x ' 10 再帰 Function foo(x) MsgBox x If x = 0 Then Exit Function End If foo(x-1) End Function foo(2) 外部で宣言された変数への影…

VBScript のステートメント、For Each...Next ステートメント

Dim ary(2) ary(0) = "foo" ary(1) = "bar" ary(2) = "baz" For Each x In ary MsgBox x Next

VBScript のステートメント、For ... Next ステートメント

For x = 1 To 2 Step 2 MsgBox x Next For x = 3 To 1 Step -1 MsgBox x Next Dim a(3) a(0) = 1 For a(0) = 1 To 2 Step 2 ' `for`ループを制御する変数が不正です。 MsgBox a(0) Next

VBScript のステートメント、Exit ステートメント

まんま Sub RandomLoop Dim I, MyNum Do ' 無限のループを設定します。 For I = 1 To 1000 ' ループを 1000 回繰り返します。 MyNum = Int(Rnd * 100) ' ランダムな数字を生成します。 Select Case MyNum ' ランダムな数値を求めます。 Case 17: MsgBox "Cas…

VBScript のステートメント、ExecuteGlobal ステートメント

ほぼまんま Dim X ' グローバル スコープで X を宣言します。 X = "Global" ' グローバルな X に値を代入します。 Sub Proc1 ' プロシージャを宣言します。 Dim X ' ローカル スコープで X を宣言します。 X = "Local" ' ローカルな X に値を代入します。 ' …

VBScript のステートメント、Execute ステートメント

ほぼ、まんま(Print を MsgBox に変更) Dim X ' グローバル スコープで X を宣言します。 X = "Global" ' グローバルな X に値を代入します。 Sub Proc1 ' プロシージャを宣言します。 Dim X ' ローカル スコープで X を宣言します。 X = "Local" ' ローカル…

VBScript のステートメント、Erase ステートメント

まんま Dim NumArray(9) Dim DynamicArray() ReDim DynamicArray(9) ' メモリを割り当てます。 Erase NumArray ' 各要素を再初期化します。 Erase DynamicArray ' 配列が使っていたメモリを解放します。

VBScript のステートメント、Do...Loop ステートメント

Dim ステートメントはスキップ Do MsgBox "foo" Exit Do Loop x = 0 Do While x = 0 MsgBox "foo " & x x = 1 Loop x = 0 Do Until x = 1 MsgBox "foo " & x x = 1 Loop x = 1 Do MsgBox "foo " & x Loop While x = 0 x = 1 Do MsgBox "foo " & x Loop Until…

VBScript のステートメント、Const ステートメント

Const c1 = 1 'c1 = 2 MsgBox c1 'Const c2 = c1 Function foo MsgBox c1 End Function foo Const c3 = 3, c4 = 4 MsgBox c3 & " " & c4

VBScript のステートメント、Class ステートメント

Class foo Public x Public Sub y MsgBox "y" End Sub End Class Set obj = New foo obj.x = "FOO" MsgBox obj.x obj.y

VBScript のステートメント、Call ステートメント

Function foo MsgBox "foo" End Function foo Call foo Function foo(arg) MsgBox arg End Function foo "a" foo("a") Call foo("a")

VBScript のプロパティ、Value プロパティ

まんま Function RegExpTest(patrn, strng) Dim regEx, Match, Matches ' 変数を作成します。 Set regEx = New RegExp ' 正規表現を作成します。 regEx.Pattern = patrn ' パターンを設定します。 regEx.IgnoreCase = True ' 大文字と小文字を区別しないよう…

VBScript のプロパティ、Source プロパティ

まんま On Error Resume Next Err.Raise 6 ' オーバーフロー エラーを発生させます。 MsgBox ("エラー番号 " & CStr(Err.Number) & " " & Err.Description & Err.Source) Err.Clear ' エラーのクリア。

VBScript のプロパティ、Pattern プロパティ \n, \xn

Set r = New RegExp str = "a" & vbTab & "b" r.Pattern = "a\11b" Set Matches = r.Execute(str) MsgBox Matches(0) ' a b r.Pattern = "a\011b" Set Matches = r.Execute(str) MsgBox Matches(0) ' a b str = "aA" r.Pattern = "\x41" Set Matches = r.Exe…

VBScript のプロパティ、Pattern プロパティ \num

Set r = New RegExp str = "1233" r.Pattern = "(.)\1" Set Matches = r.Execute(str) MsgBox Matches(0) ' 33 str = "112233" r.Pattern = "(.)\1(.)\2(.)\3" Set Matches = r.Execute(str) MsgBox Matches(0) ' 112233 str = "112233333" r.Pattern = "(.)…

VBScript のプロパティ、Pattern プロパティ \w, \W

Set r = New RegExp str = "abcdef" r.Pattern = "\w+" Set Matches = r.Execute(str) MsgBox Matches(0) ' abc r.Pattern = "\W+" Set Matches = r.Execute(str) MsgBox Matches(0) ' def

VBScript のプロパティ、Pattern プロパティ \s, \S, \t, \v

Set r = New RegExp str = "abc def" & vbTab & "ghi" & vbVerticalTab r.Pattern = ".\s" Set Matches = r.Execute(str) MsgBox Matches(0) ' c r.Pattern = ".\S" Set Matches = r.Execute(str) MsgBox Matches(0) ' ab r.Pattern = ".\t" Set Matches = r…

VBScript のプロパティ、Pattern プロパティ \f, \n, \r

Set r = New RegExp str = "abc" & vbFormFeed & "def" & vbLf & "ghi" & vbCr r.Pattern = ".\f" Set Matches = r.Execute(str) MsgBox Matches(0) ' c~ r.Pattern = ".\n" Set Matches = r.Execute(str) MsgBox Matches(0) ' f r.Pattern = ".\r" Set Matc…

VBScript のプロパティ、Pattern プロパティ \D

Set r = New RegExp str = "abc123" r.Pattern = "\D+" Set Matches = r.Execute(str) MsgBox Matches(0) ' abc

VBScript のプロパティ、Pattern プロパティ \d

Set r = New RegExp str = "abc123" r.Pattern = "\d+" Set Matches = r.Execute(str) MsgBox Matches(0) ' 123

VBScript のプロパティ、Pattern プロパティ \B

Set r = New RegExp str = "abc" r.Pattern = "\Bc" Set Matches = r.Execute(str) MsgBox Matches(0).FirstIndex ' 2 str = "abc" r.Pattern = "c\B" Set Matches = r.Execute(str) MsgBox Matches.Count ' 0

VBScript のプロパティ、Pattern プロパティ \b

Set r = New RegExp str = "abc" r.Pattern = "\bc" Set Matches = r.Execute(str) MsgBox Matches.Count ' 0 str = "abc" r.Pattern = "c\b" Set Matches = r.Execute(str) MsgBox Matches(0).FirstIndex ' 2

VBScript のプロパティ、Pattern プロパティ [^m-z]

Set r = New RegExp str = "abc" r.Pattern = "[^a-c]" Set Matches = r.Execute(str) MsgBox Matches.Count ' 0 str = "abc" r.Pattern = "[^a-d]" Set Matches = r.Execute(str) MsgBox Matches.Count ' 0 str = "abc" r.Pattern = "[^d-z]" Set Matches =…

VBScript のプロパティ、Pattern プロパティ [a-z]

Set r = New RegExp str = "abc" r.Pattern = "[a-c]" Set Matches = r.Execute(str) MsgBox Matches(0) ' a str = "abc" r.Pattern = "[a-z]" Set Matches = r.Execute(str) MsgBox Matches(0) ' a

VBScript のプロパティ、Pattern プロパティ [^xyz]

Set r = New RegExp str = "abc" r.Pattern = "[^abc]" Set Matches = r.Execute(str) MsgBox Matches.Count ' 0 str = "abc" r.Pattern = "[^abcd]" Set Matches = r.Execute(str) MsgBox Matches.Count ' 0 str = "abc" r.Pattern = "[^d]" Set Matches = …