1905russell Posted May 31, 2010 Share Posted May 31, 2010 This was wishful thinking - I took the example from the help manual but could not figure it out. I need the 2d array string combined for a combobox list. Please help. #include <Array.au3> Local $avArray[2][5] = [["JPM", "Holger", "Jon", "Larry", "Jeremy"], ["Valik", "Cyberslug", "Nutster", "JdeB", "Tylo"]] ;_ArrayDisplay($avArray, "$avArray as a 2D array") _ArrayDisplay($avArray, "$avArray as a 2D array, transposed", -1, 1) MsgBox(0, "_ArrayToString()", _ArrayToString($avArray));???????????? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 31, 2010 Moderators Share Posted May 31, 2010 (edited) The _ArrayToString is only for single dimensions. You'd have to loop through your 2d array and put the info in the order you wanted with the delim you wanted. pseudoGlobal $s_delim = "|" Global $s_out = "" For $i = 0 To UBound($avArray, 1) - 1 ; Start with dimension one For $j = 0 To UBound($avArray, 2) - 1 $s_out &= $avArray[$i][$j] & $s_delim Next Next $s_out = StringTrimRight($s_out, StringLen($s_delim)) ConsoleWrite($s_out & @CRLF) Edited May 31, 2010 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
1905russell Posted May 31, 2010 Author Share Posted May 31, 2010 Thanks Smoke_N. Much appreciated. So when you say put into order I want – do you mean split, search and concatenate after the loop or must I first rearrange the loop to give me the preferred order ie. reading array left to right: JPM|Valik|Holger|Cyberslug|Jon|Nutster|Larry|JdeB|Jeremy|Tylo Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 31, 2010 Moderators Share Posted May 31, 2010 Thanks Smoke_N. Much appreciated. So when you say put into order I want – do you mean split, search and concatenate after the loop or must I first rearrange the loop to give me the preferred order ie. reading array left to right: JPM|Valik|Holger|Cyberslug|Jon|Nutster|Larry|JdeB|Jeremy|Tylo Yes, you'd need to concatenate as I showed in the example. Without looking at _ArrayToString(), I'm sure this is what it does. Left to Right is done in the loops I provided the pseudo code for. If you need to go backwards (right to left) on the first dimension only you'd do something like: For $i = UBound($avArray, 1) - 1 To 0 Step - 1 For $j = 0 To UBound($avArray, 2) - 1 If you need to go backwards (right to left) on the 2nd dimension only: For $i = 0 To UBound($avArray, 1) - 1 For $j = UBound($avArray, 2) - 1 To 0 Step -1 Or if you wanted the whole thing backwards ( right to left ): For $i = UBound($avArray, 1) - 1 To 0 Step - 1 For $j = UBound($avArray, 2) - 1 To 0 Step -1 The options are really up to you. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
1905russell Posted June 1, 2010 Author Share Posted June 1, 2010 (edited) Thanks, I think I understood everything except: Left to Right is done in the loops I provided the pseudo code for. I could not figure out how to do that so I did it a long way by added another loop to list it in Left to Right sequence. #include <Array.au3> Local $avArray[2][5] = [["JPM", "Holger", "Jon", "Larry", "Jeremy"],["Valik", "Cyberslug", "Nutster", "JdeB", "Tylo"]] _ArrayDisplay($avArray, "$avArray as a 2D array, transposed", -1, 1) Global $s_delim = "|" Global $s_out = "" For $i = 0 To UBound($avArray, 1) - 1 For $j = 0 To UBound($avArray, 2) - 1 $s_out &= $avArray[$i][$j] & $s_delim Next Next $s_out = StringTrimRight($s_out, StringLen($s_delim)) $aNewArray = StringSplit($s_out, '|', 1) Local $s_out2 = "" For $i = 1 to (UBound($aNewArray, 1) - 1) / 2 $s_out = $aNewArray[$i] & "|" & $aNewArray[$i + (UBound($aNewArray, 1) - 1) / 2] & $s_delim $s_out2 = $s_out2 & $s_out Next ConsoleWrite($s_out2 & @CRLF) Can you now please tell me how to do this in your pseudo code nested loops? Edited June 1, 2010 by 1905russell Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 1, 2010 Moderators Share Posted June 1, 2010 You mean this? Local $avArray[2][5] = [["JPM", "Holger", "Jon", "Larry", "Jeremy"],["Valik", "Cyberslug", "Nutster", "JdeB", "Tylo"]];,["Grape", "Orange", "Bannana", "Peach", "Apple"]] Global $s_delim = "|" Global $s_out = "" Global $i_ub1 = UBound($avArray, 1) - 1 Global $i_ub2 = UBound($avArray, 2) - 1 For $i = 0 To $i_ub2 For $j = 0 To $i_ub1 $s_out &= $avArray[$j][$i] & $s_delim Next Next $s_out = StringTrimRight($s_out, StringLen($s_delim)) ConsoleWrite($s_out & @CRLF) Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
1905russell Posted June 1, 2010 Author Share Posted June 1, 2010 You mean this? Local $avArray[2][5] = [["JPM", "Holger", "Jon", "Larry", "Jeremy"],["Valik", "Cyberslug", "Nutster", "JdeB", "Tylo"]];,["Grape", "Orange", "Bannana", "Peach", "Apple"]] Global $s_delim = "|" Global $s_out = "" Global $i_ub1 = UBound($avArray, 1) - 1 Global $i_ub2 = UBound($avArray, 2) - 1 For $i = 0 To $i_ub2 For $j = 0 To $i_ub1 $s_out &= $avArray[$j][$i] & $s_delim Next Next $s_out = StringTrimRight($s_out, StringLen($s_delim)) ConsoleWrite($s_out & @CRLF) Exactly what I mean - great technique (as always)– won't forget - fabulous Smoke_N - Thanks again. 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