Jump to content

Recommended Posts

Posted (edited)

Hello, i'm trying to rename a variable to another variable name (not the value attached to the variable).  This would save me TONS of coding.

Here is an example:

 

<autoit>

Local $clear1="$SATJ"  ;sets the $clear1 variable to become $SATJ

GUICtrlSetState($clear1 & "3", $GUI_UNCHECKED)  ;i want this to come out to be $SATJ3, it should look something like - GUICtrlSetState($SATJ3, $GUI_UNCHECKED)

</autoit>

Is this possible?  I've been searching all the forums and help files for hours.  My javascript friend referenced me to the solution on JS, which lead me to searching through the "assign" help on autoit, but not much info on it.

I've already tried
<autoit>

Assign($clear1, $SATJ)

</autoit>

 

any help is greatly appreciated!!! 

Edited by kartune
Posted

you are only ever assigning values to variables.

How are you confirming that $clear1 & "3" is even a control before you set its state?

Somewhere between the creation of those controls and the setting of their state, I would declare all possible variables; and adjust the values as necessary with case statements.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

  • Moderators
Posted

Moved to the appropriate forum, as the DEV forum very clearly states:

Quote

Do not create AutoIt-related topics here, use AutoIt General Help and Support

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted

Well i'm trying to avoid hundreds of unnecessary lines of code, i was hoping there'd be an easy way to do this.

This action needs to happen to several different variables under different situtations

;;; This is for the SATJ situation ;;;

GUICtrlSetState($SATJ0, $GUI_UNCHECKED) ;removes radio button selections
GUICtrlSetState($SATJ3, $GUI_UNCHECKED)
GUICtrlSetState($SATJ6, $GUI_UNCHECKED)
GUICtrlSetState($SATJ12, $GUI_UNCHECKED)
GUICtrlSetState($SATJ18, $GUI_UNCHECKED)
GUICtrlSetState($SATJ20, $GUI_UNCHECKED)
GUICtrlSetState($SATJ30, $GUI_UNCHECKED)
GUICtrlSetState($SATJ60, $GUI_UNCHECKED)
GUICtrlSetState($SATJ100, $GUI_UNCHECKED)
GUICtrlSetState($SATJ120, $GUI_UNCHECKED)

 

;;; This is for the OBCD situation ;;;

GUICtrlSetState($OBCD0, $GUI_UNCHECKED) ;removes radio button selections
GUICtrlSetState($OBCD3, $GUI_UNCHECKED)
GUICtrlSetState($OBCD6, $GUI_UNCHECKED)
GUICtrlSetState($OBCD12, $GUI_UNCHECKED)
GUICtrlSetState($OBCD18, $GUI_UNCHECKED)
GUICtrlSetState($OBCD20, $GUI_UNCHECKED)
GUICtrlSetState($OBCD30, $GUI_UNCHECKED)
GUICtrlSetState($OBCD60, $GUI_UNCHECKED)
GUICtrlSetState($OBCD100, $GUI_UNCHECKED)
GUICtrlSetState($OBCD120, $GUI_UNCHECKED)

 

;;; What i would love to have it be ;;;

GUICtrlSetState($changeableVar0, $GUI_UNCHECKED) ;removes radio button selections
GUICtrlSetState($changeableVar3, $GUI_UNCHECKED)
GUICtrlSetState($changeableVar6, $GUI_UNCHECKED)

...

...

...

 

So if i could just rename the variable according to the situation, i could set it to a function and call the same function for every situation.

Hope that makes sense.

Posted

you can do assignments with variables, if this is headed down your mental path we probably just need to work out where in your script it would best suit, which depends a lot on how you are initially creating the controls and storing IDs as @kylomas inquired.

for $i = 1 to 3
assign("var" & $i , $i)
next

msgbox(0, '' , eval("var1"))
msgbox(0, '' , eval("var2"))
msgbox(0, '' , eval("var3"))

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Posted (edited)

Hi, Thanks for your responses and sorry i forgot to mention I am not an advanced scripter nor knowledgeable in programming languages.

So i don't exactly understand your questions in regards to storing them as controls or ids.  I'm guessing ID? 

 

What i need is to at any point be able to have autoit rename the variable when stated to.

So if i wanted every code line that contains:  $clear1     to actually become $changedvariable
Everytime the script sees a $clear1 --- it actually executes it as the variable actually being:  $changedvariable           ;NOT $clear1

I apologize this is harder than expected to explain haha.

In my script, i will be alternating back and forth.... so at certain situations, i need:  $clear1     : to actually be

$changedvar1

at other times it will be:     $changedvar2

then others:     $changedvar65
and so on....

I don't want to write out all those lines of code containing:     $clear1          :for everytime i need that specific code for:      $changedvar

I hope this makes sense.  If this works out you will be saving me a lot of copy pasted lines lol.

Edited by kartune
correction grammar
Posted

kartune,

You have sets of variables containing the control id's of sets of controls that you wish to manipulate as a set without repeating code for each individual variable in each set.

When you create a control that you wish to manipulate you create a corresponding control id.  That control id can be stored in a simple variable, e.g. $myctl = something or in an array, e.g. $checkbox[$1] = something.

The problem you have is program organization, in that you need to manage control id's in sets.  Arrays are perfect for that.  Without example code or more detail I can't really comment in more detail.  I would caution you to stay away from eval/assign if possible.

Good Luck,

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Posted
3 minutes ago, kylomas said:

kartune,

You have sets of variables containing the control id's of sets of controls that you wish to manipulate as a set without repeating code for each individual variable in each set.

When you create a control that you wish to manipulate you create a corresponding control id.  That control id can be stored in a simple variable, e.g. $myctl = something or in an array, e.g. $checkbox[$1] = something.

The problem you have is program organization, in that you need to manage control id's in sets.  Arrays are perfect for that.  Without example code or more detail I can't really comment in more detail.  I would caution you to stay away from eval/assign if possible.

Good Luck,

kylomas

thank you very much, that was informative.  I will look into arrays and learn about them!

Posted (edited)

trying to work up a simple example...

Her you go...hope it makes sense, if not just ask...

#include <GUIConstantsEx.au3>
#include <Array.au3>

#AutoIt3Wrapper_Add_Constants=n

Local $gui010 = GUICreate('CHK Box Example', 400, 600)

; arrays to store control ids in, one array per group

Local $chkbox_group1[8]
Local $chkbox_group2[15]
Local $chkbox_group3[4]

; create the controls storing the ctlid in the appropriate array

For $1 = 0 To UBound($chkbox_group1) - 1
    $chkbox_group1[$1] = GUICtrlCreateCheckbox('ChkBox-G1 ' & StringFormat('%02i', $1), 10, $1 * 30 + 10, 100, 20)
Next
For $1 = 0 To UBound($chkbox_group2) - 1
    $chkbox_group2[$1] = GUICtrlCreateCheckbox('ChkBox-G2 ' & StringFormat('%02i', $1), 130, $1 * 30 + 10, 100, 20)
Next
For $1 = 0 To UBound($chkbox_group3) - 1
    $chkbox_group3[$1] = GUICtrlCreateCheckbox('ChkBox-G3 ' & StringFormat('%02i', $1), 260, $1 * 30 + 10, 100, 20)
Next

Local $abuttons[3]

; an array of buttons to clear each group

For $1 = 0 To UBound($abuttons) - 1
    $abuttons[$1] = GUICtrlCreateButton('Clear Group ' & $1 + 1, $1 * 130 + 5, 550, 100, 20)
Next


GUISetState()

Local $msg

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $gui_event_close
            Exit
        Case $abuttons[0]
            _clear(1)
        Case $abuttons[1]
            _clear(2)
        Case $abuttons[2]
            _clear(3)
    EndSwitch
WEnd

Func _clear($group)

    ; semi reasonable use of eval...resolves to $chkbox_group1 or $chkbox_group2 or $chkbox_group3...

    For $1 = 0 To UBound(Eval('chkbox_group' & $group)) - 1
        GUICtrlSetState(Eval('chkbox_group' & $group)[$1], $gui_unchecked)
    Next

EndFunc   ;==>_clear

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Posted

Thanks!  i'm gonna study this, but just from the looks of it already, i should've started all my code using arrays.

Unfortunately i have so much code already written haha.  

I've learned a lot already, very grateful for your help!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...