Code: Select all
Col:=1
if (Col is Integer)
MsgBox, % Col " is an Integer."
if (Col is Alpha)
MsgBox, % Col " is an Alpha."
Code: Select all
Col:=1
if (Col is Integer)
MsgBox, % Col " is an Integer."
if (Col is Alpha)
MsgBox, % Col " is an Alpha."
Currently your code just concatenates the three variables Col, is and Integer/Alpha. Only Col is non-blank, hence true in both cases (because expression).https://www.autohotkey.com/docs/commands/IfIs.htm#Remarks wrote:Note: The operators "between", "is", "in", and "contains" are not supported in expressions.
Can you watch my video in this post and help me understand how AutoHotkey shows the value as an integer, yet it breaks when I put it in my code?
Code: Select all
XL :=XL_Handle(1) ;Connect to active Excel application
Col:=String_To_Number("A")
If Col is Integer
MsgBox % Col " is an integer"
;~ Col:=1
MsgBox % XL.Cells(XL.Rows.Count,Col).End(-4162).Row
return
String_To_Number(Column){
StringUpper, Column, Column
Index := 0
Loop, Parse, Column ;loop for each character
{ascii := asc(A_LoopField)
if (ascii >= 65 && ascii <= 90)
index := index * 26 + ascii - 65 + 1 ;Base = 26 (26 letters)
else { return
} }
return, index+0
}
XL_Handle(Sel){
ControlGet, hwnd, hwnd, , Excel71, ahk_class XLMAIN ;identify the hwnd for Excel
Obj:=ObjectFromWindow(hwnd,-16)
return (Sel=1?Obj.Application:Sel=2?Obj.Parent:Sel=3?Obj.ActiveSheet:"")
}
;***borrowd & tweaked from Acc.ahk Standard Library*** by Sean Updated by jethrow*****************
ObjectFromWindow(hWnd, idObject = -4){
if(h:=DllCall("LoadLibrary","Str","oleacc","Ptr"))
If DllCall("oleacc\AccessibleObjectFromWindow","Ptr",hWnd,"UInt",idObject&=0xFFFFFFFF,"Ptr",-VarSetCapacity(IID,16)+NumPut(idObject==0xFFFFFFF0?0x46000000000000C0:0x719B3800AA000C81,NumPut(idObject==0xFFFFFFF0?0x0000000000020400:0x11CF3C3D618736E0,IID,"Int64"),"Int64"), "Ptr*", pacc)=0
Return ComObjEnwrap(9,pacc,1)
}
incorrect, there are a few different if-commands that cannot accept expression formatJoe Glines wrote: ↑22 Feb 2020, 10:20however that seems counter-intuitive to me. I thought anything after an "if" could be wrapped in parens to contain it...
obviously i cannot do that lol, and i wasn't. what i was saying was incorrect was that anything after 'if' can be wrapped in parensJoe Glines wrote: ↑26 Feb 2020, 08:11@Guest3456 I may not be the worlds best programmer however I don't believe you can tell me that I'm incorrect on something that is not intuitive to me...
of course this is unintuitive, its been a quirk of ahk for years and throws off everyone. you noted at the end of your video that is works on what the value is, rather than the type stored. consider this:Joe Glines wrote: ↑26 Feb 2020, 08:11Anyway, I see how it works now but still don't understand how the "1" in my video can say it is an Integer but the variable isn't actually a number (unless I add something to it)
Code: Select all
;col = 1
;col := "1"
col := 1
if col is integer
msgbox col is integer
Yes, I would have hoped that strings to say it is not an integer (because I was thinking the command was telling me what the variable holds, not what the value is inside the variable)guest3456 wrote: ↑26 Feb 2020, 11:27if you swap the comments, ALL 3 will tell you that the variable is an integer. this is for convenience. do you want the strings to say NO, its not an integer?Code: Select all
;col = 1 ;col := "1" col := 1 if col is integer msgbox col is integer
Users browsing this forum: Anput, Descolada, RandomBoy, ShatterCoder and 317 guests