Jump to content

Recommended Posts

Posted

Hello users, i have problem with function IsNumber.

This function work good if i use it like this :

$result = IsNumber( 42 )
MsgBox( 0, "", $result)

This return 1 ( working)

But if i need use changer [ IsNumber( $changer ) ]

This don't work, always return 0, even it's numeric, $changer working good cuz i test it like that :

$changer = FileReadLine( "test.txt", 1)
MsgBox( 0, "", $changer)
$result = IsNumber( $changer )
MsgBox( 0, "", $result)

Please help :) thanks

Posted (edited)

$result = StringIsDigit($changer)

I used the wrong Command. :)

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

Whoops! :) StringIsDigit()

All I did was look in the Help File under String Management ;)

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

The reason is FileReadLine returns a 'String'.

$changer = 123

$result = IsNumber( $changer )
MsgBox( 0, "Number", $changer & " response : " & $result)

$result = IsString( $changer )
MsgBox( 0, "String", $changer & " response : " & $result)


$changer = "123"
$result = IsNumber( $changer )
MsgBox( 0, "Number", $changer & " response : " & $result)

$result = IsString( $changer )
MsgBox( 0, "String", $changer & " response : " & $result)


$result = StringIsDigit("123")
$result = IsNumber( $changer )
MsgBox( 0, "Number", $changer & " response : " & $result)

$result = IsString( $changer )
MsgBox( 0, "String", $changer & " response : " & $result)
Posted

I believe I went about it the long way, seeing as how there is a built in.

$changer = FileReadLine( "c:\test1.txt", 2)


If StringRegExp ($changer , '(\D)') Then
    msgbox (0, '' , 'not a number')
    Else
$result = Number($changer)
MsgBox( 0, "", $result)
Endif

  Reveal hidden contents

Posted

  On 1/21/2011 at 7:25 PM, 'iamtheky said:

I believe I went about it the long way, seeing as how there is a built in.

$changer = FileReadLine( "c:\test1.txt", 2)


If StringRegExp ($changer , '(\D)') Then
    msgbox (0, '' , 'not a number')
    Else
$result = Number($changer)
MsgBox( 0, "", $result)
Endif

This code fails because if $changer = "A1" or "2B", etc it will tell you it's a number and it's not...

ZacUSNYR had the correct reason: FileReadLine returns a string. StringIsDigit() is the correct test.

Posted (edited)

I added both of those to a text file (with and without quotes, just to be sure) and my code returned "not a number"

I would like to know if its flawed, it just did not seem so with those examples.

Edited by iamtheky

  Reveal hidden contents

Posted

Its one of those Functions you overlook, for example do you know about GUISwitch()? I didn't until 2months ago :)

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Check out _DisplayPassword() and you will see that this is the ONLY! time I have had to use it :) in all my Functions.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...