6

以前、PowerShell利用でオリジナルインプットボックスが作成できないか

という投稿し頂いたアドバイスを元にスクリプトを作成してみました。

皆さんの参考になればと思い投稿させて頂きます。

記載内容にまだまだ問題があるかもしれませんのであしからず。

より良い改善スプリクトがあれば、内容を修正して投稿していただければと思います。

また、アドバイスを頂いた、

スクリプト探究者 様
anothersolution 様

ありがとうございました。

cmd = "powershell.exe -command """ & _
"Add-Type -AssemblyName System.Windows.Forms;" & _
"$form=New-Object System.Windows.Forms.Form;" & _
"$form.Size='300,300';" & _
"$form.Startposition='CenterScreen';" & _
"$form.FormBorderStyle='FixedSingle';" & _
"$form.ControlBox=$false;" & _
"$form.Text='処理条件入力';" & _
"$label1=New-Object System.Windows.Forms.Label;" & _
"$label1.Location='10,20';" & _
"$label1.Size='250,20';" & _
"$label1.Text='処理年月:YYYYMM';" & _
"$textBox1=New-Object System.Windows.Forms.TextBox;" & _
"$textBox1.Location='20,40';" & _
"$textBox1.Multiline=$True;" & _
"$textBox1.AcceptsReturn=$True;" & _
"$textBox1.AcceptsTab=$True;" & _
"$textBox1.WordWrap=$True;" & _
"$textBox1.Anchor=(([System.Windows.Forms.AnchorStyles]::Left)` " & _
"-bor ([System.Windows.Forms.AnchorStyles]::Top)` " & _
"-bor ([System.Windows.Forms.AnchorStyles]::Right)` " & _
"-bor ([System.Windows.Forms.AnchorStyles]::Bottom));" & _
"$textBox1.Size='80,20';" & _
"$textBox1.MaxLength=6;" & _
"$textBox1.Text='YYYYMM';" & _
"$label2=New-Object System.Windows.Forms.Label;" & _
"$label2.Location='10,70';" & _
"$label2.Size='250,20';" & _
"$label2.Text='処理対象選択してください';" & _
"$CheckedBox1=New-Object System.Windows.Forms.CheckBox;" & _
"$CheckedBox1.Location='20,90';" & _
"$CheckedBox1.Size='100,20';" & _
"$CheckedBox1.Text='処理1';" & _
"$CheckedBox2=New-Object System.Windows.Forms.CheckBox;" & _
"$CheckedBox2.Location='20,120';" & _
"$CheckedBox2.Size='100,20';" & _
"$CheckedBox2.Text='処理2';" & _
"$CheckedBox3=New-Object System.Windows.Forms.CheckBox;" & _
"$CheckedBox3.Location='20,150';" & _
"$CheckedBox3.Size='100,20';" & _
"$CheckedBox3.Text='処理3';" & _
"$OKButton=New-Object System.Windows.Forms.Button;" & _
"$OKButton.Location='40,200';" & _
"$OKButton.Size='75,30';" & _
"$OKButton.Text='OK';" & _
"$OKButton.DialogResult=[System.Windows.Forms.DialogResult]::OK;" & _
"$CancelButton=New-Object System.Windows.Forms.Button;" & _
"$CancelButton.Location='130,200';" & _
"$CancelButton.Size='75,30';" & _
"$CancelButton.Text='Cancel';" & _
"$CancelButton.DialogResult=[System.Windows.Forms.DialogResult]::Cancel;" & _
"$form.Controls.Add($label1);" & _
"$form.Controls.Add($textBox1);" & _
"$form.Controls.Add($label2);" & _
"$form.Controls.Add($CheckedBox1);" & _
"$form.Controls.Add($CheckedBox2);" & _
"$form.Controls.Add($CheckedBox3);" & _
"$form.Controls.Add($OKButton);" & _
"$form.Controls.Add($CancelButton);" & _
"$form.AcceptButton=$OKButton;" & _
"$form.CancelButton=$CancelButton;" & _
"$form.Topmost=$True;" & _
"$OKButton.Add_Click({Write-Host 'OK,'" & _
"$textBox1.Text" & _
"','" & _
"$CheckedBox1.Checked" & _
"','" & _
"$CheckedBox2.Checked" & _
"','" & _
"$CheckedBox3.Checked" & _
"});" & _
"$CancelButton.Add_Click({Write-Host 'Cancel,,,,'});" & _
"[void]$Form.ShowDialog();"""

Set objShell = WScript.CreateObject("WScript.Shell")
Set objExec = objShell.Exec(cmd)
Do While objExec.Status = 0
WScript.Sleep 300
Loop

SetUMSVariable $結果$, objExec.StdOut.ReadLine

Set objExec = Nothing
Set objShell = Nothing

結果に内容がカンマ区切りで出力されます。

結果を既存ライブラリの

07文字列操作

02切り出し・分割

 文字列を3つに分割.ums6

のスプリクトを変更し分割数を増加させて各内容を取得する必要があります。

スプリクト一部修正しました。

スプリクト実行時の画像を追加します。

anothersolution 新しいコメントを投稿
回答とコメントは、会員登録(無料)で閲覧できるようになります。