danielmohr91 Posted January 16, 2010 Share Posted January 16, 2010 (edited) "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 January 16, 2010 by danielmohr91 Link to comment Share on other sites More sharing options...
Developers Jos Posted January 16, 2010 Developers Share Posted January 16, 2010 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 More sharing options...
danielmohr91 Posted January 16, 2010 Author Share Posted January 16, 2010 (edited) InputBox() retuns a string so IsNumber() will not work.Look at the StringIsXXX() functions.JosPerfect! 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 January 16, 2010 by danielmohr91 Link to comment Share on other sites More sharing options...
JonathanR Posted January 17, 2010 Share Posted January 17, 2010 Check out the Return Value section of InputBox.Success: Returns the string that was entered. Link to comment Share on other sites More sharing options...
wolf9228 Posted January 17, 2010 Share Posted January 17, 2010 (edited) "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 January 17, 2010 by wolf9228 صرح السماء كان هنا Link to comment Share on other sites More sharing options...
wolf9228 Posted January 17, 2010 Share Posted January 17, 2010 "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 More sharing options...
danielmohr91 Posted January 18, 2010 Author Share Posted January 18, 2010 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now