 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Nemroth
Joined: 07 Sep 2004 Posts: 262 Location: France
|
Posted: Wed Sep 21, 2005 5:36 pm Post subject: ValVarSupr and Let |
|
|
Is it possible to implement a command like :
ValVarSupr, VarList
in witch "VarList" would be a variable in witch you put a comma delimited list fo variables names.
If the contents of VarList would be for example "OneVar, AnOther, OneMore, AndAgainOne", this command would do :
OneVar=
AnOther=
OneMore=
AndAgainOne=
This can be usefull for a Gosub procedure or for the exit procedure of a GUI window to clear all the variables used by the procedure in a very fast way, and to be sure that the next time you will call the procedure, there will not be "remaining" values in the variables.
In the same spirit, a "Let" command can be usefull to initialize some variables with ... initial values, like :
Let OneVar=1, AnOther=2, OneMore=3, AndAgainOne=4 |
|
| Back to top |
|
 |
Invalid User
Joined: 14 Feb 2005 Posts: 442 Location: Texas, Usa
|
Posted: Wed Sep 21, 2005 7:57 pm Post subject: |
|
|
I was thinking of something like this the other day too, it would be very useful, I have an editor I am working on now that, when closed, not exited, should clear upwords of 30,000 variables(or more). needless to say I have been procrastinating on it because I see no easy solution... wait... | Code: |
ListOfVar = %AListOfVarsToBeCleared%
Loop, parse, ListOfVars, `,
%A_LoopField% = |
now for an easy way to gather a list of the variables since they are all dynamic.... _________________ my lame sig  |
|
| Back to top |
|
 |
Nemroth
Joined: 07 Sep 2004 Posts: 262 Location: France
|
Posted: Wed Sep 21, 2005 9:19 pm Post subject: |
|
|
Very good suggestion. So simple... Thanks, Invalid User. But of course not usable for dynamic ones... For the "Let" suggestion, finally not very usefull !!!
OneVar=1
AnOther=2
OneMore=3
AndAgainOne= 4 |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Thu Sep 22, 2005 12:48 am Post subject: |
|
|
Support for true arrays might make things like this easier. Such an array can probably be cleared or released from memory with a single command.
But this is another of those "someday" features. |
|
| Back to top |
|
 |
Nemroth
Joined: 07 Sep 2004 Posts: 262 Location: France
|
Posted: Thu Sep 22, 2005 2:34 am Post subject: |
|
|
| OK I'll wait until it. Thanks Chris. |
|
| Back to top |
|
 |
Invalid User
Joined: 14 Feb 2005 Posts: 442 Location: Texas, Usa
|
Posted: Thu Sep 22, 2005 5:20 am Post subject: |
|
|
Nemroth, what could be done, and it is what I have already done(but not coded yet) is while creating a dynamic var, store the name of that var in a list seperate from the dynamic one.
ListOfVars = %ListOfVars%|%NameOfVar%
NameOfDynamicVar%NameOfVar% = Some text
According you know the prefix of "NameOfDynamicVar" you can parse the know list and use it to clear the dynamic vars. This work around may be best until an actual command is made concidering its probly not a high priority. _________________ my lame sig  |
|
| Back to top |
|
 |
Nemroth
Joined: 07 Sep 2004 Posts: 262 Location: France
|
Posted: Thu Sep 22, 2005 4:47 pm Post subject: |
|
|
| Invalid User wrote: | ListOfVars = %ListOfVars%|%NameOfVar%
NameOfDynamicVar%NameOfVar% = Some text |
OK but excuse my bad knowledge of AHK, I never seen the | character in a (dynamic) variable definition (or at least I don't remember that). What does it means ? (Of course I seen it in lists for DropDownList, but I don't remember to have seen it elsewere).
Thanks for your answers.
Edit : Sorry : after reading the help file : | = bitwise or ? For what do you use it ? |
|
| Back to top |
|
 |
Invalid User
Joined: 14 Feb 2005 Posts: 442 Location: Texas, Usa
|
Posted: Mon Sep 26, 2005 3:11 pm Post subject: |
|
|
My two choices of delimters for lists are | and ,. I would use these in creating lists, probly (I havnt yet) used them in a dynamic var definition, besides, I dont think the | char is allowing in a variables name. A dynamic variable reference looks like:
| Code: |
MyVar%A_Index% = %A_LoopField%
|
Where part of a variable is unknown, here its the index of the loop, so the first element in the list being parsed would be in the variable named "MyVar1"
You can refer to again later by using this:
| Code: |
MyNewVar%A_Index% := MyVar%A_Index%
|
This would simply make a copy of the array of MyVar and store it in MyNewVar array. _________________ my lame sig  |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4002 Location: Pittsburgh
|
Posted: Mon Sep 26, 2005 11:21 pm Post subject: |
|
|
Nemroth, is this what you meant? | Code: | Init(" a,1, b,2, MyVar,xyz ")
ListVars
MsgBox
Clear(" a, b, MyVar ")
ListVars
MsgBox
Init(List) ; Init("VarName1, value1, VarName2, value2...")
{ ; VarName1 =value1, VarName2 =value2...
Local x
Loop Parse, list, `,, %A_Space%%A_Tab%
If (Mod(A_Index,2) = 1)
x = %A_LoopField%
Else
%x% = %A_LoopField%
}
Clear(list) ; Clear("VarName1, VarName2 ...")
{ ; VarName1=, VarName2=,...
Loop Parse, list, `,, %A_Space%%A_Tab%
%A_LoopField% =
} |
|
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4002 Location: Pittsburgh
|
Posted: Tue Sep 27, 2005 12:06 am Post subject: |
|
|
This version of the Init() function can handle variable references. You could extend it further for indexed array elements, too. | Code: | Init(" a,99, b,%a%, MyVar,xyz ")
ListVars
MsgBox
Init(List) ; Init("VarName1, value1, VarName2, value2...")
{ ; VarName1= value1, VarName2= value2...
Local x, y
Loop Parse, list, `,, %A_Space%%A_Tab%
If (A_Index & 1 = 1)
x = %A_LoopField%
Else If A_LoopField contains `%
{
StringReplace y, A_LoopField, `%,, A
%x% := %y%
}
Else
%x% = %A_LoopField%
} |
I posted more elaborate versions of these functions here |
|
| Back to top |
|
 |
Nemroth
Joined: 07 Sep 2004 Posts: 262 Location: France
|
Posted: Thu Oct 06, 2005 5:45 pm Post subject: |
|
|
| Sorry for the late answer, I was very busy these last times. Just to say thank you to Invalid User and Laszlo for your answers, they are very interesting, as usual... |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|