[Gambas-user] IsVal()
Benoit Minisini
benoit.minisini at ...2...
Tue Mar 7 17:49:55 CET 2006
On Tuesday 07 March 2006 16:09, R. Stormo wrote:
> Found a solution. The Command IsNumber()
>
> If NOT IsNumber(Textbox1.text) then return
> Now I can check for the number I want
> If val(TextBox1.Text)<2000 then return
Alas this is not a solution. Val() and IsNumber() in Gambas behave completely
differently than in VB.
To do what you want, i.e. to know if a text is a number, do that:
DIM iVal AS Integer
TRY iVal = Val(MyText)
IF ERROR THEN
PRINT "Not a Number"
ELSE
PRINT "The number is "; iVal
ENDIF
I think it's the better way, because if you have a function that tests if a
text is a number, he will do the conversion anyway just for the test, and
then you will have to do it again for getting the number.
So the better is doing the conversion explicitely with a TRY.
Regards,
--
Benoit Minisini
More information about the User
mailing list