Sign in to follow this  
Followers 0
erebus

IsNumber

6 posts in this topic

I use the following code:

$no=1

Select
   Case Not IsNumber($no)
   MsgBox(0, "DEBUG", "$no is not a number")
   Exit
EndSelect

This works as expected. $no IS a number.

Now I alter the above code as:

$no = IniRead($ini, "Something", "Number", "NOTEXIST")

Select
   Case Not IsNumber($no)
   MsgBox(0, "DEBUG", "$no is not a number")
   MsgBox(0, "DEBUG", $no + 1)
   Exit
EndSelect

"Number" in $ini = 1. Now AutoIT does not recognize $no as a number, executes the first MsgBox to indicate the error, however the result of the second MsgBox is "2". Can you explain this?

If I'm doing something really stupid (headache rules) shoot me freely.

Share this post


Link to post
Share on other sites



And why are you using a Select when there's only one condition? Why not use an If?


I have a catapult. Give me all the money or I will fling an enormous rock at your head.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

@Larry: Why can't I find this function? (using the latest unstable)

@Mr.Wizard: Just posted a sort example, there are more conditions in my case (that's why the Select function was used).

Edit: Solved - used:

$no = IniRead($ini, "Something", "Number", "NOTEXIST")

Select
   Case Not Number($no)

Thanks anyway guys :)

Edited by erebus

Share this post


Link to post
Share on other sites

I suggest you use StringIsDigit

$no = IniRead($ini, "Something", "Number", "NOTEXIST")

Select
  Case StringIsDigit($no)
     MsgBox(0, "DEBUG", "$no is not a number")
     MsgBox(0, "DEBUG", $no + 1)
     Exit
EndSelect

Share this post


Link to post
Share on other sites

@Larry: Why can't I find this function? (using the latest unstable)

@Mr.Wizard: Just posted a sort example, there are more conditions in my case (that's why the Select function was used).

Edit: Solved - used:

$no = IniRead($ini, "Something", "Number", "NOTEXIST")

Select
   Case Not Number($no)

Thanks anyway guys :)

<{POST_SNAPBACK}>

Try this and see if that explains it:

$no = 1
if Not IsNumber($no) then MsgBox(0, "DEBUG 1 ", "$no is not a number")
$no = "1"
if Not IsNumber($no) then MsgBox(0, "DEBUG 2", "$no is not a number")

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

@JdeB: Thank you, I also got the same answer from Larry:

IniRead returns a string...

@SlimShady: Very good idea! Already updated, thank you. :) I think that is what Larry means. Edited by erebus

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0