Code:
I = 0
Loop
{
I + = 1
Filereadline, line,./url.txt, % I %
If errorlevel <> 0
Break
Run, % line %, Min
Random, stime, 3000,9000
Sleep, % stime %
}
Msgbox. All URL resources are traversed!
Description 1:
Loop is a loop command in the Ahk to repeat a series of commands for a specified number of times. Exit when the break or return command is encountered. The format is:
Loop [, Count]
{
Loop body ......
}
Count cannot be an expression, but can be a variable.
The loop command implies a variable a_index, which is used to record the first loop of the current State. Let's look at an official example:
Loop, 3
{
Msgbox, number of cycles: % a_index %.
Sleep 100
}
Loop
{
If a_index> 25
Break; interrupt cycle
If a_index <20
Continue; skip this loop and start a new loop
Msgbox, the current value of the cyclic variable a_index is % a_index %
}
NOTE 2:
The sleep command is used to wait for the script for a specified time, in milliseconds. For example, if you wait for one second, sleep, 1000
NOTE 3:
In this example, variables are used to store values in the memory. Like most script programs, there is no difference between strings and numbers in the Ahk, and the script will
Row-based judgment, treated differently. variables generally do not need to be declared and can be used directly.
Let's look at an official example:
MySQL var1 = 123
Myvar2 = my string
If myvar2 = my string
{
Msgbox myvar2 contains the string "my string"
}
If myvar1> = 100
{
Msgbox myvar1 contains % myvar1 %, which is larger than 100.
}
The code is easy to understand. Note that the second myvar1 is used as a variable. The percentage symbol is used to include the variable name. The value of myvar1 is displayed in the corresponding position of the dialog box.
To perform a mathematical operation, use the colon equal sign to indicate the operation result of the expression to a variable.
For example: netprice: = price * (1-discount/100)
The I + = 1 code is actually a simplified way of writing I: = I + 1.
Note 4:
Filereadline is a text Operation Command provided by Ahk. The command reads the specified line from the specified text file and assigns a value to the specified variable. Format:
Filereadline, output variable, file name, row number
Errorlevel is a variable embedded in the command. When an error occurs while reading the file (generally because the number of lines reading the file exceeds the limit), errorlevel is assigned a value of 1.
Note 5:
The random command is used to obtain the random number of a specified range. The command format is:
Random: output variable [, minimum, maximum]
Code random, stime, indicates that a random value is obtained between and.