random number help
Forum rules
iMacros EOL - Attention!
The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.
Thank you again for your business and support.
Sincerely,
The Progress Team
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
iMacros EOL - Attention!
The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.
Thank you again for your business and support.
Sincerely,
The Progress Team
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
random number help
i am trying to get imacros to generate me some random numbers and put them in a text box.
it looks like this:
VERSION BUILD=6210326 RECORDER=FX
TAB T=1
URL GOTO=http://www.google.com/
//imacros-js:showsteps yes
var randomnumber=Math.floor(Math.random()*11)
iimSet("rnumber", randomnumber);
iimPlay("yourmacro.iim")
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:f ATTR=NAME:q CONTENT=rnumber
i looked through some old questions about the same thing, but they didn't help.
it looks like this:
VERSION BUILD=6210326 RECORDER=FX
TAB T=1
URL GOTO=http://www.google.com/
//imacros-js:showsteps yes
var randomnumber=Math.floor(Math.random()*11)
iimSet("rnumber", randomnumber);
iimPlay("yourmacro.iim")
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:f ATTR=NAME:q CONTENT=rnumber
i looked through some old questions about the same thing, but they didn't help.
-
- Posts: 190
- Joined: Wed Aug 06, 2008 2:38 am
Re: random number help
You are trying to mix .iim and .js code in the same file (probably .iim file from what it looks like). You can't do that. You can have a .js file that calls an existing .iim file, or you can embed the iim commands in a .js file. Here are examples of both using your macro above.lime wrote:i am trying to get imacros to generate me some random numbers and put them in a text box.
it looks like this:
VERSION BUILD=6210326 RECORDER=FX
TAB T=1
URL GOTO=http://www.google.com/
//imacros-js:showsteps yes
var randomnumber=Math.floor(Math.random()*11)
iimSet("rnumber", randomnumber);
iimPlay("yourmacro.iim")
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:f ATTR=NAME:q CONTENT=rnumber
i looked through some old questions about the same thing, but they didn't help.
CallExistingMacro.js (this and ExistingMacro.iim need to be in the Macros directory defined in your settings).
Code: Select all
//imacros-js:showsteps yes
var randomnumber=Math.floor(Math.random()*11)
var retcode=0;
iimSet("rnumber", randomnumber);
retcode = iimPlay("ExistingMacro.iim");
if (retcode < 0) // an error has occured
{
errtext = iimGetLastError();
alert("Error "+retcode+": "+errtext);
}
Code: Select all
VERSION BUILD=6210326 RECORDER=FX
TAB T=1
URL GOTO=http://www.google.com/
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:f ATTR=NAME:q CONTENT={{rnumber}}
Embedded.js
Code: Select all
//imacros-js:showsteps yes
var randomnumber=Math.floor(Math.random()*11)
var macro;
var retcode=0;
macro="CODE: ";
macro+="TAB T=1\n";
macro+="URL GOTO=http://www.google.com/\n";
macro+="TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:f ATTR=NAME:q CONTENT={{rnumber}}\n";
iimSet("rnumber", randomnumber);
retcode = iimPlay(macro);
if (retcode < 0) // an error has occured
{
errtext = iimGetLastError();
alert("Error "+retcode+": "+errtext);
}
Hope this helps.
Re: random number help
thanks! that helped a bunch!!
edit: how can you make the contenent something, and then add a random number to it,
i tried: CONTENT= some content here {{rnumber}}
edit: how can you make the contenent something, and then add a random number to it,
i tried: CONTENT= some content here {{rnumber}}
-
- Posts: 190
- Joined: Wed Aug 06, 2008 2:38 am
Re: random number help
By your example, I assume by "add a random number to it" you mean concatenate the random number to the end of a string and not a mathematical add of two numbers.lime wrote:thanks! that helped a bunch!!
edit: how can you make the contenent something, and then add a random number to it,
i tried: CONTENT= some content here {{rnumber}}
What you attempted looks right to me, and is used with !VAR1, etc in Demo-ExtractAndFill.iim (with the exception that, in a .iim file, you need to represent spaces with <SP>, ie: CONTENT=some<SP>content<SP>here<SP>{{rnumber}}). What happens when you try that? Do you just get your content without the number showing up at the end?
Something to try, just in case, would be converting your random number from a Number to a String in javascript before you pass it to the macro, just to make sure that you are concatenating two string types. Something like
Code: Select all
iimSet("rnumber", randomnumber.toString());
Re: random number help
josephconlin, do you code ECMAscript? Sounds like you don't. Anyways, ECMAscript (what JavaScript was called before M$ called it JScript and Netscape called it Javascript) is weakly typed, i.e. there are no strictly declared types for variables, so there is no need for a "tostring" function.
-
- Posts: 190
- Joined: Wed Aug 06, 2008 2:38 am
Re: random number help
I admit to being more familiar with programming concepts and less familiar with JavaScript. I don't recall ever hearing about ECMAscript.Hello 71 wrote:josephconlin, do you code ECMAscript? Sounds like you don't. Anyways, ECMAscript (what JavaScript was called before M$ called it JScript and Netscape called it Javascript) is weakly typed, i.e. there are no strictly declared types for variables, so there is no need for a "tostring" function.
However, Java is a strongly typed language, and that is the language that is being used to generate the random number. I have seen enough gotchas in my Javascript and iMacros experience to see that sometimes a variable that I think is being interpreted as a Number (or a String) is in fact being interpreted as the other. Number and String functions both exist in JavaScript, including the toString() function, and when I'm in doubt, I use them to make sure I know what type of data I'm working with. Just my preference.