HELP - Arrays in the registry! |
Author: |
Message: |
whiz
Senior Member
Posts: 568 Reputation: 8
– / – /
Joined: Nov 2008
|
O.P. HELP - Arrays in the registry!
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.
js 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?
|
|
06-18-2009 06:20 PM |
|
|
Mnjul
forum super mod
plz wub me
Posts: 5396 Reputation: 58
– / /
Joined: Nov 2002
Status: Away
|
RE: HELP - Arrays in the registry!
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.
|
|
06-18-2009 06:37 PM |
|
|
whiz
Senior Member
Posts: 568 Reputation: 8
– / – /
Joined: Nov 2008
|
O.P. RE: HELP - Arrays in the registry!
So, to be clear, this code...
js code: var Msg = "Item1,Item2";
Msg.split(,);
...would return the same as this code...
js code: var Msg = new Array("Item1", "Item2");
Is that correct?
|
|
06-18-2009 07:02 PM |
|
|
Mnjul
forum super mod
plz wub me
Posts: 5396 Reputation: 58
– / /
Joined: Nov 2002
Status: Away
|
RE: HELP - Arrays in the registry!
Yeah, but, it's
Msg.split(",");
with the quotes (you should be passing in a string, or a RegExp)
|
|
06-18-2009 07:06 PM |
|
|
Matti
Elite Member
Script Developer and Helper
Posts: 1646 Reputation: 39
32 / /
Joined: Apr 2004
|
RE: HELP - Arrays in the registry!
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:
js code: Msg.split(","); //note the quotes around the comma, you're passing a regular string as first parameter here for String.split()
This post was edited on 06-18-2009 at 07:07 PM by Matti.
|
|
06-18-2009 07:07 PM |
|
|
Spunky
Former Super Mod
Posts: 3658 Reputation: 61
36 / /
Joined: Aug 2006
|
RE: HELP - Arrays in the registry!
Almost,
js code: var Msg = "Item1,Item2";
Msg.split(,);
Should be:
js code: var Msg = "Item1,Item2";
Msg.split(",");
EDIT: Bit slow=/ I left the browser window open for a while
This post was edited on 06-18-2009 at 07:15 PM by Spunky.
<Eljay> "Problems encountered: shit blew up"
|
|
06-18-2009 07:14 PM |
|
|
whiz
Senior Member
Posts: 568 Reputation: 8
– / – /
Joined: Nov 2008
|
O.P. RE: HELP - Arrays in the registry!
js code: WndLstId = ReadRegistry("Lst", "Id");
WndLstId.split(",");
WndLstTitle = ReadRegistry("Lst", "Title");
WndLstTitle.split(",");
// ...
Is that the right idea?
|
|
06-18-2009 07:56 PM |
|
|
Mnjul
forum super mod
plz wub me
Posts: 5396 Reputation: 58
– / /
Joined: Nov 2002
Status: Away
|
RE: HELP - Arrays in the registry!
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(",");
This post was edited on 06-18-2009 at 08:16 PM by Mnjul.
|
|
06-18-2009 08:15 PM |
|
|
whiz
Senior Member
Posts: 568 Reputation: 8
– / – /
Joined: Nov 2008
|
O.P. RE: RE: HELP - Arrays in the registry!
js code: var TmpLstId = ReadRegistry("Lst", "Id");
WndLstId = TmpLstId.split(",");
var TmpLstTitle = ReadRegistry("Lst", "Title");
WndLstTitle = TmpLstTitle.split(",");
// ...
Like that?
|
|
06-19-2009 03:56 PM |
|
|
CookieRevised
Elite Member
Posts: 15517 Reputation: 173
– / /
Joined: Jul 2003
Status: Away
|
RE: HELP - Arrays in the registry!
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).
This post was edited on 06-19-2009 at 09:34 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
|
|
06-19-2009 09:34 PM |
|
|
Pages: (2):
« First
[ 1 ]
2
»
Last »
|
|
|