What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » reading boolean from registry

reading boolean from registry
Author: Message:
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: reading boolean from registry
quote:
Originally posted by deAd
I believe it is because of the intialization where the boolean is set to true. Because they have the same name, it's initializing again each time, setting it to true.
No... As it is, it works perfectly. JScript knows what the object is and what the variable name is.

It's not initialized each time. And the method used by Ezra can perfectly be used as a means to provide a default value.


quote:
Originally posted by TheGeek
Can't you just read/write it as a string?
code:
Shell.RegWrite(MsgPlus.ScriptRegPath + Messenger.MyEmail + "\\" + key, bMyVal?"true":"false");

bMyVal = (Shell.RegRead(MsgPlus.ScriptRegPath + Messenger.MyEmail + "\\" + key) == "true");

That is actually besides the point and not what the 'problem' is, nor does it explain anything in relation to what is happening. It is also unneeded code and makes it more complicated than it is.
quote:
Originally posted by TheGeek
also, your shell object won't be deleted, because the function returns before your delete statement.
In regards to that, that's only partially true. It is true that the delete statement isn't executed, but the object will still be deleted anyways. The important thing is that he even doesn't need the delete statement as the shell object is created as a local variable. Local variables are not valid /dont exist outside the function they're created in, they are automatically deleted when the function ends.


quote:
Originally posted by Ezra
I need a little help, i'm trying to read a boolean value from the registry, but everytime it gets converted to true.
In short:

Because the value in the registry is actually true... There is nothing wrong with your script. Change the registy value manually and read it out using your script, you'll see it will reflect the value perfectly.



Long explanation:

Note that there is no such thing as an explicit boolean value in the registry.

REG_BOOLEAN (or whatever) doesn't exist. If a program saved a boolean value to the registry it is useually done as a REG_DWORD holding a value of 1 (or -1) or 0.

----------------------

code:
preferences.percentage = ReadRegistry("\preferences\\percentage");
Note that if you use this, the property percentage will become a string, eventhough you declared it as being a boolean object. This is because JScript automatically converts properties to other types if it is needed. It is as if it doesn't care what you declared it as. And the string type is used because the ReadRegistry function returns a string.

code:
preferences.percentage = Boolean(ReadRegistry("\preferences\\percentage"));
If you use this, the property percentage will become a boolean, just as you have declared it with. The default value which you used to initialize it with will be overwritten.

code:
preferences.percentage = new Boolean(ReadRegistry("\preferences\\percentage"));
Same as above actually. Only you again declare percentage again. But makes actually no difference otherwise.

----------------------

Also, when working with boolean objects in JScript, JSCript will automatically convert the boolean object to the needed type.
(this is the essence of this whole post and the essence of your whole issue)

eg: If B is a boolean object. Then S will be a string and B will be converted automatically to a string ("false" or "true"):

S = "This is " + B

N will be a number and JScript will therefore automatically convert B to the equivalent number (0 or -1):

N = 500 + B

In an IF THEN ELSE statement a boolean object is treated as a real boolean. Thus this is perfectly valid, eventhough if you output B with Debug.Trace it will output a string:

If ( B ) {}



In other words, when you say it gets converted to "true", it is exactly what it should be doing and it works correctly.

If you output the to a boolean converted read value with the Debug.Trace statement to check its contents, then it indeed gets converted to the string "true" since Debug.Trace expects a string and outputs a string. JScript detects this and thus converts the boolean value to a string; "true" or "false" are the string equivalents of the boolean type, thus that is outputted.

In other words, there is nothing wrong with your code (except for the few unrelated pointers posted before).

code:
Shell.RegWrite(keypath, value);
Note that this is the equivalent of
code:
Shell.RegWrite(keypath, value, "REG_SZ");
And thus the value variable will be written as a string to the registry. Thus if the value variable is a boolean object, it will again be converted to a string and the string "true" or "false" will be written. If you want to write the boolean object as a number you need to specify the type to write to the registry as a REG_DWORD:
code:
Shell.RegWrite(keypath, value, "REG_DWORD");
Again, the value variable will be converted to the equivalent type because it is a boolean object. Thus this time being a number and thus the number 0 (0x0) or -1 (0xFFFFFF) will be written to the registry.



See MSDN Library:
* RegRead method
* Boolean Object


-----------------

PS: Since you use
code:
MsgPlus.ScriptRegPath + Messenger.MyEmail + "\\" + key
you do not need to specify yet another slash in your key value:
code:
ReadRegistry("\preferences\\percentage");

Doing that will make your final string actually be:
"HKEY_CURRENT_USER\\Software\\Patchou\\Messenger Plus! Live\\GlobalSettings\\Scripts\\yourscript\\my@email\\\preferences\\percentage"

This isn't technically wrong as luckally the extra slash is ignored, but it is still wrong though.

-----------------

;)

This post was edited on 07-21-2006 at 11:40 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
07-21-2006 10:31 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
reading boolean from registry - by Ezra on 07-21-2006 at 08:48 PM
RE: reading boolean from registry - by deAd on 07-21-2006 at 09:20 PM
RE: reading boolean from registry - by TheGeek on 07-21-2006 at 09:22 PM
RE: reading boolean from registry - by Ezra on 07-21-2006 at 10:28 PM
RE: reading boolean from registry - by CookieRevised on 07-21-2006 at 10:31 PM
RE: reading boolean from registry - by Ezra on 07-22-2006 at 03:56 PM
RE: reading boolean from registry - by J-Thread on 07-22-2006 at 06:04 PM
RE: reading boolean from registry - by Ezra on 07-22-2006 at 06:08 PM
RE: reading boolean from registry - by J-Thread on 07-22-2006 at 07:19 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On