Tải bản đầy đủ (.pdf) (10 trang)

AutoI Technology Curriculum Book part 15 pdf

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (119.69 KB, 10 trang )

Local $mouseCoordinates[2], $windowStats[4]

; Example 3 - Declaring constant variables
Const $x1 = 11, $y1 = 23, $z1 = 55
Global Const $PI = 3.14159, $E = 2.71828
Local Const $daysWorking = 5




Keyword Reference
ContinueCase
chạy tiếp case tiếp theo, kết thúc case hiện tại
ContinueCase
Parameters
None.
Remarks
continue case có thể dùng trong các cấu trúc có case như select, switch
Related
Select EndSelect, Switch EndSwitch
Example

$msg = ""
$szName = InputBox(Default, "Please enter a word.", "", " M", Default, Default,
Default, Default, 10)
Switch @error
Case 2
$msg = "Timeout "
ContinueCase
Case 1; Continuing previous case
$msg &= "Cancellation"


Case 0
Switch $szName
Case "a", "e", "i", "o", "u"
$msg = "Vowel"
Case "QP"
$msg = "Mathematics"
Case "Q" to "QZ"
$msg = "Science"
Case Else
$msg = "Others"
EndSwitch
Case Else
$msg = "Something went horribly wrong."
EndSwitch

MsgBox(0, Default, $msg)




Keyword Reference
ContinueLoop
chạy tiếp vòng lặp tiếp theo, kết thúc vòng lặp hiện thời
ContinueLoop [level]
Parameters
level số vòng lặp nhảy tiếp, mặc định là 1

Remarks
ContinueLoop có thể dùng trong các vòng lặp như do, while, for


Related
ExitLoop, For, While, Do
Example

;Print all numbers from 1 to 10 except number 7
For $i = 1 to 10
If $i = 7 Then ContinueLoop
MsgBox(0, "The value of $i is:", $i)
Next

;Example of using level is needed.




Keyword Reference
Default
Từ khóa có giá trị mặc định
$var = Default
Parameters
None.
Remarks
từ khóa này đùng để lấy giá trị mặc định (xem ví dụ)
Related
IsKeyWord
Example

WinMove("[active]","",default, default, 200,300) ; just resize the active window
(no move)


MyFunc2(Default,Default)

Func MyFunc2($Param1 = Default, $Param2 = 'Two', $Param3 = Default)
If $Param1 = Default Then $Param1 = 'One'
If $Param3 = Default Then $Param3 = 'Three'

MsgBox(0, 'Params', '1 = ' & $Param1 & @LF & _
'2 = ' & $Param2 & @LF & _
'3 = ' & $Param3)
EndFunc




Keyword Reference
Dim / Global / Local / Const
khai báo biến, hằng, mảng giá trị
Dim [Const] $variable [ = initializer ]
Dim [Const] $array[subscript 1] [subscript n] [ = initializer ]
Tham số
const
[ko bắt buộc] Nếu có thì sẽ tạo ra một biến hằng và ko thể thay đổi giá
trị của nó
$variable tên biến cần khai báo
initializer giá trị đầu cho biến
subscript các kích thước của mảng

Remarks
từ khóa Dim khai báo 1 biến có phạm vi tại vị trí khai báo
Global khai báo một biến toàn cầu có thể truy xuất từ bất kì đâu trong chương

trình, biến toàn cầu đc khai báo khi chương trình chạy và đc giải phóng khi chương
trinhd kết thúc
Local khai báo biến địa phương (trong 1 hàm) nó chỉ đc truy xuất trong pham vi
hàm đó và đc khai báo khi thực hiện hàm và bị xóa khi hàm kết thúc


Chú ý: mặc định autoit dùng biến ko cần khai báo trước, nhưng bạn cũng cod thể
thay đổi điều này bằng AutoItSetOption("MustDeclareVars", 1) thì mọi biến đc
dùng trong chương trình cần phải khai báo trước

Bạn cũng có thể khai báo nhiều biến trên một dòng:
Dim $a, $b, $c

Và khởi tạo các biến:
Dim $a = 2, $b = 10, $c = 20

hằng cũng có thể đc khai báo tương tự
Const $a = 2, $b = 10, $c = 20
Dim Const $d = 21, $e = Exp(1)
Local Const $f = 5, $g = 7, $h = -2


Related
UBound, ReDim, AutoItSetOption
Example

