Jump to content

Check if InputBox is Integer Problem


Recommended Posts

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

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

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

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

Link to comment
Share on other sites

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

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. :">

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...