AutoI Technology Curriculum Book part 16 potx

8 198 0
AutoI Technology Curriculum Book part 16 potx

Đang tải... (xem toàn văn)

Thông tin tài liệu

Boolean giá trị cho sử dụng trong biểu thức logic $var = False $var = True Parameters None. Remarks ? Related Example $bool= False if NOT $bool = true Then Msgbox(0,"Bool comparison", "OK") Keyword Reference For To Step Next vòng lặp biết trước số lần lặp For <variable> = <start> To <stop> [Step <stepval>] statements Next Parameters variable biến đếm start giá trị bắt đầu stop giá trị kết thúc stepval bước nhảy, sau mỗi vòng lặp biến đếm sẽ đc tăng giá theo step, mặc định là +1 Remarks Variable sẽ tự động được khai báo với phạm vi local, ngay cả khi MustDeclareVars là true. b1: gán giá trị start cho variable b2: kiểm tra biến đếm có nằm trong miền giá trị [start stop] ko nếu đúng làm bước 3 nếu sai thoát khỏi vòng lặp b3: thực hiện statements sau đó tăng variable theo stepval tiếp theo quay lại bước 2 Related ContinueLoop, ExitLoop Example For $i = 5 to 1 Step -1 MsgBox(0, "Count down!", $i) Next MsgBox(0,"", "Blast Off!") Keyword Reference For In Next vòng lặp biết trước số lần lặp For <$Variable> In <expression> statements Next Parameters Variable biến nhận giá trị expression Phải là một biểu kết quả trong một Object, hoặc một Array với ít nhất một phần tử Remarks Variable sẽ tự động được khai báo với phạm vi local, ngay cả khi MustDeclareVars là true. b1: cho Variable nhận giá trị của expression b2: thực hiện statements b3: kiểm tra expression nếu còn giá trị thì quay lại b1 nếu ko thì thoát khỏi vòng lặp Related With EndWith, ObjEvent (COM Error handler) Example ;Using an Array Dim $aArray[4] $aArray[0]="a" $aArray[1]=0 $aArray[2]=1.3434 $aArray[3]="test" $string = "" FOR $element IN $aArray $string = $string & $element & @CRLF NEXT Msgbox(0,"For IN Arraytest","Result is: " & @CRLF & $string) ;Using an Object Collection $oShell = ObjCreate("shell.application") $oShellWindows=$oShell.windows if Isobj($oShellWindows) then $string="" for $Window in $oShellWindows $String = $String & $Window.LocationName & @CRLF next msgbox(0,"","You have the following windows open:" & @CRLF & $String) else msgbox(0,"","you have no open shell windows.") endif Keyword Reference Func Return EndFunc Định nghĩa một hàm mới Func functioname ( [Const] [ByRef] $param1, , [Const] [ByRef] $paramN, $optionalpar1 = value, ) [Return [value]] EndFunc Parameters Các thông số được thiết lập của bạn. Bạn sau đó gọi hàm như thế nào khác thì sẽ đc xây dựng trong hàm. Remarks từ khóa Const là tùy chọn (có cũng đc ko có cũng đc) nếu có chương trình sẽ tạo ra một hằng và giá của nó ko thay đổi đc từ khóa ByRef cũng là tùy chọn, nếu có nó xác định tham số đó là "tham biến" Thứ tự của các từ khóa ByRef và Const không phải là điều quan trọng biến mảng cũng đc truyền theo tên bình thường, và biến mảng cũng có thể đc return macro @NUMPARAMS cho biết có bao nhiêu tham số đc sử dụng từ khóa return để kết thúc hàm và trả lại một giá trị nếu cần chú ý không thể xây dựng 1 hàm bên trong 1 hàm khác Related Dim/Global/Local, #include, Const Example ; Sample script with three user-defined functions ; Notice the use of variables, ByRef, and Return $foo = 2 $bar = 5 msgBox(0,"Today is " & today(), "$foo equals " & $foo) swap($foo, $bar) msgBox(0,"After swapping $foo and $bar", "$foo now contains " & $foo) msgBox(0,"Finally", "The larger of 3 and 4 is " & max(3,4)) Exit Func swap(ByRef $a, ByRef $b) ;swap the contents of two variables Local $t $t = $a $a = $b $b = $t EndFunc Func today() ;Return the current date in mm/dd/yyyy form return (@MON & "/" & @MDAY & "/" & @YEAR) EndFunc Func max($x, $y) ;Return the larger of two numbers If $x > $y Then return $x Else return $y EndIf EndFunc ;End of sample script Keyword Reference Func OnAutoItStart () EndFunc định nghĩa một hàm sẽ đc gọi trước khi script chạy Func OnAutoItStart ( ) EndFunc Parameters None. Remarks Tên của các chức năng không thể thay đổi vì nó cần cho "OnAutoItExit". Related Func OnAutoItExit (), OnExitFunc (Option) Example MsgBox(0,"","first statement") Func OnAutoItStart() MsgBox(0,"","Before first statement") EndFunc Keyword Reference Func OnAutoItExit () EndFunc định nghĩa một hàm sẽ đc gọi sau khi script thoát Func OnAutoItExit ( ) EndFunc Parameters None. Remarks trong hàm có thể sử dụng @ExitCode để lấy mã mà chương trình thoát trả lại. Các hình thức đi theo sẽ đc @ExitMethod nhận lại 0 Tự nhiên thoát 1 Thoát do chương trình chỉ định 2 thoát bằng tray icon trên khay hệ thống . đổi vì nó cần cho "OnAutoItExit". Related Func OnAutoItExit (), OnExitFunc (Option) Example MsgBox(0,"","first statement") Func OnAutoItStart() MsgBox(0,"","Before. ;End of sample script Keyword Reference Func OnAutoItStart () EndFunc định nghĩa một hàm sẽ đc gọi trước khi script chạy Func OnAutoItStart ( ) EndFunc Parameters None. Remarks. statement") EndFunc Keyword Reference Func OnAutoItExit () EndFunc định nghĩa một hàm sẽ đc gọi sau khi script thoát Func OnAutoItExit ( ) EndFunc Parameters None. Remarks trong

Ngày đăng: 07/07/2014, 01:20

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan