Sign in to follow this  
Followers 0
dewclaws

Variable reference inside of AutoIT?

4 posts in this topic

Is it possible to have Variable references stored inside an array and use them? For example, I have an array with my Gui page controls stored in it, then later when I want this page active, I iterate through the array section I need and turn on the controls listed.

example:

dim $PageControls[5][4]

; --- Page 2 Form 
    $PAGECONTROLS[2] = ["$page2_Radio1", "$page2_Radio2", "$page3_Radio", FALSE]

    $page2_PageCaption = "Please select one of the following  Tasks:"
    $page2_Description = FALSE; false to hide 
    $page2_Radio1 = GUICtrlCreateRadio("Assign a IP Address ", 200, 112, 241, 17)
    GUICtrlSetState(-1, $GUI_HIDE)
    $page2_Radio2 = GUICtrlCreateRadio("Reset this box", 200, 149, 249, 17)
    GUICtrlSetState(-1, $GUI_HIDE)
    $page2_Radio3 = GUICtrlCreateRadio("Restore this box to factory defaults ", 200, 185, 257, 17)
    GUICtrlSetState(-1, $GUI_HIDE)

; -- MUCH CODE LATER 
; 
; Turn on page two.. 
        For $x = 0 To Ubound($PAGECONTROLS[2]) -1
            $var = PAGECONTROLS[2][$x]
            if not $var then 
                GUICtrlSetState($var, $GUI_SHOW)
            exitif
        Next

Dewclaws

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

$PAGECONTROLS[2] = [$page2_Radio1, $page2_Radio2, $page3_Radio, FALSE]

you should also look at the controls section talking about even though it's not explicitly disallowed, you shouldn't interchange data types in an array (ie, numbers, and FALSE)

Edit:

Sorry I misunderstood what you're asking and I believe the answer is no, you cannot store a variable in an array. you can store a variable's VALUE insdie an array but not the variable itself. What you can do tho is use logic to fix your problem. My code example above stores the value of $page2_Radio1 in the $PAGECONTROLS[2][0], $page2_Radio2 in the $PAGECONTROLS[2][1] spot, etc -- so, when referencing your $PAGECONTROLS array, your controls will be logically associated so you'll know which numbered control should exist in the which element of the 2nd dimension of the $PAGECONTROLS array.

Edited by thepip3r

My Additions:- RunAs AdminDeviant Fun:- Variable Sound Volume

Share this post


Link to post
Share on other sites

Is it possible to have Variable references stored inside an array and use them? For example, I have an array with my Gui page controls stored in it, then later when I want this page active, I iterate through the array section I need and turn on the controls listed.

example:

dim $PageControls[5][4]

; --- Page 2 Form 
    $PAGECONTROLS[2] = ["$page2_Radio1", "$page2_Radio2", "$page3_Radio", FALSE]

    $page2_PageCaption = "Please select one of the following  Tasks:"
    $page2_Description = FALSE; false to hide 
    $page2_Radio1 = GUICtrlCreateRadio("Assign a IP Address ", 200, 112, 241, 17)
    GUICtrlSetState(-1, $GUI_HIDE)
    $page2_Radio2 = GUICtrlCreateRadio("Reset this box", 200, 149, 249, 17)
    GUICtrlSetState(-1, $GUI_HIDE)
    $page2_Radio3 = GUICtrlCreateRadio("Restore this box to factory defaults ", 200, 185, 257, 17)
    GUICtrlSetState(-1, $GUI_HIDE)

; -- MUCH CODE LATER 
; 
; Turn on page two.. 
        For $x = 0 To Ubound($PAGECONTROLS[2]) -1
            $var = PAGECONTROLS[2][$x]
            if not $var then 
                GUICtrlSetState($var, $GUI_SHOW)
            exitif
        Next
Your array references are invalid in several places:

1. Declaring the array with "Dim $PageControls[5][4]" is OK, though Global or Local should be explicitly used.

2. You can only set an entire row of data at once at the line that declares the array. It would look like this:

Global $PAGECONTROLS[5][4] = [[4, "", "", ""], _
        ["$page1_Radio1", "$page1_Radio2", "$page1_Radio3", False], _
        ["$page2_Radio1", "$page2_Radio2", "$page2_Radio3", False], _
        ["$page3_Radio1", "$page3_Radio2", "$page3_Radio3", False], _
        ["$page4_Radio1", "$page4_Radio2", "$page4_Radio3", False]]
Otherwise, you'll have to set each element individually with both indexes provided:
Global $PAGECONTROLS[5][4] 
$PAGECONTROLS[2][0] = "$page2_Radio1"
$PAGECONTROLS[2][1] = "$page2_Radio2"
$PAGECONTROLS[2][2] = "$page2_Radio3"
$PAGECONTROLS[2][0] = False

3. There is no reason to take the values out of the array and assign them to other named variables. You can put the array references straight into the code that uses the values:

Global $PAGECONTROLS[5][4]

For $iPage = 1 To 4
    $PAGECONTROLS[$iPage][0] = GUICtrlCreateRadio("Assign a IP Address ", 200, 112, 241, 17)
    GUICtrlSetState(-1, $GUI_HIDE)
    $PAGECONTROLS[$iPage][1] = GUICtrlCreateRadio("Reset this box", 200, 149, 249, 17)
    GUICtrlSetState(-1, $GUI_HIDE)
    $PAGECONTROLS[$iPage][2] = GUICtrlCreateRadio("Restore this box to factory defaults ", 200, 185, 257, 17)
    GUICtrlSetState(-1, $GUI_HIDE)
    $PAGECONTROLS[$iPage][3] = False; false to hide
Next

; -- MUCH CODE LATER 

; Turn on page two.. 
$iCurrentPage = 2
For $x = 0 To 3
    GUICtrlSetState($PAGECONTROLS[$iCurrentPage][$x], $GUI_SHOW)
Next

4. To get the Ubound of the second dimension of the array would be just:

For $x = 0 To Ubound($PAGECONTROLS, 2) - 1

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Thank.. I'll try this.

- Shane

Your array references are invalid in several places:

1. Declaring the array with "Dim $PageControls[5][4]" is OK, though Global or Local should be explicitly used.

2. You can only set an entire row of data at once at the line that declares the array. It would look like this:

Global $PAGECONTROLS[5][4] = [[4, "", "", ""], _
        ["$page1_Radio1", "$page1_Radio2", "$page1_Radio3", False], _
        ["$page2_Radio1", "$page2_Radio2", "$page2_Radio3", False], _
        ["$page3_Radio1", "$page3_Radio2", "$page3_Radio3", False], _
        ["$page4_Radio1", "$page4_Radio2", "$page4_Radio3", False]]
Otherwise, you'll have to set each element individually with both indexes provided:
Global $PAGECONTROLS[5][4] 
$PAGECONTROLS[2][0] = "$page2_Radio1"
$PAGECONTROLS[2][1] = "$page2_Radio2"
$PAGECONTROLS[2][2] = "$page2_Radio3"
$PAGECONTROLS[2][0] = False

3. There is no reason to take the values out of the array and assign them to other named variables. You can put the array references straight into the code that uses the values:

Global $PAGECONTROLS[5][4]

For $iPage = 1 To 4
    $PAGECONTROLS[$iPage][0] = GUICtrlCreateRadio("Assign a IP Address ", 200, 112, 241, 17)
    GUICtrlSetState(-1, $GUI_HIDE)
    $PAGECONTROLS[$iPage][1] = GUICtrlCreateRadio("Reset this box", 200, 149, 249, 17)
    GUICtrlSetState(-1, $GUI_HIDE)
    $PAGECONTROLS[$iPage][2] = GUICtrlCreateRadio("Restore this box to factory defaults ", 200, 185, 257, 17)
    GUICtrlSetState(-1, $GUI_HIDE)
    $PAGECONTROLS[$iPage][3] = False; false to hide
Next

; -- MUCH CODE LATER 

; Turn on page two.. 
$iCurrentPage = 2
For $x = 0 To 3
    GUICtrlSetState($PAGECONTROLS[$iCurrentPage][$x], $GUI_SHOW)
Next

4. To get the Ubound of the second dimension of the array would be just:

For $x = 0 To Ubound($PAGECONTROLS, 2) - 1

:)


Dewclaws

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0