Add leading zero with Eval Command

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.
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
TuanMinh
Posts: 1
Joined: Tue Mar 26, 2019 2:12 pm

Add leading zero with Eval Command

Post by TuanMinh » Tue Mar 26, 2019 3:03 pm

Good day all.

I'm new with iMacros and this is the first matter I have.
Can you please take a look at my code below. I've tried to use EVAL command but the demo/example is too complicated.
I only know code similar to VB, not JS, HTML ... so please kindly understand.

Code: Select all

VERSION BUILD=12.0.501.6698
TAB T=1
TAB CLOSEALLOTHERS
'SET !PLAYBACKDELAY 0.00

SET !DATASOURCE C:\\Users\\User\\Desktop\\001.csv
SET !LOOP 1
SET !DATASOURCE_LINE {{!LOOP}} 

URL GOTO=file://MasterPC/Report.html
TAG POS=2 TYPE=INPUT:TEXT ATTR=CLASS:txtNormal_1 CONTENT={{!COL1}}
The case is as below.
The 001.csv contains some columns to fill to Report.html.
1. Is that possible in any case to keep the leading zero in CSV file so after the file is saved from Excel, iMacros still can read the correct one, as 001 but not 1 as now.
2. How can I put command to check/revise the COL1 so if it detects COL1 < 10, to put COL1 as 01 (then 001 to be similar).

Im using Windows 10 / iMacro Editor 12.0.0.151 / Excel 2017 / IE11.
Thanks for your reading.
chivracq
Posts: 8528
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Add leading zero with Eval Command

Post by chivracq » Tue Mar 26, 2019 3:31 pm

TuanMinh wrote:
Tue Mar 26, 2019 3:03 pm

Code: Select all

Windows 10 / iMacro Editor 12.0.0.151 / Excel 2017 / IE11.
Good day all.

I'm new with iMacros and this is the first matter I have.
Can you please take a look at my code below. I've tried to use EVAL command but the demo/example is too complicated.
I only know code similar to VB, not JS, HTML ... so please kindly understand.

Code: Select all

VERSION BUILD=12.0.501.6698
TAB T=1
TAB CLOSEALLOTHERS
'SET !PLAYBACKDELAY 0.00

SET !DATASOURCE C:\\Users\\User\\Desktop\\001.csv
SET !LOOP 1
SET !DATASOURCE_LINE {{!LOOP}} 

URL GOTO=file://MasterPC/Report.html
TAG POS=2 TYPE=INPUT:TEXT ATTR=CLASS:txtNormal_1 CONTENT={{!COL1}}
The case is as below.
The 001.csv contains some columns to fill to Report.html.
1. Is that possible in any case to keep the leading zero in CSV file so after the file is saved from Excel, iMacros still can read the correct one, as 001 but not 1 as now.
2. How can I put command to check/revise the COL1 so if it detects COL1 < 10, to put COL1 as 01 (then 001 to be similar).

Im using Windows 10 / iMacro Editor 12.0.0.151 / Excel 2017 / IE11.
Thanks for your reading.
1. Is that possible in any case to keep the leading zero in CSV file so after the file is saved from Excel, iMacros still can read the correct one, as 001 but not 1 as now.
Try...:

Code: Select all

SET !VAR1 EVAL("var c1='{{!COL1}}'; var z=c1.toString(); z;")
PROMPT COL1:<SP>_{{!COL1}}_<BR>VAR1:<SP>_{{!VAR1}}_
(Not tested...)

2. How can I put command to check/revise the COL1 so if it detects COL1 < 10, to put COL1 as 01 (then 001 to be similar).
For 1x "0" (=> "01"), try...:

Code: Select all

SET !VAR1 EVAL("var c1='{{!COL1}}'; var z; if(c1*1<10){z='0'+c1;} else{z=c1;}; z;")
PROMPT COL1:<SP>_{{!COL1}}_<BR>VAR1:<SP>_{{!VAR1}}_
(Not tested...)

For 2x "0" (=> "001"), try:

Code: Select all

SET !VAR1 EVAL("var c1='{{!COL1}}'; var z; if(c1*1<10){z='00'+c1;} else if(c1*1<100){z='0'+c1;} else{z=c1;}; z;")
PROMPT COL1:<SP>_{{!COL1}}_<BR>VAR1:<SP>_{{!VAR1}}_
(Not tested...)
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
Posts: 8528
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Add leading zero with Eval Command

Post by chivracq » Wed Mar 27, 2019 6:46 pm

Hum..., and I guess I'm already not very-very "impressed" by the Follow-up, more than 24h later..., Grrr...! :shock:

Okay, fair enough..., but I don't try a 2nd time to help Users, if they don't follow up on their Threads..., just saying... :idea:
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
Post Reply