Numeric variables that begin with 0 are treated as strings

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.

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.

Numeric variables that begin with 0 are treated as strings

by scottocs on Sun Mar 19, 2017 6:16 pm

I've been using iMacros for a few days now for Chrome and FireFox, but on each of them, this bug is present.

If I run this sample code, it will add the number of the loop onto the end of the variable.

Code: Select all
VERSION BUILD=844 RECORDER=CR
SET !var0 000123
ADD !var0 {{!loop}}
PROMPT {{!var0}}


This code returns 0001231 then 0001232, etc, etc instead of 000124 and 000125.

I submitted a ticket, but does anyone know how I can work around this problem until it's fixed?

Thanks
scottocs
 
Posts: 2
Joined: Sun Mar 19, 2017 6:06 pm

Re: Numeric variables that begin with 0 are treated as strin

by chivracq on Sun Mar 19, 2017 9:01 pm

scottocs wrote:I've been using iMacros for a few days now for Chrome and FireFox, but on each of them, this bug is present.

If I run this sample code, it will add the number of the loop onto the end of the variable.

Code: Select all
VERSION BUILD=844 RECORDER=CR
SET !var0 000123
ADD !var0 {{!loop}}
PROMPT {{!var0}}


This code returns 0001231 then 0001232, etc, etc instead of 000124 and 000125.

I submitted a ticket, but does anyone know how I can work around this problem until it's fixed?

Thanks

FCIM...! :mrgreen: x2
iMacros for CR v8.4.4, CR54...?, OS...?
iMacros for FF v9.0.3/v8.9.7, FF51/52...?, OS...?

Euh, '!VAR0' is not supported on CR, not sure how you tested on CR...?

"...until it's fixed?", well, I'm not surprised, indeed because of your Leading Zeros, if you specify Leading Zeros, iMacros treats your Var as a String, otherwise they would get trimmed just like in the following:
Code: Select all
SET !var0 000123
'ADD !var0 {{!loop}}
SET !VAR1 EVAL("var v0='{{!VAR0}}'; var n='{{!LOOP}}'; var v1=(v0*1)+(n*1); v1;")
PROMPT {{!VAR1}}
(Tested on iMacros for FF v8.8.2, PM v26.3.3 (=FF47), Win10-x64.)

=> You will get 124/125/126/etc but the Leading Zeros get trimmed...
If you need them, you'll have to handle them yourself with 'EVAL()' depending on the Length of your Result... (... or again "misusing" the 'ADD' Command...!)

Advanced User @iimfun had posted a few months ago some (easier) Solution for a similar Qt with Leading Zeros, check his Posts from maybe 2-3-4 months ago..., or he will post it again if he sees this Thread... :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...
chivracq
 
Posts: 6484
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Numeric variables that begin with 0 are treated as strin

by scottocs on Mon Mar 20, 2017 4:53 am

Well !var0 worked for me in Chrome!

Also, I found my work-around by doing this:

Code: Select all
VERSION BUILD=844 RECORDER=CR
SET !var1 000
SET !var2 123
ADD !var2 {{!loop}}
ADD !var1 {{!var2}}
PROMPT {{!var1}}
scottocs
 
Posts: 2
Joined: Sun Mar 19, 2017 6:06 pm

Re: Numeric variables that begin with 0 are treated as strin

by chivracq on Mon Mar 20, 2017 10:23 am

scottocs wrote:Well !var0 worked for me in Chrome!

Also, I found my work-around by doing this:

Code: Select all
VERSION BUILD=844 RECORDER=CR
SET !var1 000
SET !var2 123
ADD !var2 {{!loop}}
ADD !var1 {{!var2}}
PROMPT {{!var1}}

Hum, FCIM again, but never mind, I guess you won't bother as you found some Workaroud/Solution...

Well, about '!VAR0', it is according to the Wiki not supported on CR, or maybe only since v8.4.4 which was a Major Release with a lot of extra Functionality and Commands implemented from iMacros for FF.

OK, good for your Workaround, that's what I meant with "(... or again "misusing" the 'ADD' Command...!)", but it will only work if you have at least 2 Leading Zeros.
You had not mentioned in what Range you wanted to increment your 123 Counter but it you always keep 3 Zeros, then you can easily adapt "my" Solution to:
Code: Select all
SET !var0 000123
SET !VAR1 EVAL("var v0='{{!VAR0}}'; var n='{{!LOOP}}'; var v1='000'+((v0*1)+(n*1)); v1;")
PROMPT {{!VAR1}}


And I located the Thread I had mentioned with some similar Solution, it was indeed from exactly 4 months ago:
- Re: How to create a variable from one to four positions?
iimfun wrote:You can use this code, for example
Code: Select all
SET counter EVAL("('000' + ({{!LOOP}} - 1)).match(/\\d{4}$/);")
TAG POS=1 TYPE=BUTTON ATTR=TXT:Accepted<SP>{{counter}}

Play it in loop mode. (Current: 1, Max: 10000)

... => Which, adapted to your Case, would give stg like:
Code: Select all
SET !VAR1 123
SET !VAR2 EVAL("('000' + ({{!LOOP}} + {{!VAR1}})).match(/\\d{6}$/);")
'PROMPT {{!VAR2}}

(And this one would handle a variable Length of your Counter to adapt the Number of Zeros...)

(Don't forget to mention your FCI next time you open a Thread, I won't react otherwise... I was "nice" for this one as it was your first Thread on the Forum, I normally don't even read the Qt if FCI is not mentioned, or only to quickly scan for (hidden) Spam, and certainly don't answer... :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...
chivracq
 
Posts: 6484
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)


Return to General Support & Discussions

Who is online

Users browsing this forum: No registered users and 6 guests

cron
-->