Khautekier Posted November 20, 2006 Share Posted November 20, 2006 Hi All, i'm writing a script for recording sound. I ask the user (with InputBox) to give me the sample duration. after the input i need to check if the given value is a number. The code i am using is the following : $Sample_Time = "a"; to be sure it will show the InputBox do $Sample_Time = InputBox("Sampletime","How Long must the sample be in minutes?",10) until IsInt($Sample_Time) Problem: No mather what input i am giving in. IsInt returns all the Time 0 and stays in the 'do-until-loop'. Can anybody telling me what i'm doing wrong. What code can I use to check if the input is an Integer? Thanks in advance. Link to comment Share on other sites More sharing options...
xcal Posted November 20, 2006 Share Posted November 20, 2006 InputBox() returns a string, so IsInt() will always be False (zero). How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
xcal Posted November 20, 2006 Share Posted November 20, 2006 (edited) Try it like this: Do $Sample_Time = InputBox("Sampletime", "How Long must the sample be in minutes?", 10) Until Not StringIsAlpha($Sample_Time) Edited November 20, 2006 by xcal How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
jvanegmond Posted November 20, 2006 Share Posted November 20, 2006 (edited) While 1 $Sample_Time = InputBox("Sampletime","How Long must the sample be in minutes?",10) If not @error Then ExitLoop EndIf Wend MsgBox(0, "InputBox value", $Sample_Time) Edited November 20, 2006 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
xcal Posted November 20, 2006 Share Posted November 20, 2006 Manadar... I think you missed the point. He wants to check if $Sample_Time is a number or not. How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
jvanegmond Posted November 20, 2006 Share Posted November 20, 2006 (edited) I missed the point. While 1 $Sample_Time = InputBox("Sampletime","How Long must the sample be in minutes?",10) If @error Then Exit Else If Number($Sample_Time) > 0 Then ExitLoop Else MsgBox(0, "", "A valid number is required") EndIf EndIf Wend MsgBox(0, "InputBox value", $Sample_Time) Edited November 20, 2006 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
xcal Posted November 20, 2006 Share Posted November 20, 2006 I missed the point. While 1 $Sample_Time = InputBox("Sampletime","How Long must the sample be in minutes?",10) If @error Then Exit Else If Number($Sample_Time) > 0 Then ExitLoop Else MsgBox(0, "", "A valid number is required") EndIf EndIf Wend MsgBox(0, "InputBox value", $Sample_Time) That won't work either. Number('12woot') will be > 0 (because it will be 12), but it isn't a properly inputted number. How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
Khautekier Posted November 20, 2006 Author Share Posted November 20, 2006 Hi,using StringIsAlpha($Sample_Time) is ok as far as all the character are letters.As soon as you use 1 number it doesnt work anymore.input "10" --> StringIsAlpha($Sample_Time) = 0input "a" -->StringIsAlpha($Sample_Time) = 1input "myname1" --> StringIsAlpha($Sample_Time) = 0Autoit can do such a great things.There must be a function or something to test if user input is 100% correctly.KHautekier Link to comment Share on other sites More sharing options...
jvanegmond Posted November 20, 2006 Share Posted November 20, 2006 (edited) That won't work either. Number('12woot') will be > 0 (because it will be 12), but it isn't a properly inputted number.Well, if you won't settle for that. Create a GUI with a edit control and set the state to $ES_NUMBER. Done.Looks better too then an InputBox. Edited November 20, 2006 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
xcal Posted November 20, 2006 Share Posted November 20, 2006 Hi,using StringIsAlpha($Sample_Time) is ok as far as all the character are letters.As soon as you use 1 number it doesnt work anymore.input "10" --> StringIsAlpha($Sample_Time) = 0input "a" -->StringIsAlpha($Sample_Time) = 1input "myname1" --> StringIsAlpha($Sample_Time) = 0Autoit can do such a great things.There must be a function or something to test if user input is 100% correctly.KHautekierOk, I see the problem there, too.I'd go with Manadar's solution. :"> How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
xcal Posted November 20, 2006 Share Posted November 20, 2006 Ok, jackpot! (I think. ) Do $Sample_Time = InputBox("Sampletime", "How Long must the sample be in minutes?", 10) Until Not StringRegExp($Sample_Time, '[:alpha:]') How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
Khautekier Posted November 20, 2006 Author Share Posted November 20, 2006 xcal, Yes. I sure works with your code. Do $Sample_Time = InputBox("Sampletime", "How Long must the sample be in minutes?", 10) Until Not StringRegExp($Sample_Time, '[:alpha:]') Thanks a lot. 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