Jump to content

Accessing a variable with an array element.


Recommended Posts

Global $Active0 , $Active1 , $Active2

$array[3][3] = [ _
[ "Tyranna"     , $Active0 , "My Street ] , _
[ "AutoIt"      , $Active1 , "Your Street" ] , _
[ "Version3"    , $Active2 , "Their Street ]]

Func Main() 

    $Active0 = 1
    $Active1 = 0
    $Active2 = 1
    
    Output()
    
EndFunc

Func Output()

    For $i = 0 to 2
        For $i = 0 to 2
            ConsoleWrite( $array[$i][0] , $array[$i][1] , $array[$i][2] )
        Next
    Next

EndFunc

I want to be able to access the current value of a variable through an array element somewhat like this.
The middle array element when accessed needs to return the current value of the variable.

Is there a way to say  "value of" array[0][1] , "value of" array[1][1], "value of" array[2][1] ?

Edited by Tyranna


 

Link to comment
Share on other sites

7 minutes ago, Tyranna said:

Is there a way to say  "value of" array[0][1] , "value of" array[1][1], "value of" array[2][1] ?

For $i = 0 To UBound($arrSomeArray) - 1
    ConsoleWrite("The value of " & "$arrSomeArray[" & $i & "][1] is " & $arrSomeArray[$i][1] & @CRLF)
Next

:)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

Well , maybe I am not clear.  What I am trying to do is access the current value of the $Active variables by accessing an array element.
I am creating or reading in the array first and then changing the variable values and want to access the new values by accessing the
array elements.   I want to somehow link the array element and the CURRENT variable value without reloading the array. Maybe making the
array element a pointer to the other variable.  Not sure exactly how.


 

Link to comment
Share on other sites

Yeah , I have seen that one before , but I really do not want to jump through a dozen hoops to get a variable value.

What about making the Array element a string , and doing some kind of expansion on it ?  Seems like I have seen something like

that before...


 

Link to comment
Share on other sites

I don

9 minutes ago, Tyranna said:

Yeah , I have seen that one before , but I really do not want to jump through a dozen hoops to get a variable value.

you may not have much choice here except to write it in C or C++

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

Try this:

Global $Active0, $Active1, $Active2

Global $array[3][3] = [["Tyranna", "Active0", "My Street "], ["AutoIt", "Active1", "Your Street"], ["Version3", "Active2", "Their Street "]]
Main()
Func Main()

    $Active0 = 1
    $Active1 = 0
    $Active2 = 1

    Output()

EndFunc   ;==>Main

Func Output()

    For $i = 0 To 2
        ConsoleWrite("$Active" & $i & " = " & Eval($array[$i][1]) & @CRLF)
    Next

EndFunc   ;==>Output

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

This is the ANSWER!

Thanks.  Looks like all you have to do is  remove the $ from the front of the variable name in the array ,  and EVAL grabs the global variables value...

I just tested it and it seems to run correct .

All smiles now. 8)


 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...