Sign in to follow this  
Followers 0

Check if InputBox is Integer Problem

12 posts in this topic

Posted

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.

Share this post


Link to post
Share on other sites



Posted

InputBox() returns a string, so IsInt() will always be False (zero).

Share this post


Link to post
Share on other sites

Posted (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 by xcal

Share this post


Link to post
Share on other sites

Posted (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 by Manadar

Share this post


Link to post
Share on other sites

Posted

Manadar... I think you missed the point. He wants to check if $Sample_Time is a number or not.

Share this post


Link to post
Share on other sites

Posted (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 by Manadar

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted

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) = 0

input "a" -->StringIsAlpha($Sample_Time) = 1

input "myname1" --> StringIsAlpha($Sample_Time) = 0

Autoit can do such a great things.

There must be a function or something to test if user input is 100% correctly.

KHautekier

Share this post


Link to post
Share on other sites

Posted (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 by Manadar

Share this post


Link to post
Share on other sites

Posted

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) = 0

input "a" -->StringIsAlpha($Sample_Time) = 1

input "myname1" --> StringIsAlpha($Sample_Time) = 0

Autoit can do such a great things.

There must be a function or something to test if user input is 100% correctly.

KHautekier

Ok, I see the problem there, too.

I'd go with Manadar's solution. :">

Share this post


Link to post
Share on other sites

Posted

Ok, jackpot! (I think. ;) )

Do
    $Sample_Time = InputBox("Sampletime", "How Long must the sample be in minutes?", 10)
Until Not StringRegExp($Sample_Time, '[:alpha:]')

Share this post


Link to post
Share on other sites

Posted

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.

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  
Followers 0