Is Alpha not working correctly

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Joe Glines
Posts: 689
Joined: 30 Sep 2013, 20:49
Facebook: https://www.facebook.com/theAutomatorGuru/
Google: https://plus.google.com/105328929654286634910
GitHub: joetazz
Location: Dallas
Contact:

Is Alpha not working correctly

22 Feb 2020, 09:49

I'm pretty sure the below code should not be true on both of the if statements.

Code: Select all

Col:=1
if (Col is Integer)
	MsgBox, % Col " is an Integer."

if (Col is Alpha)
	MsgBox, % Col " is an Alpha."
gregster
Posts: 4476
Joined: 30 Sep 2013, 06:48

Re: Is Alpha not working correctly

22 Feb 2020, 10:01

Not a bug, afaik.

You can't use is in If-Expression mode (with parentheses).
https://www.autohotkey.com/docs/commands/IfIs.htm#Remarks wrote:Note: The operators "between", "is", "in", and "contains" are not supported in expressions.
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).
So, remove the parentheses.
User avatar
Joe Glines
Posts: 689
Joined: 30 Sep 2013, 20:49
Facebook: https://www.facebook.com/theAutomatorGuru/
Google: https://plus.google.com/105328929654286634910
GitHub: joetazz
Location: Dallas
Contact:

Re: Is Alpha not working correctly

22 Feb 2020, 10:20

Okay, I did it and it worked as you said however that seems counter-intuitive to me. I thought anything after an "if" could be wrapped in parens to contain it... Thanks!
User avatar
Joe Glines
Posts: 689
Joined: 30 Sep 2013, 20:49
Facebook: https://www.facebook.com/theAutomatorGuru/
Google: https://plus.google.com/105328929654286634910
GitHub: joetazz
Location: Dallas
Contact:

Re: Is Alpha not working correctly

22 Feb 2020, 10:42

gregster wrote:
22 Feb 2020, 10:01
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?
https://the-automator.com/is-it-truly-and-integer-variable-in-autohotkey/

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)
}

guest3456
Posts: 3110
Joined: 09 Oct 2013, 10:31

Re: Is Alpha not working correctly

22 Feb 2020, 17:00

Joe Glines wrote:
22 Feb 2020, 10:20
however that seems counter-intuitive to me. I thought anything after an "if" could be wrapped in parens to contain it...
incorrect, there are a few different if-commands that cannot accept expression format

User avatar
Joe Glines
Posts: 689
Joined: 30 Sep 2013, 20:49
Facebook: https://www.facebook.com/theAutomatorGuru/
Google: https://plus.google.com/105328929654286634910
GitHub: joetazz
Location: Dallas
Contact:

Re: Is Alpha not working correctly

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

Anyway, 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)
guest3456
Posts: 3110
Joined: 09 Oct 2013, 10:31

Re: Is Alpha not working correctly

26 Feb 2020, 11:27

Joe 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...
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 parens
Joe Glines wrote:
26 Feb 2020, 08:11
Anyway, 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)
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:

Code: Select all

;col = 1
;col := "1"
col := 1
if col is integer
   msgbox col is integer
if 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?
its a remnant of the old literal assignment days. the first two lines are functionally equivalent, however the first line looks like you are assigning a number, but in fact you're really assigning a string containing the number 1

also notice, there is no 'string' type on the if is help page:
https://www.autohotkey.com/docs/commands/IfIs.htm
youll see on that page, and lots of other places in the docs, the wording of a variable containing something "numeric". you wont see it say that a variable containing a "number". i'm guessing they are using "numeric" to mean that it could be a stringing containing a number.

see this help page for whats going on:
https://www.autohotkey.com/docs/Concepts.htm#caching

most commonly you'll see this kind of nonsense needing to be done when converting from decimal to hex. look at the example at the bottom of SetFormat:
https://www.autohotkey.com/docs/commands/SetFormat.htm

ahk v2 fixes most of this, and has a Type() func

User avatar
Joe Glines
Posts: 689
Joined: 30 Sep 2013, 20:49
Facebook: https://www.facebook.com/theAutomatorGuru/
Google: https://plus.google.com/105328929654286634910
GitHub: joetazz
Location: Dallas
Contact:

Re: Is Alpha not working correctly

26 Feb 2020, 12:29

guest3456 wrote:
26 Feb 2020, 11:27

Code: Select all

;col = 1
;col := "1"
col := 1
if col is integer
   msgbox col is integer
if 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?
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)

Anyway, thank you for the links! They really helped me understand what was going on and how to work with it!

Joe

Return to “Ask For Help”

Who is online

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