ユーザに文字列を入力させる(3)

newpops2005-09-24


コンソールからユーザに文字列を入力させるサンプルは以下で紹介しました。


今日は、VB.NETのInputBox関数を利用して、ユーザに文字列を入力させるサンプルを紹介します。

VB.NETのInputBox関数を利用する

MSH C:\> [void][Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic")
MSH C:\> $inputMsg = [Microsoft.VisualBasic.Interaction]
 ::InputBox("Input Messages","Title")
MSH C:\> $inputMsg
InputBoxからメッセージを入力
MSH C:\>

利用可能なVB.NETランタイムライブラリは以下のページで参照できます。
Visual Basic ランタイム ライブラリのメンバ

モジュールの参照を変数に取得する

上記サンプルは横に長くなるので、可読性がよくありません。
モジュールの参照を変数に取得して、シンプルに書くと以下のようになります。

MSH C:\> [void][Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic")
MSH C:\> $vbInteraction = [Microsoft.VisualBasic.Interaction]
MSH C:\> $inputMsg = $vbInteraction::InputBox("Input Messages","Title")
MSH C:\> $inputMsg
InputBoxからメッセージを入力