3.1 注释;
3.2 数据类型
$fBoolean1 = True; //boolea值
$fBoolean2 = False
//二进制
$bin = Binary("abc")
$str = String($bin) ; "0x616263"
//指针Pointer
3.3 变量$xX
Local $vVariabl=1; //局部变量
Global $vVariable1="xx", $vVariable2; //全局变量
Const $iConst1 = 1, $iConst2 = 12; //静态变量
//数组
Local $aArray[4];
$aArray[0]="asdasd";
Local $aArray[7] = [3, 7.5, "string"]
$aArray[0] == "xx"; //取值
3.4 操作符
//其它符号同常用含义
& //连接字符串, "one" & 10=="one10"
<> //是否不相等,等同 Not ("string1" == "string2")
And //If $vVar = 5 And $vVar2 > 6 Then
Or //If $vVar = 5 Or $vVar2 > 6 Then
Not //Not 1
? : //三目运算符
3.5 条件语句
//以下所有,如果一个条件成立,则后面所有条件都被忽略
a). If...Then...Else
b). Select...Case
c). Switch...Case
d). Ternary
3.5.1 示例1
#include <Constants.au3>
If $iNumber > 0 Then
MsgBox($MB_SYSTEMMODAL, "Example", "$iNumber was positive!")
ElseIf $iNumber < 0 Then
MsgBox($MB_SYSTEMMODAL, "Example", "$iNumber was negative!")
Else
MsgBox($MB_SYSTEMMODAL, "Example", "$iNumber was zero.")
EndIf
3.5.2 示例2, 代替多分的if else
Select
Case $iNumber > 1 And $iNumber <= 10
MsgBox($MB_SYSTEMMODAL, "Example", "$iNumber was greater than 1")
Case $iNumber > 10 And $iNumber <= 20
MsgBox($MB_SYSTEMMODAL, "Example", "$iNumber was greater than 10")
Case $iNumber > 20 And $iNumber <= 30
MsgBox($MB_SYSTEMMODAL, "Example", "$iNumber was greater than 20")
Case $iNumber > 30 And $iNumber <= 40
MsgBox($MB_SYSTEMMODAL, "Example", "$iNumber was greater than 30")
Case $iNumber > 40
MsgBox($MB_SYSTEMMODAL, "Example", "$iNumber was greater than 40")
EndSelect
3.5.3 示例3
Local $iNumber = 30
Switch Int($iNumber)
Case 1 To 10
MsgBox($MB_SYSTEMMODAL, "Example", "$iNumber was greater than 1")
Case 11 To 20
MsgBox($MB_SYSTEMMODAL, "Example", "$iNumber was greater than 10")
Case 21 To 30
MsgBox($MB_SYSTEMMODAL, "Example", "$iNumber was greater than 20")
Case 31 To 40
MsgBox($MB_SYSTEMMODAL, "Example", "$iNumber was greater than 30")
Case Else
MsgBox($MB_SYSTEMMODAL, "Example", "$iNumber was greater than 40 or less or equal to 0")
EndSwitch
3.6 循环
a). For...Next
b). While...WEnd
c). Do...Until
d). For...In...Next (可遍历对象节点)
e). ExitLoop 终止while/do/for循环(类似break)
ContinueLoop 继续循环(continue)
//示例1
For $i = 5 To 1 Step -1
MsgBox($MB_SYSTEMMODAL, "", "Count down!" & @CRLF & $i)
Next
//示例2
Local $i = 0
While $i <= 10
MsgBox($MB_SYSTEMMODAL, "", "Value of $i is: " & $i)
$i = $i + 1
WEnd
//示例3
Local $i = 0
Do
MsgBox($MB_SYSTEMMODAL, "", "The value of $i is: " & $i) ;
$i = $i + 1 ;
Until $i = 10 ;
//示例4--遍历数组或对象节点
For $Window In $oShellWindows
$sString = $sString & $Window.LocationName & @CRLF
Next
3.7 自定义函数Func...EndFunc
$iDoubled = MyDouble($iNumber);
Func MyDouble($iValue)
$iValue = $iValue * 2
Return $iValue
EndFunc