Archive for iMacros

iMacros Select Random Datasource Line

If you’re like me, you want things to be as random as possible, this means selecting just about everything from a CSV or database. If you want to select a random line from your datasource, just create as many columns you need and use this code.


URL GOTO=http://www.graphpad.com/quickcalcs/randomN1.cfm
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:CFForm_1 ATTR=ID:low CONTENT=1
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:CFForm_1 ATTR=ID:hi CONTENT=10
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:CFForm_1 ATTR=NAME:Random
TAG POS=18 TYPE=TD ATTR=TXT:* EXTRACT=TXT
'
SET !VAR1 {{!EXTRACT}}
'
CMDLINE !DATASOURCE datasource.csv
SET !DATASOURCE_COLUMNS 1
SET !DATASOURCE_LINE {{!VAR1}}

The last three lines are what choose the random line in your CSV. Line 2 sets the low range and line 3 sets the high range of your random choice, so if you have a datasource with 55 lines, set the following.

TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:CFForm_1 ATTR=ID:hi CONTENT=10

Hope that helps you use iMacros in a better and more random way!

iMacros Random Number Variable

I’ve been using iMacros a lot lately and absolutely love it! Here is a quick and easy snippet of code to set your variable to be a random number between X and Y.

URL GOTO=http://www.graphpad.com/quickcalcs/randomN1.cfm
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:CFForm_1 ATTR=ID:low CONTENT=1
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:CFForm_1 ATTR=ID:hi CONTENT=10
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:CFForm_1 ATTR=NAME:Random
TAG POS=18 TYPE=TD ATTR=TXT:* EXTRACT=TXT
'
SET !VAR1 {{!EXTRACT}}
SET !EXTRACT NULL

This bit of code will choose a random number between 1 and 10 (you can change the high and low number on lines 2 and 3), extract that random number then set your random number into an iMacros variable !VAR1. It then erases the !EXTRACT so you’re ready to move onto something else.

You can then use !VAR1 anywhere else you need to use that random number. You can even use it multiple times!