; Example 1 - Declaring variables
Dim $x, $y = 23, $z
Global $_PI = 3.14159, $RADIUS
Local $_daysWorking = 5


; Example 2 - Declaring arrays
Dim $weeklyWorkSchedule[$_daysWorking]
Global $chessBoard[8][8]
Local $mouseCoordinates[2], $windowStats[4]

; Example 3 - Declaring constant variables
Const $x1 = 11, $y1 = 23, $z1 = 55
Global Const $PI = 3.14159, $E = 2.71828
Local Const $daysWorking = 5




Keyword Reference
Do Until
lặp cho đến khi điều kiện đúng thì thôi
Do
statements

Until <expression>
Parameters
expression ddieeuf kiện dừng

Remarks
b1: thực hiện statements
b2: kiểm tra điều kiện expression
nếu đúng thì thoát khỏi vòng lặp thực hiện dòng lệnh tiếp theo
nếu sai thì quay lại b1
Related

ContinueLoop, ExitLoop, While WEnd, For Next
Example

$i = 0
Do
MsgBox(0, "Value of $i is:", $i)
$i = $i + 1
Until $i = 10




Keyword Reference
Enum
liệt kê hằng
[scope] Enum [Step <stepval>] <constantlist>
Parameters
scope phạm vi (local, global)
stepval bước nhảy (+n, -n, *n) mặc định là +1
constantlist

danh sách liệt kê các hằng

Remarks
Theo mặc định hằng đầu tiên có giá trị = 0 và các hằng tiếp theo lần lượt nhận giá
trị tăng thêm 1
Related
Example

Global Enum $E1VAR1, $E1VAR2, $E1VAR3

MsgBox(4096, "", "Expect 0: " & $E1VAR1)
MsgBox(4096, "", "Expect 1: " & $E1VAR2)
MsgBox(4096, "", "Expect 2: " & $E1VAR3)

Global Enum $E2VAR1 = 10, $E2VAR2, $E2VAR3 = 15
MsgBox(4096, "", "Expect 10: " & $E2VAR1)
MsgBox(4096, "", "Expect 11: " & $E2VAR2)
MsgBox(4096, "", "Expect 15: " & $E2VAR3)

Global Enum Step *2 $E3VAR1, $E3VAR2, $E3VAR3
MsgBox(4096, "", "Expect 1: " & $E3VAR1)
MsgBox(4096, "", "Expect 2: " & $E3VAR2)
MsgBox(4096, "", "Expect 4: " & $E3VAR3)




Keyword Reference
Exit
Kết thúc ngay script
Exit [return code]
Parameters
return code

là một số nguyên đc trả lại khi kết thúc chương trình
mặc định là 0
trả lại code = 1 nghĩa là chương trình bị "cưỡng chế" kết thúc (bị end
task ko phải tự nó thoát mà do 1 chương trình khác "giết" nó)

Remarks

các cách viết sau đều hợp lệ Exit, Exit 0, Exit(0). Tuy nhiên, Exit() là không hợp
lệ.

code return có thể được đọc bởi hàm OnAutoItExit() bởi @EXITCODE.
Related
ExitLoop, Func OnAutoItExit ()
Example

;First Example
Exit

;Second Example
; Terminate script if no command-line arguments
If $CmdLine[0] = 0 Then Exit(1)

;Third Example
; Open file specified as first command-line argument
$file = FileOpen($CmdLine[1], 0)

; Check if file opened for reading OK
If $file = -1 Then Exit(2)

; If file is empty then exit (script is successful)
$line = FileReadLine($file)
If @error = -1 Then Exit

;code to process file goes here
FileClose($file)
Exit ;is optional if last line of script





Keyword Reference
ExitLoop
Thoát khỏi vòng lặp
ExitLoop [level]
Parameters
level số vòng lặp cần thoát, mặc định là 1 tức là thoát khỏi vòng lặp hiện tại


Remarks
ExitLoop có thê thoát khỏi vòng lặp While, Do, For
Related
ContinueLoop, Exit, For, Do, While
Example

$sum = 0
While 1 ;use infinite loop since ExitLoop will get called
$ans = InputBox("Running total=" & $sum, _
" Enter a positive number. (A negative number exits)")
If $ans < 0 Then ExitLoop
$sum = $sum + $ans
WEnd
MsgBox(0,"The sum was", $sum)




Keyword Reference

False / True

×