totoymola Posted September 25, 2005 Posted September 25, 2005 (edited) Hi. This is my first post I'm having a problem with my script. I want to make an inputbox that will check if the input is a number. I spent several hours to make this work, and I finally figured out a solution. However, it is NOT perfect.. This is my current working script so far.#CS#=#=#=#=#=#=#=#=#=#=#=#=#=#=# PURPOSE : NUMBER CHECKER #CE#=#=#=#=#=#=#=#=#=#=#=#=#=#=# While 1 $Num = InputBox("Number Checker", "Please enter a VALID number greater than or equal to zero.", "0") If @error = 0 Then If $Num >= 1 Or $Num = "0" Then MsgBox(0, "Result", "VALID") Else MsgBox(0, "Result", "NOT VALID") EndIf Else Exit EndIf WEndBefore this, I tried using If $Num >= 0 Then instead of If $Num >= 1 Or $Num = "0" Then, but it didn't work. It always return "VALID".Then I thought of using the IsNumber function, and it didn't work too. It always returns "NOT VALID" Here is the code with the IsNumber:#CS#=#=#=#=#=#=#=#=#=#=#=#=#=#=# PURPOSE : NUMBER CHECKER #CE#=#=#=#=#=#=#=#=#=#=#=#=#=#=# While 1 $Num = InputBox("Number Checker", "Please enter a VALID number greater than or equal to zero.", "0") If @error = 0 Then If IsNumber($Num) Then MsgBox(0, "Result", "VALID") Else MsgBox(0, "Result", "NOT VALID") EndIf Else Exit EndIf WEndPlease tell me what is wrong with this.Thanks! Edited September 25, 2005 by totoymola
B3TA_SCR1PT3R Posted September 25, 2005 Posted September 25, 2005 $Num = InputBox("Number Checker", "Please enter a VALID number greater than or equal to zero.","0") If $Num >= 0 Then MsgBox(0, "Result", "VALID") Else MsgBox(0, "Result", "NOT VALID") EndIf works for me [right][font="Courier New"]...Run these streets all day, I can sleep when I die.[/font] [/right]
totoymola Posted September 25, 2005 Author Posted September 25, 2005 (edited) $Num = InputBox("Number Checker", "Please enter a VALID number greater than or equal to zero.","0") If $Num >= 0 Then MsgBox(0, "Result", "VALID") Else MsgBox(0, "Result", "NOT VALID") EndIfworks for meThanks! Actually, I tried that before. It is not 100% working for me, because if I enter other characters (not numbers), it will still return "VALID"This is what I have in mind, but it doesn't work! $Num = InputBox("Number Checker", "Please enter a VALID number greater than or equal to zero.","0") If IsNumber($Num) And $Num >= 0 Then MsgBox(0, "Result", "VALID") Else MsgBox(0, "Result", "NOT VALID") EndIfCould you please tell me how to implement the IsNumber? Because that code above always return "NOT VALID".Thanks again! Edited September 25, 2005 by totoymola
/dev/null Posted September 25, 2005 Posted September 25, 2005 Thanks! Actually, I tried that before. It is not 100% working for me, because if I enter other characters (not numbers), it will still return "VALID"what you need is StringIsInt().$Num = InputBox("Number Checker", "Please enter a VALID number greater than or equal to zero.","0") If StringIsInt($Num) And $Num >= 0 Then MsgBox(0, "Result", "VALID") Else MsgBox(0, "Result", "NOT VALID") EndIfCheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *
totoymola Posted September 25, 2005 Author Posted September 25, 2005 what you need is StringIsInt().$Num = InputBox("Number Checker", "Please enter a VALID number greater than or equal to zero.","0") If StringIsInt($Num) And $Num >= 0 Then MsgBox(0, "Result", "VALID") Else MsgBox(0, "Result", "NOT VALID") EndIfCheersKurtWow!! That solved my problem! Thanks a lot Kurt and B3TA_SCR1PT3R! I'm a total n00b that's why I don't know how to use that function (yet). By the way, if it's not too much to ask, can you give me examples of using the IsNumber function? The help file doesn't give much info about it.Thanks!
/dev/null Posted September 26, 2005 Posted September 26, 2005 By the way, if it's not too much to ask, can you give me examples of using the IsNumber function? The help file doesn't give much info about it.From help file: IsNumber() checks if a variable's base type is numeric. As InputBox() allways returns a string, your if clause failed (IsNumber($Num) is allways 0 then!).CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *
totoymola Posted September 26, 2005 Author Posted September 26, 2005 Brilliant! I didn't even know that inputboxes always return strings. Now I know. Thanks once again.
totoymola Posted September 26, 2005 Author Posted September 26, 2005 Thanks fro all your help. This is my final working code (I hope). $Num = InputBox("Number Checker", "Please enter a VALID number greater than or equal to zero.", "0") If (StringIsInt($Num) Or StringIsFloat($Num)) And $Num >= 0 Then MsgBox(0, "Result", "VALID") Else MsgBox(0, "Result", "NOT VALID") EndIf I added the StringIsFloat() so it will accept numbers with decimals as well. Everything is working fine so far, but I'm curious to know the other methods of doing this too.
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