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
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
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

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!
Post Reply