AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ValVarSupr and Let

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
Nemroth



Joined: 07 Sep 2004
Posts: 262
Location: France

PostPosted: Wed Sep 21, 2005 5:36 pm    Post subject: ValVarSupr and Let Reply with quote

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
View user's profile Send private message
Invalid User



Joined: 14 Feb 2005
Posts: 442
Location: Texas, Usa

PostPosted: Wed Sep 21, 2005 7:57 pm    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
Nemroth



Joined: 07 Sep 2004
Posts: 262
Location: France

PostPosted: Wed Sep 21, 2005 9:19 pm    Post subject: Reply with quote

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
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Thu Sep 22, 2005 12:48 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Nemroth



Joined: 07 Sep 2004
Posts: 262
Location: France

PostPosted: Thu Sep 22, 2005 2:34 am    Post subject: Reply with quote

OK I'll wait until it. Thanks Chris.
Back to top
View user's profile Send private message
Invalid User



Joined: 14 Feb 2005
Posts: 442
Location: Texas, Usa

PostPosted: Thu Sep 22, 2005 5:20 am    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
Nemroth



Joined: 07 Sep 2004
Posts: 262
Location: France

PostPosted: Thu Sep 22, 2005 4:47 pm    Post subject: Reply with quote

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
View user's profile Send private message
Invalid User



Joined: 14 Feb 2005
Posts: 442
Location: Texas, Usa

PostPosted: Mon Sep 26, 2005 3:11 pm    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
Laszlo



Joined: 14 Feb 2005
Posts: 4002
Location: Pittsburgh

PostPosted: Mon Sep 26, 2005 11:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4002
Location: Pittsburgh

PostPosted: Tue Sep 27, 2005 12:06 am    Post subject: Reply with quote

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
View user's profile Send private message
Nemroth



Joined: 07 Sep 2004
Posts: 262
Location: France

PostPosted: Thu Oct 06, 2005 5:45 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group