Use variables in imacros

Source: Internet
Author: User
Tags microsoft access database


In this tutorial, we will learn how to use variables in imacros.
There are two types of variables in imacros: built-in variables and User-Defined variables.

Built-in variables:
Built-in variables are used to define macro behaviors of certain performance, such as macro supervalues:
Set! Timeout 33
The preceding statement indicates that the page timeout time is set to 33 S.
There are three special built-in variables ,! Var1 ,! Var2 and! Var3. These variables can be set to any custom value.
For example:
Set! Var1 helloworld
Set! Var1 is helloworld (PS: <SP> represents a space <br> represents a carriage return)
Prompt pleaseentertext! Var1
An input box is displayed. The content you enter in the input box will be uploaded! In var1.

User-Defined variables:
User-Defined variables are input variables during external control. For example, in the Visual BASIC script example, this will be shown as follows:
Iret = imacros. iimset ("-var_item", "15") (PS: You can set the variable item as follows: iimset ("item", "15)
Replace {item} with the value to be replaced in the called place.

imacros allows you to specify a text file, CSV file, as input.
for example, a CSV file:
"artist", "album title", "price"
"Beatles", "Abbey Road ", "13.49"
"Beatles", "The Beatles 25.49, 3", ""
"symbol art", "symphonies No. 40 & 41 ", "9.98"
"courier art", "Requiem", "7.50"
the file name is onlineauction.csv
now we need to tell the imacros macro how to locate the data input file. For this reason, we use built-in variables! Datasource
set! Datasource onlineauction.csv
if you do not use any path information, the datasource path is located in the directory of the standard data source by default. You can specify this path in the Options dialog box. The default path is the CES folder under the imacros data path.
after selecting the data source file, we need to tell the imacroscsv file the number of columns. We use it! Performance_columns variable settings:
set! Performance_columns 3
This number must exactly match the number of columns in the input file
since we want to insert all the datasets, we need a macro loop to control them.
set! Performance_line {{! Loop} (PS: loop indicates the number of script loops. Do you still remember the loop running button of play loop ~~)
This built-in variable is used to set the rows for reading files.
now we have prepared all the preparations. Next we will read the corresponding data.
tag type = input: text form = listing ATTR = Name: Name content = {{! Col1 }}< br> tag type = input: text form = listing ATTR = Name: album content = {{! Col2 }}< br> tag type = input: text form = listing ATTR = Name: price content = {{! Col3 }}< BR> {{! Col1 }}indicates reading the corresponding first column of Data

Database
This example only applies to the Professional Edition.
Imacros can read data directly from the database.
In this exampleCodeConnect the Visual BASIC script to the Microsoft Access database :))
'Open Database
Set rs = Createobject ("ADODB. Connection ")
Rs. Open ("driver = {Microsoft Access Driver (*. mdb)}; DBQ = "_
& Mypath & "IIM-TEST-SUBMIT.MDB ")

'Use SQL to select information
SQL = "select * From Table1"
Set rs = Rs. Execute (SQL)

'Start imacros
Set iim1 = Createobject ("imacros ")
Iret = iim1.iiminit
Iret = iim1.iimdisplay ("submitting data from MS access ")

'Loop through result Dataset
Do until Rs. EOF
'Set the variable
Iret = iim1.iimset ("-var_fname", Rs. Fields (0 ))
Iret = iim1.iimset ("-var_lname", Rs. Fields (1 ))
Iret = iim1.iimset ("-var_address", Rs. Fields (2 ))
Iret = iim1.iimset ("-var_city", Rs. Fields (3 ))
Iret = iim1.iimset ("-var_zip", Rs. Fields (4 ))
Iret = iim1.iimset ("-var_STATE-ID", Rs. Fields (5 ))
Iret = iim1.iimset ("-var_COUNTRY-ID", Rs. Fields (6 ))
Iret = iim1.iimset ("-var_email", Rs. Fields (7 ))
'Run the macro
'Note: this is the same macro, as in the FILE-2-WEB-METHOD2.VBS example script !!!
Iret = iim1.iimplay ("wsh-submit-2-web ")
If iret <0 then
Msgbox iim1.iimgetlasterror ()
End if
Rs. movenext
Loop

Iret = iim1.iimdisplay ("done! ")
Iret = iim1.iimexit
Wscript. Quit (0)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.