win286 Posted August 29, 2012 Share Posted August 29, 2012 (edited) In a loop I have an array with a generic name ($aIncoming) Local $aIncoming[3] = ['NAME', 'UN', 'User Name Here'] some items are based on variable content. The rest is handled in a case statement. $aIncoming[1] could be any one of 30-40 different qualifiers DN=Domain Name, MN=Machine Name, UR=URL Title, etc... Array will have 3 or more fields/elements Local $aIncoming[4] = ['NAME', 'VN', 'Vendor Name Here', 'Vendor ID Here']I create the name the array needs to be in a variable ($varName) Local $varName = "$a" & $aIncoming[0] & $aIncoming[1]I Want to have the equivalent of: $aNAMEUN = $aIncoming $aNAMEVN = $aIncomingAny help is appreciated. My alternative is to create numbered arrays and read the needed elements in a loop when needed.Local $aIncoming[3] = ['NAME', 'UN', 'User Name Here'] Local $varName = "$a" & $aIncoming[0] & $aIncoming[1] Local $varCnt = UBound($aIncoming) Msgbox(0, "What I Want is:", $varName &"[" & $varCnt & "] = ['" & $aIncoming[0] & "' , '" & $aIncoming[1] & "' , '" & $aIncoming[2] & "']") Edited August 31, 2012 by win286 Link to comment Share on other sites More sharing options...
BrewManNH Posted August 29, 2012 Share Posted August 29, 2012 Use Assign. 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 GudeHow 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 More sharing options...
win286 Posted August 29, 2012 Author Share Posted August 29, 2012 I've tried assign. I may be doing it wrong but it appears blank. Thanks. Link to comment Share on other sites More sharing options...
BrewManNH Posted August 29, 2012 Share Posted August 29, 2012 I don't think you're explaining very clearly what exactly it is that you are trying to do with the arrays and variables. What is the outcome of the variable's name and its contents supposed to be when it's done? 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 GudeHow 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 More sharing options...
win286 Posted August 29, 2012 Author Share Posted August 29, 2012 I would like to get an array name $aIncoming into another array which the name is found in the variable $varName and is based on the text "$a" and contents of $aIncoming[0] & $aIncoming[1]. I can assign one element from $aIncoming but not the array. I've tried many ways. Let me know if there is anything I can do to clarify my need. Thanks. Local $aIncoming[3] = ['NAME', 'UN', 'User Name Here'] Local $varName = "$a" & $aIncoming[0] & $aIncoming[1] Assign($varName, $aIncoming) ; the assign does nothing with the array, I can assign one element $aIncoming[2] but not what I want Execute($varName &"[" & $varCnt & "] = ['" & $aIncoming[0] & "' , '" & $aIncoming[1] & "' , '" & $aIncoming[2] & "']") ; the execute didn't work either ; Local $varCnt = UBound($aIncoming) Msgbox(0, "What I Want is:", $varName &"[" & $varCnt & "] = ['" & $aIncoming[0] & "' , '" & $aIncoming[1] & "' , '" & $aIncoming[2] & "']") Link to comment Share on other sites More sharing options...
jdelaney Posted August 29, 2012 Share Posted August 29, 2012 (edited) I'd just create a 2D array, and then pull the data necessary as required Global Enum $iArray1D_Domain = 0, _ $iArray1D_Machine, _ $iArray1D_URL, _ $iArray1D_UBound Global Enum $iArray2D_Def = 0, _ $iArray2D_Key, _ $iArray2D_Value, _ $iArray2D_UBound Global $aIncoming[$iArray1D_UBound][$iArray2D_UBound] Example of pulling data later: ; Example of later pulling the [Machine][Key], and [Machine][Value] $Key = $aIncoming[$iArray1D_Machine][$iArray2D_Key] $Value = $aIncoming[$iArray1D_Machine][$iArray2D_Value] Edited August 29, 2012 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
BrewManNH Posted August 29, 2012 Share Posted August 29, 2012 May I ask why you're trying to create an array this way? Explain what you want to do with this array/variable after you've created it, there's probably a much better way around this. 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 GudeHow 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 More sharing options...
win286 Posted August 30, 2012 Author Share Posted August 30, 2012 Sorry for the delayed response, forum restrictions didn't allow me to post again. I'm taking reporting data and creating an electronic version The data references in the program config file are what I'm following For things like Title, SubTitle, Header, SubHeader, etc... I create an array with that name $aTITLE and in the config file I get the reference TITLE05, TITLE07, TITLE10, TITLE11, etc... then I just split the reference text and Execute $isdk = stringright($aSDName[$iSD][1], 2) $sdval = Execute("$a" & StringTrimRight($aSDName[$iSD][1],2) & $qual & "[" & $isdk & "]") For data references with a qualifier I look for a ")" The data references would now look like NAME02(CN), NAME02(VN), etc... If stringright($aSDName[$iSD][1], 1) = ")" Then I will parce, set $qual and Execute with the qualifier not empty Thanks. Link to comment Share on other sites More sharing options...
BrewManNH Posted August 30, 2012 Share Posted August 30, 2012 That's not really clearing anything up very much. I'd do what jdelaney said and just create a dynamic 2D array and parse the data into one array. Creating multiple arrays for the data seems the long way round, and I'm not sure you can even do it with arrays like that. 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 GudeHow 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 More sharing options...
bogQ Posted August 30, 2012 Share Posted August 30, 2012 (edited) apparently no one understand him so one more longshot maybe he is looking for eval?!! $1 = 'D' $2 = 'a' $3 = 't' $4 = 'a' $Data = 'hi there' MsgBox(0, '', Eval($1&$2&$3&$4)) thought, whud not know if it'll work with arrays if not using some kinde of a loop to join variable array data before Eval. Edited August 30, 2012 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
dany Posted August 30, 2012 Share Posted August 30, 2012 I'm guessing OP is talking about variable variables like they have in PHP. If that's the case I'd advise to rethink your code as it's ambiguous, unreliable and a maintenance hell. Just go with jdelaney's suggestion and store your commands as strings and cross-reference the indexes between arrays. [center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF Link to comment Share on other sites More sharing options...
win286 Posted August 31, 2012 Author Share Posted August 31, 2012 The 2D array does follow the conventions I have been using better but the example makes no sense to me. Here is my attempt: expandcollapse popup#include Global $aMultiArray = 0 ;Simulate Incoming Data Local $aIncoming[4] = [3, 'NAME', 'UN', 'User Name Here'] BuildArray($aIncoming) $aIncoming = 0 Local $aIncoming[5] = [4, 'NAME', 'VN', 'Vendor Name Here', 'ID'] BuildArray($aIncoming) $aIncoming = 0 Local $aIncoming[4] = [3, 'NAME', 'CN', 'Customer Name Here'] BuildArray($aIncoming) Exit Func BuildArray($aSD) ;Check if array exists If UBound($aMultiArray) > 0 Then ;If array exists, get # of elements (col) ;Increase # of elements if needed ;Add row for data set Else ;If array doesn't exist, create array Dim $aMultiArray[$aSD[0]+1][1] EndIf ;Add data For $i = 0 to UBound($aSD) ;$aMultiArray[$i] = $aSD[$i] Next ;Display for Testing _ArrayDisplay($aMultiArray) _ArrayDisplay($aSD) Return 1 EndFunc Please let me know what I'm doing... Thanks. Link to comment Share on other sites More sharing options...
kylomas Posted August 31, 2012 Share Posted August 31, 2012 win286, I see that the heavy hitters are looking at this so I will offer this advice. Define your inputs and your expected results. The experts have a cagillion ways to skin a cat. 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 Link to comment Share on other sites More sharing options...
BrewManNH Posted August 31, 2012 Share Posted August 31, 2012 Here's one of the ways to skin said feline. expandcollapse popup#include <array.au3> Global $aMultiArray[2][5] ; make the second dimension as large as the largest incoming array you expect to see $aMultiArray[0][0] = 0 ;Simulate Incoming Data Local $aIncoming[4] = [3, 'NAME', 'UN', 'User Name Here'] BuildArray($aIncoming) $aIncoming = 0 Local $aIncoming[5] = [4, 'NAME', 'VN', 'Vendor Name Here', 'ID'] BuildArray($aIncoming) $aIncoming = 0 Local $aIncoming[4] = [3, 'NAME', 'CN', 'Customer Name Here'] BuildArray($aIncoming) Local $aIncoming[4] = [3, 'NAME', 'CN', 'Customer Name Here'] BuildArray($aIncoming) Local $aIncoming[4] = [3, 'NAME', 'CN', 'Customer Name Here'] BuildArray($aIncoming) ReDim $aMultiArray[$aMultiArray[0][0] + 1][5] ; shrinks the array down to just large enough to hold the data it contains _ArrayDisplay($aMultiArray) Exit Func BuildArray($aSD) ; Make the array $aMultiArray dynamically sized so there shouldn't be a problem with adding more data $aMultiArray[0][0] = $aMultiArray[0][0] + 1 If $aMultiArray[0][0] > UBound($aMultiArray) - 1 Then ReDim $aMultiArray[$aMultiArray[0][0] + 1000][5] EndIf ;Add data For $i = 0 To UBound($aSD) - 1 $aMultiArray[$aMultiArray[0][0]][$i] = $aSD[$i] Next ;Display for Testing _ArrayDisplay($aMultiArray) Return 1 EndFunc ;==>BuildArray 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 GudeHow 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 More sharing options...
kylomas Posted August 31, 2012 Share Posted August 31, 2012 win286, Is you input comming from a file? If so, is each record in the file delimited (perhaps by a comma)? The first element in each row of your array seems to be an indicator of the number of following elements. If so, what is your intended use of this value? 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 Link to comment Share on other sites More sharing options...
kylomas Posted August 31, 2012 Share Posted August 31, 2012 win286, This may be usefull to you. The following creates a 2d array of variable columns from a comma delimited file. #include <file.au3> #include <Array.au3> Opt("MustDeclareVars", 1) dim $file,$a1,$a2 $file = "some.comma.delimited.file" ; read the file to an array splitting on @LF $a1 = stringsplit(fileread($file),@lf,1) ; define vars for munber of rows and max number of columns local $rows = ubound($a1),$cols = 0 ; spin the array of records splitting on the field delimiter of each row to find the max col value for $i = 0 to ubound($a1) - 1 $a2 = stringsplit($a1[$i],',',1) if ubound($a2) > $cols then $cols = ubound($a2) next ; define your final array local $aFinal[$rows][$cols] ; finally, populate the final 2d array from the array created during the file read for $i = 1 to $rows - 1 $a2 = stringsplit($a1[$i],',',1) for $j = 0 to ubound($a2) - 1 $aFinal[$i][$j] = $a2[$j] Next next _arraydisplay($aFinal) 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 Link to comment Share on other sites More sharing options...
win286 Posted August 31, 2012 Author Share Posted August 31, 2012 Thanks BrewManNH, This gets me moving again! Is the ReDim process slow or slows down with data in the array? Just trying to understand why the ReDim shouldn't be in the loop as +1 vs. seading the array with +1000. I now know enough to ask a specific question! :-) Thanks again. Link to comment Share on other sites More sharing options...
win286 Posted August 31, 2012 Author Share Posted August 31, 2012 kylomas - No, the data is coming from a case statement that's already parsed. I found that there were items I had to loop through again to make things work. Thanks. Also, I don't know how to change the subject or mark this thread as resolved. Thanks! Link to comment Share on other sites More sharing options...
kylomas Posted August 31, 2012 Share Posted August 31, 2012 win286, Redim is slow and should not be used in a loop. A common technique for redim is to increase the size of the array by 50 percent of its size at the time of redim. Another caution, _arraydisplay is slow and has a limit of appx 60,000 + rows (in case you are using larger arrays) 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 Link to comment Share on other sites More sharing options...
kylomas Posted August 31, 2012 Share Posted August 31, 2012 win286, Go to the first post and you can edit the title using the full editor. Most people prepend "[solved]" to the title. 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 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