force string or double interpretation

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
rblack
Pro Scripter
Posts: 87
Joined: Sat Dec 22, 2007 12:39 pm

force string or double interpretation

Post by rblack » Thu Jul 30, 2015 2:46 pm

Hello,

I have the latest Macro Scheduler version (14.2.03) and still have the same problem as in earlier versions.

With bigger and longer working scripts, there is a big problem with ms ducktyping interpreter (string/number automated recognition). I want to force a recognized text to be interpreted as a number, or a string.

I.e. I have a function which reads a number from text on disc, and:

Code: Select all

    let>amount=%r1%-1,50
    wait>1
    lclick
    send>%amount%
sometimes, when the r1 variable is float, i.e r1=75,50 , instead of computing the output, which is "74,00" or "74" , the form is filled with "75,50-1,50" (see attached screenshot). In my experience this happens to various mathematical computations in rare occasions.


I have reported this issue 3 years ago, but it still persists in the latest version. I even sometimes make weird hacks in the code to write variables on disc and read them again, but as you can see, it still doesnt always solve the problem.

I would really, really need to force interpretation to double (float) instead of string. Can I somehow do that?

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: force string or double interpretation

Post by hagchr » Thu Jul 30, 2015 3:09 pm

Hi, have you tried to put curly brackets around the expression (has solved it for me when I had the problem)? Not sure if there is a different global way to do it.

let>amount={%r1%-1,50}

rblack
Pro Scripter
Posts: 87
Joined: Sat Dec 22, 2007 12:39 pm

Re: force string or double interpretation

Post by rblack » Tue Aug 04, 2015 11:50 am

no, this doesn't work. When I add { and } to the calculations, the form is filled with empty variable.

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: force string or double interpretation

Post by hagchr » Tue Aug 04, 2015 5:22 pm

Hi, not sure then what the problem is. Have attached illustration of type of problem I sometimes have and how it can be solved using {} (with {} it is ok, without, it does not resolve).

Code: Select all

VBSTART
    Dim x1, x2
    Sub Test
        x1=75
        x2=1
    End Sub
VBEND

Let>a=1.5

VBRun>Test
VBEval>x1,x1
VBEval>x2,x2

Let>d=%a%+%x1%+%x2%
Let>e={%a%+%x1%+%x2%}

MDL>%d% %CRLF%%e%

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

Re: force string or double interpretation

Post by Marcus Tettmar » Wed Aug 05, 2015 11:38 am

This is not valid syntax:

Let>d=%a%+%x1%+%x2%

This IS valid syntax:

Let>d={%a%+%x1%+%x2%}

Without the { } then you can only do very basic math - e.g. one addition, not two:

let>d=a+x

For anything more involved use the { ... }
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

rblack
Pro Scripter
Posts: 87
Joined: Sat Dec 22, 2007 12:39 pm

Re: force string or double interpretation

Post by rblack » Tue Sep 08, 2015 12:46 pm

Hi Marcus,

unfortunately this doesnt solve the problem, still I have many problems with wrong interpretation of variables to be strings instead of floats. Especially when processing large csv collumns and summing them up.

rblack
Pro Scripter
Posts: 87
Joined: Sat Dec 22, 2007 12:39 pm

Re: force string or double interpretation

Post by rblack » Tue Sep 08, 2015 1:19 pm

This somewhat solves the problem

Code: Select all

Let>DECIMAL_SEPARATOR=,
But first all data needs to be parsed and unified. Where decimal separator is dot, it needs to be replaced to comma.

I deal with all kinds of data input, and all combinations with numbers formats are encountered (decimal separator may be any of the: , or . or " " and at the same time thousand separator can be any of the : , or . or " ").

This means, that before any mathematical operation I have to parse any variable with my own filtering subroutine...
A generic String to Double function would be still very nice to have.

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Re: force string or double interpretation

Post by Jerry Thomas » Wed Sep 09, 2015 4:17 pm

It looks like what we need is access to this
CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator


Marcus, is it possible to get this with MS?

If we have this then in the initial setup we set the separator to the correct character and everything runs
Thanks,
Jerry

[email protected]

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

Re: force string or double interpretation

Post by Marcus Tettmar » Thu Sep 10, 2015 11:58 am

Sorry, what is "CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator" ?? Looks like some property of an object of an object of an object ..... Are you referring to a dialog object?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Re: force string or double interpretation

Post by Jerry Thomas » Thu Sep 10, 2015 1:47 pm

In a C# app, that is how they are able to get the separator character
http://stackoverflow.com/questions/1451 ... -separator
Thanks,
Jerry

[email protected]

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

Re: force string or double interpretation

Post by Marcus Tettmar » Tue Sep 15, 2015 9:33 am

In Macro Scheduler the default decimal separator is alway "."

You can set it by setting DECIMAL_SEPARATOR:
https://www.mjtnet.com/manual/index.htm ... iables.htm
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