Jump to content

IsNumber


Recommended Posts

"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
Link to comment
Share on other sites

  • Developers

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

Look at the StringIsXXX() functions.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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
Link to comment
Share on other sites

"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

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

 

Link to comment
Share on other sites

"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

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

 

Link to comment
Share on other sites

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

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