How control data type in inputbox

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Superbobo
Posts: 6
Joined: 30 Apr 2020, 04:58

How control data type in inputbox

16 May 2021, 07:59

Hi,

I would like to check the variable inserted in the input box if it is eg an integer. If not, it returns to the beginning and displays the input box again. I have this script:

Code: Select all

shdPictures:
InputBox, numberPictures, Number of photos, how many images will be processed in a row.,,,,,,,, 1
if (numberPictures is not integer) {
	MsgBox "Please enter a number"
        gosub, shdPicures
}
MsgBox "number entered"
return
However, the condition never evaluates, for example, the letter "d" as "is not integer". Why? And how to edit it?

thanks
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: How control data type in inputbox

16 May 2021, 08:51

The If... is syntax is special and requires specific syntax as documented. It cannot be used inside parentheses as a direct expression.

Code: Select all

done := False
Loop {
 InputBox, nPics, Number of photos, How many images will be processed?,, 300, 125,,,,, 1
 If !nPics || nPics < 0 || ErrorLevel
  ExitApp
 If nPics is integer
  done := True
 Else MsgBox, 48, Error, Please enter an integer.
} Until done
MsgBox, 64, Number of photos, %nPics%
Superbobo
Posts: 6
Joined: 30 Apr 2020, 04:58

Re: How control data type in inputbox

19 May 2021, 03:30

Thank you for the solution.

It's just a pity that it doesn't work as I wrote the code myself :)
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: How control data type in inputbox

19 May 2021, 06:10

All you really needed was to remove parentheses and move your brace to the next line.
Superbobo
Posts: 6
Joined: 30 Apr 2020, 04:58

Re: How control data type in inputbox

22 May 2021, 13:36

Wow, magic :)
Thanks

PS: What makes your original solution better when the result is the same. But in a much shorter way :)
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: How control data type in inputbox

22 May 2021, 13:44

Fixes the terminology of number vs. integer. Handles negative numbers and zero properly. Allows the inputbox to be aborted. Avoids wonky flow due to routine calling itself.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 259 guests