Passing arguments to sub-scripts?

Discussions and Tech Support related to the iMacros Firefox Add-on, including the built-in Javascript scripting interface for playing .js files.

Moderators: Community Moderators, iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

Passing arguments to sub-scripts?

by RCobb1 on Wed Nov 05, 2008 7:46 am

Is there a mechanism for passing prompted arguments to sub-scripts? For example, I have this JavaScript macro that calls other macros as follows:
Code: Select all
iimPlay("Common/login")
iimPlay("Test/DoSomething")
iimPlay("Common/logout")

and I would like to do something more like this:
Code: Select all
iimPlay("PROMPT Enter<SP>target<SP>URL: !VAR1")
iimPlay("Common/login", !VAR1)
iimPlay("Test/DoSomething", !VAR1)
iimPlay("Common/logout", !VAR1)

... so I can collect a human entered value for something like a URL that each of the sub-macros use.

Is this an alien concept that isn't supported? Or, have I simply missed something in the documentation somewhere?

Thanks in advance!
Randy
RCobb1
 
Posts: 20
Joined: Thu Jun 26, 2008 11:19 am

Re: Passing arguments to sub-scripts?

by Tech Support on Wed Nov 05, 2008 2:28 pm

This is a good question! It is supported via the data extraction feature:

In the macro1 use:
PROMPT Enter<SP>target<SP>URL: !VAR1
ADD {{!EXTRACT}} !VAR1
PROMPT Enter<SP>name: !VAR1
ADD {{!EXTRACT}} !VAR1


In the script you can retrieve the "extracted" values:
iimPlay("Macro1")
url = iimGetLastExtract(1)
name = iimGetLastExtract(2)

Then you can pass the values to the next macro2:
iimSet ("myurl", url)
iimSet ("myname", name)
iimPlay("Macro2")

And inside the second macro use:
TAG ... CONTENT={{myurl}}
TAG ... CONTENT={{myname}}
User avatar
Tech Support
 
Posts: 5003
Joined: Tue Sep 20, 2005 12:25 pm

Re: Passing arguments to sub-scripts?

by RCobb1 on Thu Nov 06, 2008 9:07 am

Excellent! That's exactly what I needed.

Many thank yous!
RCobb1
 
Posts: 20
Joined: Thu Jun 26, 2008 11:19 am

Re: Passing arguments to sub-scripts?

by sputnik13 on Sat Feb 27, 2010 11:38 am

No matter what I try I cant seem to pass my var's to my scripts in javacript. I have to use 2 different macros as I need to access two different data source .csv's. Ive tried coding out the 2nd script in javascript in its entirety ... and it works if i use a static value instead of pass in the var [ which is always ends up "undefined" ]

Ive tried multiple examples and none are working

