strykerg Posted June 3, 2013 Share Posted June 3, 2013 hi all, i'm new here. my programming experience is all self-learnt so not much. as the title says im trying to divide a long string into a multidimensional array. i.e.: aa (tab) aa1 (tab) aa2(@CRLF) bb (tab) bb1 (tab) bb2(@CRLF) cc (tab) cc1 (tab) cc2(@CRLF) dd (tab) dd1 (tab) dd2 into $line[1] [1] = aa $line[1] [2] = aa1 $line[1] [3] = aa2 $line[2] [1] = bb $line[2] [2] = bb1 $line[2] [3] = bb2 $line[3] [1] = cc $line[3] [2] = cc1 $line[3] [3] = cc2 $line[4] [1] = dd $line[4] [2] = dd1 $line[4] [3] = dd2 Global $linelist Global $linetabs $thestring = "aa (tab) aa1 (tab) aa2(@CRLF) bb (tab) bb1 (tab) bb2(@CRLF) cc (tab) cc1 (tab) cc2(@CRLF) dd (tab) dd1 (tab) dd2" $linelist = StringSplit($thestring, "(@CRLF)",1) $i = 1 While $i <= $linelist[0] $linetabs[$i] = StringSplit($linelist[$i], "(tab)",1) $i = $i + 1 WEnd MsgBox(0, $i, $linelist[2]) ;ok this gives "bb (tab) bb1 (tab) bb2" MsgBox(0, $i, $linetabs[2][2]) ;shouldnt this give "bb1" ?? intead i get ;==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: can't understand what im doing wrong thanks in advance! Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted June 3, 2013 Moderators Solution Share Posted June 3, 2013 strykerg, Welcome to the AutoIt forum. You need to correctly structure the string and then learn a bit more about arrays. Take alook at this and see if you can follow: expandcollapse popup#include <Array.au3> Global $linelist ; A correctly structured string $thestring = "aa" & @TAB & "aa1" & @TAB & "aa2" & @CRLF & "bb" & @TAB & "bb1" & @TAB & "bb2" & @CRLF & "cc" & @TAB & "cc1" & @TAB & "cc2" & @CRLF & "dd" & @TAB & "dd1" & @TAB & "dd2" ; Split on @CRLF $linelist = StringSplit($thestring, @CRLF, 1) ; Check we actually have an array If Not @error Then ; Display it _ArrayDisplay($linelist) ; Now check how many tabs there are in the line StringReplace($linelist[1], @TAB, "") $iCols = @extended ; And now create an array to hold all the elements when we split each line Global $linetabs[$linelist[0] + 1][$iCols + 1] ; Which we do here For $i = 1 To $linelist[0] ; Split the line into a temporary array $aTemp = StringSplit($linelist[$i], @TAB) ; And then move each element into the big array For $j = 1 To $aTemp[0] $linetabs[$i][$j - 1] = $aTemp[$j] Next Next ; And here is the result _ArrayDisplay($linetabs) ; And the elements are properly displayed MsgBox(0, $i, $linelist[2]) MsgBox(0, $i, $linetabs[2][2]) EndIf Please ask if you have any questions. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
strykerg Posted June 3, 2013 Author Share Posted June 3, 2013 damn that was fast. yes I definitely need to learn stuff, and today you taught me quite a few _ArrayDisplay($linelist) << I love this! perfect debugging tool the only thing i'm not sure of is: For $i = 1 To 50 do something Next is the same as While ($i <= 50) do something $i = $i + 1 Wend thanks a lot! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 3, 2013 Moderators Share Posted June 3, 2013 strykerg,Yes, the loops are functionally identical, but the For...Next version is more elegant - and you have less coding to do. m23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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