Some Experience of Au3

7 views
Skip to first unread message

Chris

unread,
Dec 20, 2012, 10:12:48 AM12/20/12
to qda_...@googlegroups.com


hey jennery, today you met some questions about the script cann't  invoke the .bat file.  pls refer the first item.


                                                                                                                GDDL-QDA-SW Automation Team

 

1.       You should add “#include-once” statement, When you are using #include <xxx.au3> statement at your script header.

2.       If creating an object or using an object, you should free the memory after using it.

3.       When you want to using an external file, such as: .txt / .xml / .ini and other styles file, you’d better to make sure the file is exist or not, and then open it. All actions about operating external file should have a return value.

For example:

 

Using .dll file:

Local $dll = DllOpen("user32.dll")
Local $result = DllCall($dll, "int", "MessageBox", "hwnd", 0, "str", "Some text", "str", "Some title", "int", 0)
DllClose($dll)

Using .txt file:

Local $file = FileOpen("test.txt", 0)
; Check if file opened for reading OK
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf
; Read in 1 character at a time until the EOF is reached
While 1
Local $chars = FileRead($file, 1)
If @error = -1 Then ExitLoop
MsgBox(0, "Char read:", $chars)
WEnd
FileClose($file)

 

4.       This is a very important advice, when you are using an external file, you should use a relative path. For example, if the reference file is the same directory with your script, you should use “@script & “\filename”, not refer it directly.

For example:

This is incorrect:

If fileexist(“test.ini”) then

                ; your code here

Endif

This is correct:

If fileexist(@script & “\test.ini”) then

                ; your statement here.

Endif

 

5.       One script should support multiple platforms. We suggest that your script had better support multiple OS (WIN7/XP/WIN8 & 32Bit/64Bit), multiple languages. So, If possible, we just need the only one script  support multiple platform, not that script for win7/ script for XP etc. 

6.       AutoIt operates in one of three "Window matching" modes, We suggest that using advanced mode to match window, That means you had better match window using  window handle, not window title.

 

For example:

Top-priority mode (handle matching):

 

If winexist(0x0001A3E4) then

               

; Your code here.

 

Endif

 

Bad mode (title matching):

 

If winexist(“window title”) then

 

                ; Your code here.

Endif

 

7.       Rule for naming

 

File Name:

                All initial of filename should be upper case, for example: GetRegistrySubKey.vbs

                Function Name:

1.       The initial of the function name should be upper case, eg: ReadKey()

2.       Using verb as the initial of function name, eg: GetConfig()

 

8.       Action Name

The initial of the action name should be upper case, eg: OpenNewPage()

 

9.       Rule for naming variables

 

1.       Using the first three characters of variable type as the variable’s prefix.

Eg: strPassword

2.       The first character should be lower and the first character of following-up word should be upper case. Eg: intRow

3.       Using “g_” as global variable prefix. Eg: g_strUsername

Variable type

Prefix

Example

Boolean

Bln

blnFound

Byte

Byt

bytRasterData

Date (Time)

Dtm

dtmStart

Double

Dbl

dblTolerance

Error

Err

errOrderNum

Integer

Int

intQuantity

Long

Lng

lngDistance

Object

Obj

objCurrent

String

Str

strFirstName

 

 

File comments:

'******************************************************************************

‘NAME: Controller.vbs

‘Summary:

' DATE : XXXXXX

' Version: 1.0

'******************************************************************************

Function comments:

'******************************************************************************

‘Name: GetConfig

‘Summary: Gets config information from specified sheet of config file

‘Syntax:

‘Parameters:

'               strConfigFile: config file's path, such as "D:\TA\Conf.xls"

'               strSheet: the sheet name, such as "config"

‘Return:

'               A Dictionary which contains "item", "value"

'******************************************************************************

Reply all
Reply to author
Forward
0 new messages