[solved] COM, integers ...

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Learning one
Posts: 173
Joined: 04 Oct 2013, 13:59
Location: Croatia
Contact:

[solved] COM, integers ...

20 Nov 2013, 06:48

Pressing F1 will explore user's most recently used documents - OK
But pressing F2 won't do the same thing although I'm passing the same integer (8) to Explore method.
Why?
Using Round(o.Folder) instead of o.Folder solves the problem, but I would like to hear explanation why do I have to do that... Rounding 8 to 8 sounds funny but it makes it work...

Code: Select all

;===Hotkeys=============================================================================
F1::ComObjCreate("Shell.Application").Explore(8)	; explores user's most recently used documents

F2::
Options=
(
Folder:	8
Color:	red
Sounds:	no
)
o := GetOptions(Options)
ToolTip % o.Folder	; result: 8
ComObjCreate("Shell.Application").Explore(o.Folder)			; doesn't work
;ComObjCreate("Shell.Application").Explore(Round(o.Folder))	; works
return

Esc::ExitApp

; ShellSpecialFolderConstants:	http://msdn.microsoft.com/en-us/library/windows/desktop/bb774096%28v=vs.85%29.aspx

;===Functions===========================================================================
GetOptions(Text) {
	Out := {}	; create Out object (associative array)
	Loop, parse, Text, `n, `r	; parse, find first ":" sign, and assign key = value in Out object
	{
		Line := Trim(A_LoopField), pos := InStr(Line, ":")
		if (pos > 1)	;  0 is not found + key must have at least one letter
			key := Trim(SubStr(Line, 1, pos-1)), Value := Trim(SubStr(Line, pos+1)), Out.Insert(key,value)
	}
	return Out
}
Last edited by Learning one on 27 Nov 2013, 08:18, edited 1 time in total.
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: COM, integers ...

20 Nov 2013, 11:02

I think it's because in ComObjCreate("Shell.Application").Explore(o.Folder) o.Folder is stored as a string, so the command is similar to ComObjCreate("Shell.Application").Explore("8"). If you perform a token math operation on it, the value stored will be converted to a number ComObjCreate("Shell.Application").Explore(o.Folder + 0)
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: COM, integers ...

20 Nov 2013, 12:17

To solve:

Code: Select all

GetOptions(Text) {
    Out := {}   ; create Out object (associative array)
    Loop, parse, Text, `n, `r   ; parse, find first ":" sign, and assign key = value in Out object
    {
        Line := Trim(A_LoopField), pos := InStr(Line, ":")
        if (pos > 1)    ;  0 is not found + key must have at least one letter
            key := Trim(SubStr(Line, 1, pos-1)), Value := Trim(SubStr(Line, pos+1)), Out.Insert(key,value+0=""?value:value+0)
    }
    return Out
}
User avatar
Learning one
Posts: 173
Joined: 04 Oct 2013, 13:59
Location: Croatia
Contact:

Re: COM, integers ...

21 Nov 2013, 07:10

Hmm, so when value (integer 8) is stored as a string, it won't work...
Kon & HotKeyIt, thank you for you replies ;)

Code: Select all

F1::	; works
Folder := 8
ComObjCreate("Shell.Application").Explore(Folder) 
return

F2::	; doesn't work
Folder := "8"
ComObjCreate("Shell.Application").Explore(Folder)
return
User avatar
Learning one
Posts: 173
Joined: 04 Oct 2013, 13:59
Location: Croatia
Contact:

Re: [solved] COM, integers ...

27 Nov 2013, 08:21

For others reference :) : Just found this post by Lexikos - use var := var*1 or similar to assign a pure number.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 133 guests