基础命令
定义变量
Dim a="UiBot"
数据类型转换
查看数据类型 type()
例:TracePrint("转换前数据类型为:"&Type("1.5"))
转整型 dRet = CInt(1.5)
转小数 dRet = CNumber("1.5")
转字符 dRet = CStr(1)
延时 Delay(1000) #1000毫秒 = 1秒
例: dTime = Time.Now()
sRet = Time.Format(dTime,"yyyy-mm-dd")
TracePrint("当前时间为:"&sRet)
子程序(方法)
Function test(a,b)
Return a+b
End Function
TracePrint ("执行结果:"&test(1,2))
基础语法
条件分支
Select Case
Select Case a + 1
Case 1
TracePrint("This is Case 1")
Case 2
TracePrint("This is Case 2")
Case 3
TracePrint("This is Case 3")
Case Else
TracePrint("This is Case Else")
End Select
IF
If a = 1
TracePrint "yes"
ElseIf a = "UiBot"
TracePrint "no"
Else
TracePrint "no0"
End If
循环
DO LOOP 无限循环
TracePrint("无限执行a加1计算")
a = 1
Do
a = a+1
Loop
DO LOOP Until
先执行语句块 (Block),使用 Until 时,
当条件表达式 (expression) 的值为假(不成立)时则继续执行语句(Block),
当条件表达式 (expression) 的值为真(成立)时退出循环)
TracePrint("令a=1,执行a自增1,直到a等于10,退出循环")
a = 1
Do
a = a + 1
Loop Until a=10
DO LOOP While
使用 While 时,执行 Block 语句块,当 expression 为真时退出循环
TracePrint("令a=1,令a自增1,此时a = 2,符合循环条件a=2,退出循环"
a = 1
Do
a = a + 1
TracePrint a
Loop While a = 2
For Each 遍历数组
temp = [1,2,3,5,6]
For Each value In temp
TracePrint(value)
Next
For Each 遍历字典
t = {'name':'zhangsan','age':14 }
For Each key, value In t
TracePrint(key&' '&value)
Next
For 步长遍历
For i = 0 To 10 step 1
TracePrint(i)
Next
异常
普通异常执行
Try
Mouse.Action(@ui"","left","click",10,{"bContinueOnError": false, "iDelayAfter": 300, "iDelayBefore": 200, "bSetForeground": true, "sCursorPosition": "Center", "iCursorOffsetX": 0, "iCursorOffsetY": 0, "sKeyModifiers": [],"sSimulate": "simulate", "bMoveSmoothly": false})
Catch 变量名
TracePrint("出现异常")
End Try
TracePrint("后续程序")
重复执行多次
a = 0
Try 3
a = a+1
Mouse.Action(@ui"","left","click",10,{"bContinueOnError": false, "iDelayAfter": 300, "iDelayBefore": 200, "bSetForeground": true, "sCursorPosition": "Center", "iCursorOffsetX": 0, "iCursorOffsetY": 0, "sKeyModifiers": [],"sSimulate": "simulate", "bMoveSmoothly": false})
Catch 变量名
TracePrint("出现异常")
End Try
TracePrint(a)
日志
Log.SetLevel 设置日志级别共5类
设置日志级别
Log.SetLevel(3)
写入错误日志
Log.Error("111")
写入警告日志
Log.Warn("222")‘
写入调试日志
Log.Debug("333")
写入普通日志
Log.Info("444")
写入输出日志
TracePrint(a)