vbsの作法 その36
概要
vbsの作法調べてみた。
練習問題やってみた。
練習問題
中学生でも、使えるrpaツールを作れ。
環境
windows7 64bit
方針
取りあえず、電卓を操作する。
インタープリター方式
コマンドがある。
コマンドは'で始まる。
変数が使える。
変数は、$a,$b,$c,$dの4つ。
データは、カンマ区切り。
sendkeysを使う。
命令文
'win 電卓
'{
$a,$b,$c
0,1,2
'}
123{+}
$a
=
命令文の意味
'win 電卓
'{
$a,$b,$c
0,1,2
'}
123{+}
$a
=
アクティブウィンドウとして、電卓を使う。
変数は、a,b,cを使う
繰り返しは、1回。
操作は、123+変数a=を押す。
写真
サンプルコード
Dim App6
Dim Appflg
Set App6 = Createobject("OHIcompo6.srv")
WScript.ConnectObject App6, "App6_"
App6.text = "'win 電卓" & vbcrlf & "'{" & vbcrlf & "$a,$b,$c" & vbcrlf & "0,1,2" & vbcrlf & "'}" & vbcrlf & "123{+}" & vbcrlf & "$a" & vbcrlf & "="
Sub App6_exit()
Appflg = 2
End Sub
Sub App6_ok()
Dim sh
Dim m
Dim lines
Dim win
Dim n
Dim a(100)
Dim b(100)
Dim c(100)
Dim d(100)
Dim line
Dim lin
Dim i
Dim j
Dim v0
Dim v1
Set sh = CreateObject("WScript.Shell")
lines = Split(App6.text, vbCrLf)
For i = 0 To UBound(lines)
If Left(lines(i), 4) = "'win" Then
win = Mid(lines(i), 6)
lines(i) = ""
End If
If Left(lines(i), 2) = "'{" Then
v0 = i + 1
lines(i) = ""
End If
If Left(lines(i), 2) = "'}" Then
v1 = i - 1
lines(i) = ""
End If
Next
If v0 > 0 Then
line = Split(lines(v0), ",")
For i = 0 To UBound(line)
If line(i) = "$a" Then
For j = v0 + 1 To v1
lin = Split(lines(j), ",")
a(j - v0 - 1) = lin(i)
Next
End If
If line(i) = "$b" Then
For j = v0 + 1 To v1
lin = Split(lines(j), ",")
b(j - v0 - 1) = lin(i)
Next
End If
If line(i) = "$c" Then
For j = v0 + 1 To v1
lin = Split(lines(j), ",")
c(j - v0 - 1) = lin(i)
Next
End If
If line(i) = "$d" Then
For j = v0 + 1 To v1
lin = Split(lines(j), ",")
d(j - v0 - 1) = lin(i)
Next
End If
Next
For i = v0 To v1
lines(i) = ""
Next
n = v1 - v0 - 1
End If
m = sh.AppActivate(win)
If m Then
For j = 0 To n
For i = 0 To UBound(lines)
If lines(i) = "" Then
ElseIf lines(i) = "$a" Then
sh.SendKeys a(j)
ElseIf lines(i) = "$b" Then
sh.SendKeys b(j)
ElseIf lines(i) = "$c" Then
sh.SendKeys c(j)
ElseIf lines(i) = "$d" Then
sh.SendKeys d(j)
Else
sh.SendKeys lines(i)
End If
Next
'msgbox j
Next
Else
MsgBox "ウィンドウが見つかりません。"
End If
Set sh = Nothing
End Sub
Do
WScript.Sleep(100)
App6.ping
Loop until Appflg = 2
Set App6 = Nothing
Dim App6
Dim Appflg
Set App6 = Createobject("OHIcompo6.srv")
WScript.ConnectObject App6, "App6_"
App6.text = "'win 電卓" & vbcrlf & "'{" & vbcrlf & "$a,$b,$c" & vbcrlf & "0,1,2" & vbcrlf & "'}" & vbcrlf & "123{+}" & vbcrlf & "$a" & vbcrlf & "="
Sub App6_exit()
Appflg = 2
End Sub
Sub App6_ok()
Dim sh
Dim m
Dim lines
Dim win
Dim n
Dim a(100)
Dim b(100)
Dim c(100)
Dim d(100)
Dim line
Dim lin
Dim i
Dim j
Dim v0
Dim v1
Set sh = CreateObject("WScript.Shell")
lines = Split(App6.text, vbCrLf)
For i = 0 To UBound(lines)
If Left(lines(i), 4) = "'win" Then
win = Mid(lines(i), 6)
lines(i) = ""
End If
If Left(lines(i), 2) = "'{" Then
v0 = i + 1
lines(i) = ""
End If
If Left(lines(i), 2) = "'}" Then
v1 = i - 1
lines(i) = ""
End If
Next
If v0 > 0 Then
line = Split(lines(v0), ",")
For i = 0 To UBound(line)
If line(i) = "$a" Then
For j = v0 + 1 To v1
lin = Split(lines(j), ",")
a(j - v0 - 1) = lin(i)
Next
End If
If line(i) = "$b" Then
For j = v0 + 1 To v1
lin = Split(lines(j), ",")
b(j - v0 - 1) = lin(i)
Next
End If
If line(i) = "$c" Then
For j = v0 + 1 To v1
lin = Split(lines(j), ",")
c(j - v0 - 1) = lin(i)
Next
End If
If line(i) = "$d" Then
For j = v0 + 1 To v1
lin = Split(lines(j), ",")
d(j - v0 - 1) = lin(i)
Next
End If
Next
For i = v0 To v1
lines(i) = ""
Next
n = v1 - v0 - 1
End If
m = sh.AppActivate(win)
If m Then
For j = 0 To n
For i = 0 To UBound(lines)
If lines(i) = "" Then
ElseIf lines(i) = "$a" Then
sh.SendKeys a(j)
ElseIf lines(i) = "$b" Then
sh.SendKeys b(j)
ElseIf lines(i) = "$c" Then
sh.SendKeys c(j)
ElseIf lines(i) = "$d" Then
sh.SendKeys d(j)
Else
sh.SendKeys lines(i)
End If
Next
'msgbox j
Next
Else
MsgBox "ウィンドウが見つかりません。"
End If
Set sh = Nothing
End Sub
Do
WScript.Sleep(100)
App6.ping
Loop until Appflg = 2
Set App6 = Nothing
以上。
Author And Source
この問題について(vbsの作法 その36), 我々は、より多くの情報をここで見つけました https://qiita.com/ohisama@github/items/25f2531b01f0dd8a0e3c著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .