Shoutbox

HELP - Arrays in the registry! - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: HELP - Arrays in the registry! (/showthread.php?tid=91109)

HELP - Arrays in the registry! by whiz on 06-18-2009 at 06:20 PM

I want to use this with the Interface Writer script, but I have a problem with what it returns.

Note: this function uses a registry code snippet.

Javascript code:
function SaveProject()
{
    Debug.Trace("<-- Start project save. -->");
    try
    {
        Debug.Trace("> Attempting to save project to the registry...");
        if (ExistsRegistry("Sys", "FilePath"))
        {
            if (Interop.Call('user32', 'MessageBoxW', objWnd.Handle, "A file already exists in the registry.  Overwrite?", "Interface Writer | Save Project", 4 | 48) !== 7)
            {
                Debug.Trace("-> Saving system data to the registry...");   
                Debug.Trace("--> Saving file path...");
                WriteRegistry("Sys", "FilePath", FilePath, true);
                Debug.Trace("-> Saving window data to the registry...");
                Debug.Trace("--> Saving window IDs...");
                WriteRegistry("Lst", "Id", WndLstId, true);
                Debug.Trace("--> Saving window titles...");
                WriteRegistry("Lst", "Title", WndLstTitle, true);
                Debug.Trace("--> Saving window widths...");
                WriteRegistry("Lst", "Width", WndLstWidth, true);
                Debug.Trace("--> Saving window heights...");
                WriteRegistry("Lst", "Height", WndLstHeight, true);
                Debug.Trace("--> Saving other window data...");
                WriteRegistry("Lst", "Minimize", WndLstMinimize, true);
                WriteRegistry("Lst", "Maximize", WndLstMaximize, true);
                WriteRegistry("Lst", "Close", WndLstClose, true);
                Debug.Trace("-> Saving control data to the registry...");
                Debug.Trace("--> Saving control IDs...");
                WriteRegistry("Ctrl", "Id", WndCtrlId, true);
                Debug.Trace("--> Saving control types...");
                WriteRegistry("Ctrl", "Type", WndCtrlType, true);
                Debug.Trace("--> Saving control left positionings...");
                WriteRegistry("Ctrl", "Left", WndCtrlLeft, true);
                Debug.Trace("--> Saving control down positionings...");
                WriteRegistry("Ctrl", "Down", WndCtrlDown, true);
                Debug.Trace("--> Saving control widths...");
                WriteRegistry("Ctrl", "Width", WndCtrlWidth, true);
                Debug.Trace("--> Saving control heights...");
                WriteRegistry("Ctrl", "Height", WndCtrlHeight, true);
                Debug.Trace("--> Saving control captions...");
                WriteRegistry("Ctrl", "Caption", WndCtrlCaption, true);
                Debug.Trace("--> Saving control help texts...");
                WriteRegistry("Ctrl", "Help", WndCtrlHelp, true);
            }
        }
        else
        {
            Debug.Trace("-> Saving system data to the registry...");   
            Debug.Trace("--> Saving file path...");
            WriteRegistry("Sys", "FilePath", FilePath, true);
            Debug.Trace("-> Saving window data to the registry...");
            Debug.Trace("--> Saving window IDs...");
            WriteRegistry("Lst", "Id", WndLstId, true);
            Debug.Trace("--> Saving window titles...");
            WriteRegistry("Lst", "Title", WndLstTitle, true);
            Debug.Trace("--> Saving window widths...");
            WriteRegistry("Lst", "Width", WndLstWidth, true);
            Debug.Trace("--> Saving window heights...");
            WriteRegistry("Lst", "Height", WndLstHeight, true);
            Debug.Trace("--> Saving other window data...");
            WriteRegistry("Lst", "Minimize", WndLstMinimize, true);
            WriteRegistry("Lst", "Maximize", WndLstMaximize, true);
            WriteRegistry("Lst", "Close", WndLstClose, true);
            Debug.Trace("-> Saving control data to the registry...");
            Debug.Trace("--> Saving control IDs...");
            WriteRegistry("Ctrl", "Id", WndCtrlId, true);
            Debug.Trace("--> Saving control types...");
            WriteRegistry("Ctrl", "Type", WndCtrlType, true);
            Debug.Trace("--> Saving control left positionings...");
            WriteRegistry("Ctrl", "Left", WndCtrlLeft, true);
            Debug.Trace("--> Saving control down positionings...");
            WriteRegistry("Ctrl", "Down", WndCtrlDown, true);
            Debug.Trace("--> Saving control widths...");
            WriteRegistry("Ctrl", "Width", WndCtrlWidth, true);
            Debug.Trace("--> Saving control heights...");
            WriteRegistry("Ctrl", "Height", WndCtrlHeight, true);
            Debug.Trace("--> Saving control captions...");
            WriteRegistry("Ctrl", "Caption", WndCtrlCaption, true);
            Debug.Trace("--> Saving control help texts...");
            WriteRegistry("Ctrl", "Help", WndCtrlHelp, true);
            Debug.Trace("> Project save successful.");
        }
        Interop.Call('user32', 'MessageBoxW', WndWriterEditFile.Handle, "The interface project has been saved successfully.\nInterface Writer will now exit...", "Interface Writer | Save Project", 64);
    }
    catch (error)
    {
        Debug.Trace("> Project save error (" + error + ").");
        Interop.Call('user32', 'MessageBoxW', WndWriterEditFile.Handle, "There was a problem whilst saving the project.\nError reported by script: " + error, "Interface Writer | Save Project", 64);
    }
    Debug.Trace("<-- End project save. -->");
}
 
function LoadProject()
{
    Debug.Trace("<-- Start project load. -->");
    try
    {
        Debug.Trace("> Attempting to load project from the registry...");
        Debug.Trace("-> Loading system data to the registry...");  
        Debug.Trace("--> Loading file path...");
        FilePath = ReadRegistry("Sys", "FilePath");
        Debug.Trace("-> Loading window data to the registry...");
        Debug.Trace("--> Loading window IDs...");
        WndLstId = new Array(ReadRegistry("Lst", "Id"));
        Debug.Trace("--> Loading window titles...");
        WndLstTitle = new Array(ReadRegistry("Lst", "Title"));
        Debug.Trace("--> Loading window widths...");
        WndLstWidth = new Array(ReadRegistry("Lst", "Width"));
        Debug.Trace("--> Loading window heights...");
        WndLstHeight = new Array(ReadRegistry("Lst", "Height"));
        Debug.Trace("--> Loading other window data...");
        WndLstMinimize = new Array(ReadRegistry("Lst", "Minimize"));
        WndLstMaximize = new Array(ReadRegistry("Lst", "Maximize"));
        WndLstClose = new Array(ReadRegistry("Lst", "Close"));
        Debug.Trace("-> Loading control data to the registry...");
        Debug.Trace("--> Loading control IDs...");
        WndCtrlId = new Array(ReadRegistry("Ctrl", "Id"));
        Debug.Trace("--> Loading control types...");
        WndCtrlType = new Array(ReadRegistry("Ctrl", "Type"));
        Debug.Trace("--> Loading control left positionings...");
        WndCtrlLeft = new Array(ReadRegistry("Ctrl", "Left"));
        Debug.Trace("--> Loading control down positionings...");
        WndCtrlDown = new Array(ReadRegistry("Ctrl", "Down"));
        Debug.Trace("--> Loading control widths...");
        WndCtrlWidth = new Array(ReadRegistry("Ctrl", "Width"));
        Debug.Trace("--> Loading control heights...");
        WndCtrlHeight = new Array(ReadRegistry("Ctrl", "Height"));
        Debug.Trace("--> Loading control captions...");
        WndCtrlCaption = new Array(ReadRegistry("Ctrl", "Caption"));
        Debug.Trace("--> Loading control help texts...");
        WndCtrlHelp = new Array(ReadRegistry("Ctrl", "Help"));
        Debug.Trace("-> Deleting system data from the registry...");   
        Debug.Trace("--> Deleting file path...");
        DeleteRegistry("Sys", "FilePath");
        Debug.Trace("-> Deleting window data to the registry...");
        Debug.Trace("--> Deleting window IDs...");
        DeleteRegistry("Lst", "Id");
        Debug.Trace("--> Deleting window titles...");
        DeleteRegistry("Lst", "Title");
        Debug.Trace("--> Deleting window widths...");
        DeleteRegistry("Lst", "Width");
        Debug.Trace("--> Deleting window heights...");
        DeleteRegistry("Lst", "Height");
        Debug.Trace("--> Deleting other window data...");
        DeleteRegistry("Lst", "Minimize");
        DeleteRegistry("Lst", "Maximize");
        DeleteRegistry("Lst", "Close");
        Debug.Trace("-> Deleting control data to the registry...");
        Debug.Trace("--> Deleting control IDs...");
        DeleteRegistry("Ctrl", "Id");
        Debug.Trace("--> Deleting control types...");
        DeleteRegistry("Ctrl", "Type");
        Debug.Trace("--> Deleting control left positionings...");
        DeleteRegistry("Ctrl", "Left");
        Debug.Trace("--> Deleting control down positionings...");
        DeleteRegistry("Ctrl", "Down");
        Debug.Trace("--> Deleting control widths...");
        DeleteRegistry("Ctrl", "Width");
        Debug.Trace("--> Deleting control heights...");
        DeleteRegistry("Ctrl", "Height");
        Debug.Trace("--> Deleting control captions...");
        DeleteRegistry("Ctrl", "Caption");
        Debug.Trace("--> Deleting control help texts...");
        DeleteRegistry("Ctrl", "Help");
        Debug.Trace("> Project loading successful.");
        Interop.Call('user32', 'MessageBoxW', null, "The interface project has been loaded successfully.\nInterface Writer will now exit...", "Interface Writer | Save Project", 64);
        OnWndWriterEditFileEvent_Build();
    }
    catch (error)
    {
        Debug.Trace("> Project load error (" + error + ").");
        Interop.Call('user32', 'MessageBoxW', null, "There was a problem whilst loading the project.\nError reported by script: " + error, "Interface Writer | Save Project", 64);
    }
    Debug.Trace("<-- End project load. -->");
}


Let's say, for example, that I have two window IDs, "Wnd1" and "Wnd2".  Instead of the registry returning "Wnd1" in "WndLstId[0]" and "Wnd2" in "WndLstId[1]", I get "Wnd1,Wnd2" in "WndLstId[0]".  How can I get it so it splits items using the comma?
RE: HELP - Arrays in the registry! by Mnjul on 06-18-2009 at 06:37 PM

I didn't read your code, but, if this is what you want:

quote:
Originally posted by whiz
Let's say, for example, that I have two window IDs, "Wnd1" and "Wnd2".  Instead of the registry returning "Wnd1" in "WndLstId[0]" and "Wnd2" in "WndLstId[1]", I get "Wnd1,Wnd2" in "WndLstId[0]".  How can I get it so it splits items using the comma?
You can use WndLstId[0].split(','); which returns an array of split strings.
RE: HELP - Arrays in the registry! by whiz on 06-18-2009 at 07:02 PM

So, to be clear, this code...

Javascript code:
var Msg = "Item1,Item2";
Msg.split(,);


...would return the same as this code...
Javascript code:
var Msg = new Array("Item1", "Item2");


Is that correct?
RE: HELP - Arrays in the registry! by Mnjul on 06-18-2009 at 07:06 PM

Yeah, but, it's
Msg.split(",");
with the quotes (you should be passing in a string, or a RegExp)


RE: HELP - Arrays in the registry! by Matti on 06-18-2009 at 07:07 PM

Yes, as long as the array elements don't contain your separator character (in this case, a comma), you'll get the same array. Since you're trying to retrieve an array of window IDs, you won't have any trouble with possibly having a comma in an element's value.

Just one note, it should say:

Javascript code:
Msg.split(","); //note the quotes around the comma, you're passing a regular string as first parameter here for String.split()


RE: HELP - Arrays in the registry! by Spunky on 06-18-2009 at 07:14 PM

Almost,

Javascript code:
var Msg = "Item1,Item2";
Msg.split(,);


Should be:

Javascript code:
var Msg = "Item1,Item2";
Msg.split(",");



EDIT: Bit slow=/ I left the browser window open for a while :p
RE: HELP - Arrays in the registry! by whiz on 06-18-2009 at 07:56 PM

Javascript code:
WndLstId = ReadRegistry("Lst", "Id");
WndLstId.split(",");
WndLstTitle = ReadRegistry("Lst", "Title");
WndLstTitle.split(",");
// ...

Is that the right idea?
RE: HELP - Arrays in the registry! by Mnjul on 06-18-2009 at 08:15 PM

Blah, sorry for not making it clear..

You'll need to some variable to save the return value of the split() function, like

JScript code:
var Msg = "Item1,Item2";
var arrayOfItems = Msg.split(",");


