autohotkey - How can I check type of multiple variables in one block? -


how can check type of multiple variables in 1 if statement block, without using several if statements? example:

if var1 not integer {     msgbox, 0, error, var1 not integer     return } if var2 not integer {     msgbox, 0, error, var2 not integer     return } 

what check types in single boolean expression.

i tried this, doesn't work.

if ((var1 not integer) or (var2 not integer)) {     msgbox, 0, error, variables not integers     return } 

special if commands in ahk if var [not] between , if var [not] in/contains matchlist, if var [not] type, ifwin... aren't actual boolean expressions, can't chain them using boolean operators.
however, these conditional statements can wrapped in function. furthermore, if var [not] type can rebuilt using regex:

solution 1: wrapper function

isinteger(arg) {     if arg integer         return true     else         return false }  if(isinteger(123) && isinteger(456)) {     msgbox, yay! } 

solution 2: regex

if(regexmatch(123, "^\d+$") && regexmatch(456, "^\d+$")) {     msgbox, hooray! } 

some tests

if you're interested, take @ array values, copy script , run it. may find results surprising. both our wrapper function , regexmatch provide same back-to-back results.

arr := [123, 456, 123.456, "789", "not_an_integer!", true, false] msg := "" loop % arr.maxindex() {     msg .= arr[a_index]     msg .= ":`tisinteger(): " isinteger(arr[a_index])     msg .= " regexmatch(): " regexmatch(arr[a_index], "^\d+$")     msg .= "`n" } msgbox  % msg   isinteger(arg) {     if arg integer         return true     else         return false } 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -