AutoHotkey Community

It is currently May 27th, 2012, 2:32 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: ValVarSupr and Let
PostPosted: September 21st, 2005, 5:36 pm 
Offline

Joined: September 7th, 2004, 9:20 pm
Posts: 275
Location: France
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 21st, 2005, 7:57 pm 
Offline

Joined: February 14th, 2005, 10:54 am
Posts: 447
Location: Texas, Usa
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 :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 21st, 2005, 9:19 pm 
Offline

Joined: September 7th, 2004, 9:20 pm
Posts: 275
Location: France
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 22nd, 2005, 12:48 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 22nd, 2005, 2:34 am 
Offline

Joined: September 7th, 2004, 9:20 pm
Posts: 275
Location: France
OK I'll wait until it. Thanks Chris.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 22nd, 2005, 5:20 am 
Offline

Joined: February 14th, 2005, 10:54 am
Posts: 447
Location: Texas, Usa
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 :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 22nd, 2005, 4:47 pm 
Offline

Joined: September 7th, 2004, 9:20 pm
Posts: 275
Location: France
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 ?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 26th, 2005, 3:11 pm 
Offline

Joined: February 14th, 2005, 10:54 am
Posts: 447
Location: Texas, Usa
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 :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 26th, 2005, 11:21 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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% =
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 27th, 2005, 12:06 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 6th, 2005, 5:45 pm 
Offline

Joined: September 7th, 2004, 9:20 pm
Posts: 275
Location: France
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...


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot] and 2 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group