[VBScript] Executeステートメントを使えばロジック動的変更できる
2020年 11月 22日
Executeステートメントで動的変更すると何がうれしいのか?
「動的変更」とは、プログラムの実行中にどの動作を変更する、ということ。Executeステートメントの利用サンプル
i = 1
j = 9
s = "i + j"
MsgBox s
Execute "MsgBox " & s
Execute "MsgBox i * j"
サンプル実行時の動作イメージ
Msgbox s
sの格納文字列をそのまま出力する、だけ。Execute "MsgBox ” & s
sの格納文字列となる「i + j」を実行する。つまり、MsgBoxは「1+9」の実行結果を表示する。Execute "MsgBox i * j"
MsgBox i * j をプログラムとして実行する。つまり、MsgBoxは「1*9」の実行結果を表示する。