beserk1 Posted February 5, 2010 Share Posted February 5, 2010 (edited) I am trying to pass elements from a 1D array to a 2D arraybelow is my code, and the error I kept getting is "Array variable has incorrect number of subscripts or subscript dimension range exceeded."#include <Array.au3> ; For _ArrayDisplay() $data = "0_0,-1_0,-2_0,-3_0,-4_0,-5_0" _Process ( $data ) Func _Process ( $in ) $dataRaw = StringSplit ( $in, "," ) ;_ArrayDisplay ($dataRaw) Global $mapArray [$dataRaw[0]+1][2] ;_ArrayDisplay ($mapArray) For $i = 1 To $dataRaw[0] Step 1 $temp = StringSplit ($dataRaw[$i], "_") ;_ArrayDisplay ($temp) For $a = 1 To $temp[0] Step 1 $mapArray[$i][$a] = $temp[$a] ;<-- error here ; ^^^^ need to be [$a-1] Next Next ;_ArrayDisplay ($mapArray) EndFuncEDIT: fixed it, thanks to this thread Edited February 5, 2010 by beserk1 Link to comment Share on other sites More sharing options...
Hawkwing Posted February 5, 2010 Share Posted February 5, 2010 When you set the second dimension of an array to 2, it lets you set values to $array[$whatever][0] and $array[$whatever][1]. You're trying to set $array[$whatever][1] and $array[$whatever][2], so the subscript dimension range is exceeded. Change $mapArray[$i][$a] = $temp[$a] to $mapArray[$i][$a - 1] = $temp[$a] The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 5, 2010 Moderators Share Posted February 5, 2010 beserk1,You have declared $mapArray [$dataRaw[0]+1][2] - so the available values of the second dimension are [0] and [1].Yet hereFor $a = 1 To $temp[0] Step 1 $mapArray[$i][$a] = $temp[$a] ;<-- error hereNextyou are trying to address the second dimension of the array using [$a] which goes from [1] to [2].Try changing it to:For $a = 1 To $temp[0] Step 1 $mapArray[$i][$a - 1] = $temp[$a] ;<-- error hereNextand it should work. Or you could declare the array with [3] as the second dimension. 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