Jump to content
Sign in to follow this  
danielmohr91

IsNumber

Recommended Posts

danielmohr91

"IsNumber: 
Success: Returns 1.
Failure: returns 0 if expression is not numeric. "
So IsNumber returns one if it is a number, if not, zero. I used the IsNumber command with an actual number, and it worked as expected. But when I use it with a variable it doesn't work. I added a msgbox to manually make sure $temp was actually a number. What am I doing wrong?
Func Start_Delay()
    $temp = $Start_Delay
    Do
        $temp = InputBox("Start delay", "Enter a new value (in seconds) for starting delay.", $temp)
        MsgBox(0, "", $temp)
        $ans = IsNumber($temp) ; returns 1 if number, 0 if not
        MsgBox(0, "", $ans)
        If $ans = 0 Then
            $temp = "Enter a number"
        Else
            TrayTip("Starting Delay", "Delay of " & $temp & " seconds before playback begins.", 10)
        EndIf
    Until $temp > 0
    Global $Start_Delay = $temp
EndFunc   ;==>Start_Delay

Edited by danielmohr91

Share this post


Link to post
Share on other sites
Jos

InputBox() retuns a string so IsNumber() will not work.

Look at the StringIsXXX() functions.

Jos


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

Share this post


Link to post
Share on other sites
danielmohr91

InputBox() retuns a string so IsNumber() will not work.

Look at the StringIsXXX() functions.

Jos

Perfect! I replaced IsNumber with StringIsDigit, and it's working. I didn't realize there was a difference between the number returned by an input box, and normal. How would I read up more on this? What's the term for this? Edited by danielmohr91

Share this post


Link to post
Share on other sites
JonathanR

Check out the Return Value section of InputBox.

Success: Returns the string that was entered.

Share this post


Link to post
Share on other sites
wolf9228

"IsNumber: 
Success: Returns 1.
Failure: returns 0 if expression is not numeric. "
So IsNumber returns one if it is a number, if not, zero. I used the IsNumber command with an actual number, and it worked as expected. But when I use it with a variable it doesn't work. I added a msgbox to manually make sure $temp was actually a number. What am I doing wrong?
Func Start_Delay()
    $temp = $Start_Delay
    Do
        $temp = InputBox("Start delay", "Enter a new value (in seconds) for starting delay.", $temp)
        MsgBox(0, "", $temp)
        $ans = IsNumber($temp) ; returns 1 if number, 0 if not
        MsgBox(0, "", $ans)
        If $ans = 0 Then
            $temp = "Enter a number"
        Else
            TrayTip("Starting Delay", "Delay of " & $temp & " seconds before playback begins.", 10)
        EndIf
    Until $temp > 0
    Global $Start_Delay = $temp
EndFunc   ;==>Start_Delay

$temp = InputBox("Start delay", "Enter a new value (in seconds) for starting delay.", "111")
if Not @error Then
if $temp <> "0" Then
$temp = int($temp)
if $temp <> 0 Then MsgBox(0, "IsNumber", IsNumber($temp))
Else
$temp = int($temp)
MsgBox(0, "IsNumber", IsNumber($temp))
EndIf
EndIf
Edited by wolf9228

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites
wolf9228

"IsNumber: 
Success: Returns 1.
Failure: returns 0 if expression is not numeric. "
So IsNumber returns one if it is a number, if not, zero. I used the IsNumber command with an actual number, and it worked as expected. But when I use it with a variable it doesn't work. I added a msgbox to manually make sure $temp was actually a number. What am I doing wrong?
Func Start_Delay()
    $temp = $Start_Delay
    Do
        $temp = InputBox("Start delay", "Enter a new value (in seconds) for starting delay.", $temp)
        MsgBox(0, "", $temp)
        $ans = IsNumber($temp) ; returns 1 if number, 0 if not
        MsgBox(0, "", $ans)
        If $ans = 0 Then
            $temp = "Enter a number"
        Else
            TrayTip("Starting Delay", "Delay of " & $temp & " seconds before playback begins.", 10)
        EndIf
    Until $temp > 0
    Global $Start_Delay = $temp
EndFunc   ;==>Start_Delay

Or

$temp = InputBox("Start delay", "Enter a new value (in seconds) for starting delay.", "-110.9")
if Not @error Then
if StringIsInt($temp) Or StringIsFloat($temp) Then
$temp = int($temp)
MsgBox(0, "IsNumber", IsNumber($temp))
EndIf
EndIf

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites
danielmohr91

Awesome! Thank you everyone! And I love the idea of using StringIsInt and StringIsFloat, so now it works with decimals too.

Do
        $temp = InputBox("Start delay", "Enter a new value (in seconds) for starting delay.", $temp)
        If @error Then
            $temp = 5 ; If cancel is hit or box is closed, it defualts to 5 seconds
        Else
            If StringIsInt($temp) Or StringIsFloat($temp) Then
                $temp = Int($temp)
                TrayTip("Starting Delay", "Delay of " & $temp & " seconds before playback begins.", 10)
            Else
                $temp = "Enter a number"
            EndIf
        EndIf
    Until $temp > 0

Here's my final code. Much better.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.