PDA

View Full Version : What the heck am I doing wrong?


Buffman
09-22-2006, 04:42 PM
tPath = {Desktop="SHF_DESKTOP",
DesktopCommon="SHF_DESKTOP_COMMON",
QuickLaunch="SHF_APPLICATIONDATA",
QuickLaunchCommon="SHF_APPLICATIONDATA_COMMON",
StartMenu="SHF_STARTMENU",
StartMenuCommon="SHF_STARTMENU_COMMON"
}
-----
for j,path in tPath do
sPath = Shell.GetFolder(path);
Dialog.Message("Return", path.." is "..sPath);
end

sPath keeps resulting in the path to my desktop (the first evaluation)!! What the heck am I doing wrong?

Lorne
09-22-2006, 05:15 PM
Those aren't strings, they're named constants that represent numbers.

For example, SHF_DESKTOP is a constant that represents the number 16.

Try this instead:
tPath = {Desktop=SHF_DESKTOP,
DesktopCommon=SHF_DESKTOP_COMMON,
QuickLaunch=SHF_APPLICATIONDATA,
QuickLaunchCommon=SHF_APPLICATIONDATA_COMMON,
StartMenu=SHF_STARTMENU,
StartMenuCommon=SHF_STARTMENU_COMMON
}
-----
for j,path in tPath do
sPath = Shell.GetFolder(path);
Dialog.Message("Return", path.." is "..sPath);
end

...and you'll see what I mean.

Buffman
09-22-2006, 05:41 PM
See, I knew they were number values, but I tried doing this:
Shell.GetPath(String.ToNumber(path));
and it was doing the same thing. I got thrown off track because I'm actually using the string values elsewhere in my script and just assumed that since it converted the first string value ok, it'd do subsequent ones okay too.

Which leads me to ask, why does it result the first string successfully and not the rest? Why wouldn't String.ToNumber work either?

Anyhow, I just created 2 tables, one for the numeric value and another for strings.

Thanks a lot Lorne!!

Lorne
09-22-2006, 11:30 PM
Or do a table containing tables, with both items (the string to display and the id number).

tPath = { {str="Desktop", id=SHF_DESKTOP}
, {str="DesktopCommon", id=SHF_DESKTOP_COMMON}
, {str="QuickLaunch", id=SHF_APPLICATIONDATA}
} --etc.
-----
for j,path in tPath do
sPath = Shell.GetFolder(path.id);
Dialog.Message("Return", path.str.." is "..sPath);
end

Or just do a reverse lookup table based on the numeric values.

tPath = {SHF_DESKTOP="Desktop",
SHF_DESKTOP_COMMON="DesktopCommon",
SHF_APPLICATIONDATA="QuickLaunch",
SHF_APPLICATIONDATA_COMMON="QuickLaunchCommon",
SHF_STARTMENU="StartMenu",
SHF_STARTMENU_COMMON="StartMenuCommon"
}
-----
for j,path in tPath do
sPath = Shell.GetFolder(j);
Dialog.Message("Return", path.." is "..sPath);
end

I suspect the reason it's always returning the SHF_DESKTOP is probably just because that's what Shell.GetFolder() returns by default if you pass it a number that it doesn't recognize. I'd check the source code and tell you for sure, but I'm at home and feeling kind of lazy. :)

Intrigued
09-23-2006, 09:12 AM
Or do a table containing tables, with both items (the string to display and the id number).

tPath = { {str="Desktop", id=SHF_DESKTOP}
, {str="DesktopCommon", id=SHF_DESKTOP_COMMON}
, {str="QuickLaunch", id=SHF_APPLICATIONDATA}
} --etc.
-----
for j,path in tPath do
sPath = Shell.GetFolder(path.id);
Dialog.Message("Return", path.str.." is "..sPath);
end

Or just do a reverse lookup table based on the numeric values.

tPath = {SHF_DESKTOP="Desktop",
SHF_DESKTOP_COMMON="DesktopCommon",
SHF_APPLICATIONDATA="QuickLaunch",
SHF_APPLICATIONDATA_COMMON="QuickLaunchCommon",
SHF_STARTMENU="StartMenu",
SHF_STARTMENU_COMMON="StartMenuCommon"
}
-----
for j,path in tPath do
sPath = Shell.GetFolder(j);
Dialog.Message("Return", path.." is "..sPath);
end

I suspect the reason it's always returning the SHF_DESKTOP is probably just because that's what Shell.GetFolder() returns by default if you pass it a number that it doesn't recognize. I'd check the source code and tell you for sure, but I'm at home and feeling kind of lazy. :)

(puts on lovingly Grampa like hat, clothes, and demeanor and says)

"That's what I like about them young folks up there, so honest!"

:D