Posts: 12,087
Threads: 142
Joined: Dec 2002
What is the code? This error may occur for example when working with OLE types. Example:
DATE d="444444"
QM internally uses standard conversion functions, and, if function fails, it returns error code, and QM just displays error code and associated message.
To show last error line, press F2. To show automatically, set it in Options.
CURRENCY a
CURRENCY b
str c="AMOUNT (100,000.00)"
str d=100000
b=d
c.trim("AMOUNT (")
c.trim (")")
a=c
if a <= b
mes "ok"
else
mes "not ok"
What I am trying to do is get the value of "c" and compare it to the value of "d."
If I use wait 5 before the if statement, seems to work.
Is there also a way to find out the line where the error occurs?
Posts: 12,087
Threads: 142
Joined: Dec 2002
There is one weak place:
c.trim("AMOUNT (")
Here "AMOUNT (" is set of characters that are trimmed. Now this succeeds, and it would also succeed if c would be eg "TNU 100,000.00A". But if c sometimes has different format, this statement may fail to extract the number. Then c would not be numeric, and a=c would throw "...Type mismatch" error.
Regular expressions are ideal to extract numbers and other complex substrings. Try this:
CURRENCY a b="100000"
str c="AMOUNT (100,000.00)"
if(findrx(c "\d+(,\d+)*\.\d\d" 0 2 c)<0) out "number not found"; ret
a=c
mes iif(a<=b "ok" "not ok")
To show last error line, press F2. To show automatically, set it in Options.
Is it possible just to extract the numbers, which is always there, from a string?
Posts: 12,087
Threads: 142
Joined: Dec 2002
Above example extracts number in format xxx.xx or xxx,xxx.xx , etc. Do you have problems with it?
I haven't tried it yet. But what if the numbers does not have a comma or period?
I thought that maybe there's a way to remove any alpha and/or punctuation from a string, leaving the numbers.
Posts: 12,087
Threads: 142
Joined: Dec 2002
This regular expression extracts decimal numbers in any format. Positive, negative, with or without commas, integers or with decimal point, with or without positive or negative exponent.
CURRENCY a b="100000"
[color=blue]str [/color]c="AMOUNT (100,000.00)"
[color=blue]str [/color]rx="[+-]? *\d+(,\d+)*(\.\d+)?([Ee][+-]\d+)?" [color=green];;regexp to extract numbers[/color]
[color=blue]if[/color]([color=blue]findrx[/color](c rx 0 0 c)<0) [color=blue]out [/color]"number not found"; [color=blue]ret[/color]
[color=blue]out [/color]c
a=c
[color=blue]mes iif[/color](a<=b "ok" "not ok")
WORKS LIKE A CHARM!
TYVM :lol: