Jump to content

Passing values from 2d array into another function


Go to solution Solved by JohnOne,

Recommended Posts

For some reason what seems like a simple function has gone over my head as to why this doesn't work, so there must be some simple concept here I'm completely missing.

I have a 2d array full of values from a csv file and I know that row 1,2 has nothing important, but column 3 has all the classes from the CSV

So $twoDarray[3][*one through six] =
1. Name
2. Location
3. host
..etc
So I should be able to pass all rows of column 3 by strconvert($twoDarray[3]).
I've searched the forums but I could not find the solution to this probably simple problem.

Dim $oneDarray
$oneDarray=StringSplit($Rawfile, @CRLF, 1)
$columnsCounter = stringsplit($oneDarray[2],",")
Dim $twoDarray[$oneDarray[0] + 1][$columnsCounter[0] + 1]
For $x = 1 to ($oneDarray[0])
$oneRow = stringsplit($oneDarray[$x],",")
For $y = 1 to ($oneRow[0])
$twoDarray[$x][$y] = $oneRow[$y]
Next
Next 

strconvert($classes,$twoDarray[3])

Log Output
Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
strconvert($classes,$twoDarray[3])
strconvert($classes,^ ERROR

Thanks,

Bob

Link to comment
Share on other sites

  • Solution

First, what is "strconvert"?

Second, you cannot pass a part of an array to a function, unless it's its full location ($twoDarray[y][x])

You can however pass the whole array to a function, where you can loop through the needed parts and process them.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

strconvert is just my next function where I begin to step through the strings and parse the values I'm looking for, but is irrelevant to this topic just because the topic is really dealing with 'like you confirmed' passing part of an array into a function.  So thank you for clearing that up.

This question is resolved for me, thanks.

Link to comment
Share on other sites

I see.

Additionally, when passing an array to a function the size of which you indicate, it is advisable to pass it by reference (ByRef).

That way the array is not copied, saving time and memory.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
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
 Share

×
×
  • Create New...