Code: Select all
var macro;
var randArticle;
var randRow
// Generate a number between 2 and 2500
{
iimPlay("myLogin.iim")
randArticle = Math.round(15*Math.random());
iimDisplay(randArticle)
iimSet("randRow","randArticle")
iimDisplay(randRow)
iimPlay("myPost.iim")
sputnik13
 
Posts: 3
Joined: Fri Feb 26, 2010 12:16 am

Re: Passing arguments to sub-scripts?

by ab30 on Sun Nov 06, 2011 7:49 am

Tech Support wrote:It is supported via the data extraction feature:
In the macro1 use:
PROMPT Enter<SP>target<SP>URL: !VAR1
ADD {{!EXTRACT}} !VAR1
PROMPT Enter<SP>name: !VAR1
ADD {{!EXTRACT}} !VAR1


I think there may have a typo error in the code here, it should be:


PROMPT Enter<SP>target<SP>URL: !VAR1
ADD !EXTRACT {{!VAR1}}
PROMPT Enter<SP>name: !VAR1
ADD !EXTRACT {{!VAR1}}


Also, i personally can't get it to work with the new renamed iimGetExtract function:

Code: Select all
ReferenceError: iimGetExtract is not defined (Error code: 991)


But the iimGetLastExtract function works.
ab30
 
Posts: 1
Joined: Sun Nov 06, 2011 6:55 am

Re: Passing arguments to sub-scripts?

by MattBell7 on Mon Nov 07, 2011 6:04 am

iimGetExtract is for v7.40 of the iMacros scripting interface onwards.

I don't know if they've changed it for the Javascript scripting interface in iMacros for FX.

check your version if you're using the full version though
MattBell7
 
Posts: 628
Joined: Thu Nov 26, 2009 4:07 am
Location: United Kingdom

Re: Passing arguments to sub-scripts?

by kind03cn on Tue Jan 06, 2015 10:57 pm

sputnik13 wrote:No matter what I try I cant seem to pass my var's to my scripts in javacript. I have to use 2 different macros as I need to access two different data source .csv's. Ive tried coding out the 2nd script in javascript in its entirety ... and it works if i use a static value instead of pass in the var [ which is always ends up "undefined" ]

Ive tried multiple examples and none are working

Code: Select all
var macro;
var randArticle;
var randRow
// Generate a number between 2 and 2500
{
iimPlay("myLogin.iim")
randArticle = Math.round(15*Math.random());
iimDisplay(randArticle)
iimSet("randRow","randArticle")
iimDisplay(randRow)
iimPlay("myPost.iim")


I think one sentence may be wrong
iimSet("randRow","randArticle") should be changed to
iimSet("randRow",String(randArticle))
kind03cn
 
Posts: 16
Joined: Mon Nov 03, 2014 3:19 pm

Re: Passing arguments to sub-scripts?

by snuhhh on Thu Oct 29, 2015 3:43 am

Hello,

I also would like to pass a VAR created in my iim macro to a vbs loop. The purpose is to read out the number of elements in a drop down list, save it in a variable and then use this number in the vbs script in order to loop through the drop down menu.
In the following code, the counting of dropdown items works fine, but using the GetExtract command only produces a "_undefined_" output. Do you have any idea, why?

Code: Select all
schleife = "CODE:"
   schleife = schleife + "TAG POS=1 TYPE=SELECT FORM=ID:ctl00 ATTR=ID:_pageHeader_fin_dropdown_source EXTRACT=TXTALL" + vbNewLine   
    'Calculate Nb of Options in DDLB (by using the Length of the Array after a 'split()'):
    schleife = schleife + "SET DDLB_Nb_of_Options EVAL(""var s='{{!EXTRACT}}'; var x,y; y=s.split('[OPTION]'); x=y.length; x;"")" + vbNewLine
   'schleife = schleife + "PROMPT DDLB_Nb_of_Options:<SP>_{{DDLB_Nb_of_Options}}_" + vbNewLine
   schleife = schleife + "ADD !EXTRACT {{!DDLB_Nb_of_Options}}" + vbNewLine
   schleife = schleife + "TAG POS=1 TYPE=SELECT FORM=ID:ctl00 ATTR=ID:_pageHeader_fin_dropdown_source CONTENT=#{{loopNumber}} " + vbNewLine
   

   Dim recentyear, ddlb
   ddlb = 1
   recentyear = 0
   do while not (recentyear > ddlb) 'loop until last entry of dropdown reached
      recentyear = recentyear +1
      status = iim.iimSet("loopNumber", Cstr(recentyear))
      status = iim.iimSet("warte", Cstr(warte))
      status = iim.iimPlay(schleife)
      ddlb = iim.iimGetExtract(2)
      WScript.Echo ddlb
      if (recentyear > ddlb) OR (status < 0) then '
         exit do
      end if
   loop
snuhhh
 
Posts: 5
Joined: Thu Oct 22, 2015 1:06 pm


Return to iMacros for Firefox

Who is online

Users browsing this forum: No registered users and 7 guests

-->