Max length integer 19 positions

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Enricoys
Junior Coder
Posts: 24
Joined: Mon Jan 06, 2014 1:18 pm

Max length integer 19 positions

Post by Enricoys » Mon Apr 06, 2020 9:04 am

I observe the following issue when I read a long string from a CSV file. Sometimes this string is actually a long integer. If this integer is longer then 19 positions I get an error message when I perform an empty string check. Unfortunately the strings in the CSV file are not surrounded with quotes which would have solved this issue.

Let>test=12345678901234567890
// Error parsing expression:
If>{(%test%="")}
MessageModal>Empty string
EndIf

I tried several type conversions (like Concat, Format) however that did not solve this issue. My workaround is to check the length of this string. However, I think this is a bug which has to be solved.

Workaround:
Length>test,LT
If>{(%LT%=0)}
MessageModal>Empty string
EndIf

User avatar
JRL
Automation Wizard
Posts: 3497
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Max length integer 19 positions

Post by JRL » Mon Apr 06, 2020 1:45 pm

Not really a bug. More a consequence of not needing to declare variables and their type. This topic has been discussed since the early days of Macro Scheduler time. Numbers are not supposed to be quoted in a complex expression. The long ago concluded solution is/was to append some text onto the number prior to testing. Something like this:

Code: Select all

Let>AppendedString=~!---!~UniqueNeverToBeEncounteredString~!---!~
Let>String=12345678901234567890
Let>test=%AppendedString%%String%
If>{%test%=%AppendedString%}
MessageModal>Empty string
EndIf
In this case, your solution for checking length and if the result is zero the string is empty is far more elegant. Good job!


You might also simply abandon the complex expression.

Code: Select all

Let>test=12345678901234567890
If>test=
MessageModal>Empty string
EndIf

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Max length integer 19 positions

Post by Marcus Tettmar » Tue Apr 07, 2020 7:44 am

As JRL says this is nothing to do with the length it's to do with type. Your value is a number but your If comparison expects a string.

Another solution is to declare the variable as a string before assigning it. To do this just make sure the first time you declare the variable you assign a string to it:

Code: Select all

//initialise variable to a string type
Let>test={""}

Let>test=12345678901234567890
// Error parsing expression:
If>{(%test%="")}
  MessageModal>Empty string
EndIf
So before reading the value from the file, declare it with Let and set it to a string:

Code: Select all

Let>test={""}
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts