How to append 0 to prompted number with EVAL

Discussions and Tech Support related to automating the iMacros Browser or Internet Explorer from any scripting and programming language, such as VBS (WSH), VBA, VB, Perl, Delphi, C# or C++.
Forum rules
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
Post Reply
PaulyWalnuts
Posts: 1
Joined: Wed Dec 11, 2013 5:09 am

How to append 0 to prompted number with EVAL

Post by PaulyWalnuts » Wed Dec 11, 2013 5:15 am

Really simple one but I'm not familiar with JavaScript.
I want to prompt the user for a number, if that number is under 2 digits I want to append a '0' before the first digit, 5->05, 8->08, etc.

What I have so far

Code: Select all

PROMPT Enter<SP>number: !VAR1
SET !VAR1 EVAL("var x = newX(); if (x.length < 2) {'0' + {{!VAR1}}; newX;"})
PROMPT {{!VAR1}}
So if user inputs '5' should output '05' inputs '11' should ignore 0 and output '11'.
Derek, Tech Support
Posts: 12
Joined: Thu Dec 12, 2013 3:27 pm

Re: How to append 0 to prompted number with EVAL

Post by Derek, Tech Support » Fri Dec 13, 2013 3:47 pm

Hello!

Please give this a try:

Code: Select all

PROMPT Enter<SP>number: !VAR1
SET !VAR1 EVAL("var number = \"{{!VAR1}}\"; if (number.length < 2) number = \"0\" + number; number;")
PROMPT {{!VAR1}}
Thanks!
Kind regards,
iMacros Support
Post Reply