Sign in to follow this  
Followers 0
beserk1

Array incorrect number subscripts?

3 posts in this topic

#1 ·  Posted (edited)

I am trying to pass elements from a 1D array to a 2D array

below 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)
    
EndFunc

EDIT: fixed it, thanks to this thread

Edited by beserk1

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

beserk1,

You have declared $mapArray [$dataRaw[0]+1][2] - so the available values of the second dimension are [0] and [1].

Yet here

For $a = 1 To $temp[0] Step 1

$mapArray[$i][$a] = $temp[$a] ;<-- error here

Next

you 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 here

Next

and it should work. Or you could declare the array with [3] as the second dimension. :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0