Please click the button to accept our cookies. If you continue to use the site, we'll assume you're happy to accept the cookies anyway. I'm fine with this

# Check if InputBox is Integer Problem

11 replies to this topic

### #1 Khautekier

Khautekier

Seeker

• Active Members
• 12 posts

Posted 20 November 2006 - 08:07 AM

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?

### #2 xcal

xcal

Permanent Noob

• Active Members
• 871 posts

Posted 20 November 2006 - 10:33 AM

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

### #3 xcal

xcal

Permanent Noob

• Active Members
• 871 posts

Posted 20 November 2006 - 10:40 AM

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, 20 November 2006 - 11:43 AM.

Taking a REST.

• MVPs
• 10,716 posts

Posted 20 November 2006 - 10:43 AM

```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, 20 November 2006 - 10:44 AM.

### #5 xcal

xcal

Permanent Noob

• Active Members
• 871 posts

Posted 20 November 2006 - 10:49 AM

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

Taking a REST.

• MVPs
• 10,716 posts

Posted 20 November 2006 - 10:54 AM

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, 20 November 2006 - 10:55 AM.

### #7 xcal

xcal

Permanent Noob

• Active Members
• 871 posts

Posted 20 November 2006 - 10:59 AM

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.

### #8 Khautekier

Khautekier

Seeker

• Active Members
• 12 posts

Posted 20 November 2006 - 11:03 AM

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

Taking a REST.

• MVPs
• 10,716 posts

Posted 20 November 2006 - 11:03 AM

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, 20 November 2006 - 11:04 AM.

### #10 xcal

xcal

Permanent Noob

• Active Members
• 871 posts

Posted 20 November 2006 - 11:37 AM

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

### #11 xcal

xcal

Permanent Noob

• Active Members
• 871 posts

Posted 20 November 2006 - 12:06 PM

Ok, jackpot! (I think. )

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

### #12 Khautekier

Khautekier

Seeker

• Active Members
• 12 posts

Posted 20 November 2006 - 03:39 PM

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.

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users