RE: RE: HELP - Arrays in the registry! by whiz on 06-19-2009 at 03:56 PM

Javascript code:
var TmpLstId = ReadRegistry("Lst", "Id");
WndLstId = TmpLstId.split(",");
var TmpLstTitle = ReadRegistry("Lst", "Title");
WndLstTitle = TmpLstTitle.split(",");
// ...

Like that?
RE: HELP - Arrays in the registry! by CookieRevised on 06-19-2009 at 09:34 PM

Provided "Id" and "Title" were saved as a string (and read out as a string), yes...

PS: since this is JScript, you could also do:

JScript code:
var WndLstId = ReadRegistry("Lst", "Id");
WndLstId = WndLstId.split(",");
var WndLstTitle = ReadRegistry("Lst", "Title");
WndLstTitle = WndLstTitle.split(",");
// ...

So you don't realy need the temporary variables, you could just assign a string to your existing WndLstWhatever  variable and then use that same string variable to make it into an array. JScript is fine with that (as it automatically converts and overwrites the types in this case).

This might save you a lot of variable names and code.

Although there are a lot more, and more efficient methods to do what you do though (storing a lot of individual variables in the registry I mean).

RE: HELP - Arrays in the registry! by markee on 06-20-2009 at 07:14 AM

May I make the recommendation to use an XML or INI file rather than registry keys for such a large amount of data.  You seem to have layered information which would fit nicely in an XML format imho.

Here is a link to information http://www.devguru.com/technologies/xmldom/quickref/xmldom_index.html . You might also want to look around for some code snippets.  I hope this helps.


RE: HELP - Arrays in the registry! by whiz on 06-20-2009 at 11:55 AM

quote:
Originally posted by CookieRevised
Provided "Id" and "Title" were saved as a string (and read out as a string), yes...

PS: since this is JScript, you could also do:
JScript code:
var WndLstId = ReadRegistry("Lst", "Id");
WndLstId = WndLstId.split(",");
var WndLstTitle = ReadRegistry("Lst", "Title");
WndLstTitle = WndLstTitle.split(",");
// ...

So you don't realy need the temporary variables, you could just assign a string to your existing WndLstWhatever  variable and then use that same string variable to make it into an array. JScript is fine with that (as it automatically converts and overwrites the types in this case).

This might save you a lot of variable names and code.

Although there are a lot more, and more efficient methods to do what you do though (storing a lot of individual variables in the registry I mean).

Well, I did find an even quicker method, that still uses normal variables:
Javascript code:
WndLstId = ReadRegistry("Lst", "Id").split(",");
WndLstTitle = ReadRegistry("Lst", "Title").split(",");
// ...




quote:
Originally posted by markee
May I make the recommendation to use an XML or INI file rather than registry keys for such a large amount of data.  You seem to have layered information which would fit nicely in an XML format imho.

Here is a link to information http://www.devguru.com/technologies/xmldom/quickref/xmldom_index.html . You might also want to look around for some code snippets.  I hope this helps.
Well, I have had a look, but I'm still confused with the whole idea of XML reading/writing.  :S
RE: HELP - Arrays in the registry! by NanaFreak on 06-20-2009 at 12:05 PM

quote:
Originally posted by whiz
quote:
Originally posted by markee
May I make the recommendation to use an XML or INI file rather than registry keys for such a large amount of data.  You seem to have layered information which would fit nicely in an XML format imho.

Here is a link to information http://www.devguru.com/technologies/xmldom/quickref/xmldom_index.html . You might also want to look around for some code snippets.  I hope this helps.
Well, I have had a look, but I'm still confused with the whole idea of XML reading/writing.  :S
just try some examples, practice with some made up examples and after a day of that you should start to get the hang of it...

also, this is for your interface maker project, why not just save the xml as an interface, then work out how to re-load it into your script, this would give your script more functionality as well because you could load any window into it and then edit that window!
RE: HELP - Arrays in the registry! by whiz on 06-21-2009 at 09:49 AM

quote:
Originally posted by NanaFreak
just try some examples, practice with some made up examples and after a day of that you should start to get the hang of it...

also, this is for your interface maker project, why not just save the xml as an interface, then work out how to re-load it into your script, this would give your script more functionality as well because you could load any window into it and then edit that window!
I have had a bit of a discussion about this:
mynetx's reply to "Interface Writer | [release] 1.2" (and onwards)