Sarg Posted April 20, 2009 Share Posted April 20, 2009 After much experimentation, I discovered that I could read from an array with a string reference like so: CODE Const $num_PCs = 13 Const $num_attrs = 12 Const $IPAddr = 3 Const $SubMask = 4 Const $DefGate = 5 ... ... ... Func qr ( $sArrayName, Const $iElement ) ; this is the function in question, qr for Quick Read, takes a string and an index Local $iTrueElement If IsNumber($iElement) Then ; if iElement is really an index ... Return Execute("$avPC_" & $sArrayName & "[" & $iElement &"]") ; ... then read the value and return it Else $iTrueElement = Execute("$" & $iElement) ; otherwise convert it to an index by using the constants Return Execute("$avPC_" & $sArrayName & "[" & $iTrueElement &"]") ; ... and read/return that EndIf EndFunc ... ... ... Dim $avPC_List [$num_PCs] = ["ttinsley","knguyen","jsmith","bwendall","tamhearst","wfarmer","sbrindal","jwerner","hfelton","vtucker","melder","aricker","dashmore"] Dim $avPC_ttinsley [$num_attrs] = ["ttinsley","MG97F3","Indianapolis","10.125.24.51","255.255.254.0","10.125.24.1","Win2k3",1494,"c:\vpnclient\corp_primary.pcf",1,0,0] ... ... ... Local $sActive_PC = "" ... For $sPCCounter in $avPC_List ; Loop through the list of PC, by username $sActive_PC = qr($sPCCounter,"IPAddr") ; set sActive_PC to the IP Address located in the PC's array ... ... ... This works well. However, the same can not be said for the function to alter the information in the array! No matter what I try, it just refuses to set. I managed to get it to store "$avPC_bwendall[11] = 2" in a variable named $setthis (my frustration is showing!) but even Execute($setthis) isn't doing anything. Anyone able to lend a hand? Link to comment Share on other sites More sharing options...
bo8ster Posted April 20, 2009 Share Posted April 20, 2009 Do you have any code where u attempt to do this? Posting your code really helps - also don't forget to add indents for readability. Lastly welcome to the forum. Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic] Link to comment Share on other sites More sharing options...
martin Posted April 20, 2009 Share Posted April 20, 2009 After much experimentation, I discovered that I could read from an array with a string reference like so: CODE Const $num_PCs = 13 Const $num_attrs = 12 Const $IPAddr = 3 Const $SubMask = 4 Const $DefGate = 5 ... ... ... Func qr ( $sArrayName, Const $iElement ) ; this is the function in question, qr for Quick Read, takes a string and an index Local $iTrueElement If IsNumber($iElement) Then ; if iElement is really an index ... Return Execute("$avPC_" & $sArrayName & "[" & $iElement &"]") ; ... then read the value and return it Else $iTrueElement = Execute("{:content:}quot; & $iElement) ; otherwise convert it to an index by using the constants Return Execute("$avPC_" & $sArrayName & "[" & $iTrueElement &"]") ; ... and read/return that EndIf EndFunc ... ... ... Dim $avPC_List [$num_PCs] = ["ttinsley","knguyen","jsmith","bwendall","tamhearst","wfarmer","sbrindal","jwerner","hfelton","vtucker","melder","aricker","dashmore"] Dim $avPC_ttinsley [$num_attrs] = ["ttinsley","MG97F3","Indianapolis","10.125.24.51","255.255.254.0","10.125.24.1","Win2k3",1494,"c:\vpnclient\corp_primary.pcf",1,0,0] ... ... ... Local $sActive_PC = "" ... For $sPCCounter in $avPC_List ; Loop through the list of PC, by username $sActive_PC = qr($sPCCounter,"IPAddr") ; set sActive_PC to the IP Address located in the PC's array ... ... ... This works well. However, the same can not be said for the function to alter the information in the array! No matter what I try, it just refuses to set. I managed to get it to store "$avPC_bwendall[11] = 2" in a variable named $setthis (my frustration is showing!) but even Execute($setthis) isn't doing anything. Anyone able to lend a hand?To set a variable using a string you need Assign BUT it can't be used with arrays. You would have to have an array of arrays and pass elements only to do what you want. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now