if string is a number - how to findout?
Moderators: JRL, Dorian (MJT support)
if string is a number - how to findout?
hello,
lets say i have the following code
readln>file.txt,1,answer
How can i find if the %answer% is a number not a string ? Is there some cool VB function for this?
lets say i have the following code
readln>file.txt,1,answer
How can i find if the %answer% is a number not a string ? Is there some cool VB function for this?
See this thread. You probably want the last post by Marcus.
propably yes, but if I use the following code:
And run the script, and the first line of test.txt is sth like: 345334a
I get
compile error:1006, line2 column 16, no ")" sign
Code: Select all
VBSTART
Function IsNumber(var)
IsNumber = (LCase(var) = UCase(var)) and isNumeric(var)
End Function
VBEND
Readln>c:\test.txt,1,text
VBEval>IsNumber(%text%),IsNum
MessageModal>IsNum
If>IsNum=True
MessageModal>Its a number!
Endif
I get
compile error:1006, line2 column 16, no ")" sign
Here is a rewrite of my script from the previously referenced thread. See if you can make it fail.
Code: Select all
Let>Text=345334a
Let>IsIntegerFlag=0
SRT>Test
If>%var_count%>1
Let>IsIntegerFlag=1
EndIF
END>Test
Separate>%text%,-,var
GoSub>Test
Separate>%text%,.,var
GoSub>Test
Separate>%text%,%SPACE%,var
GoSub>Test
Separate>%text%,E,var
GoSub>Test
Separate>%text%,e,var
GoSub>Test
Let>test_res=%text%/1
Separate>%test_res%,/,var
GoSub>Test
If>IsIntegerFlag=0
MDL>"%Text%" is an integer
Else
MDL>"%Text%" is NOT an integer
EndIf
Good one!!!
Here's roughly the same technique with a test for a dot which will slip through your original that seems to accurately test for "numbers" but needs this extra step to test for "integers".

Here's roughly the same technique with a test for a dot which will slip through your original that seems to accurately test for "numbers" but needs this extra step to test for "integers".
Code: Select all
Let>text=12345
Separate>text,.,var
If>var_count>1
Let>text3=Nope
Else
Let>text2=text+1
Let>text3=text2-1
EndIf
If>text<>text3
MDL>"%text%" is not an integer
Else
MDL>"%text%" is an integer
Endif
hi there again, now i need sth more complicated. I need to know if a number can be divided by 20, so i need to know if it can be a pure integer. But unfortunately none of your scripts above do that
the if>k>20,end is for security for debuging, because its hard to stop the script.
So i tried many combinations:
Separate>text,.,var, Separate>text,,,var
If>var_count>1, If>var_count>0
But the results are incorrect. For example it tels that 0,05 is an integer, or that 1 is not an integer, or 2 is not an integer. Arent there any build-in functions to chcec if number is an integer?
Code: Select all
Let>text=%k%/20
MessageModal>%text%
let>k=k+1
Separate>text,.,var
If>var_count>1
Let>text3=Nope
Else
Let>text2=text+1
Let>text3=text2-1
EndIf
If>text<text3>"%text%" is not an integer
if>k>20,end
goto>generuj
Else
MDL>"%text%" is an integer
if>k>20,end
Endif
label>end
So i tried many combinations:
Separate>text,.,var, Separate>text,,,var
If>var_count>1, If>var_count>0
But the results are incorrect. For example it tels that 0,05 is an integer, or that 1 is not an integer, or 2 is not an integer. Arent there any build-in functions to chcec if number is an integer?
ok, here is what i needed:
Code: Select all
let>m={%k% MOD 20}
if>m<>0,start