Return Nested Array

Recommended Posts

RC86 0

RC86 0

I have a requirement to return both a string and an array from a function so as a result I put them both into an array and returned that. I can access them in their entirety after returning them but then I can't seem to access the array elements after this. Should I be able to or is there a prettier way?

Share on other sites

RC86 0

RC86 0

To the start of the script, it appeared to work OK for me. What was your error?

Apologies, I've edited the code now so it runs from copy paste.

No sorry - the issue I'm having is you'll notice the final message box/array display will show blank. I'd like to be able to access the elements from the returned array, but as that has been returned within an array, is that even possible?

Yea I've edited that in my original post thanks. My issue is lines 8-12. You'll notice they are blank. I'm trying to access elements from an array that have been returned within an array.

eg. So by running _getMemoryInfo() function the return value is an array and im assigning it to $memoryInfo. That means $memoryInfo is an array then with 2 elements [0] is a string [1] is an array. So u can make [1] show in its entirety (using _ArrayDisplay), but how can you access the individual elements of the array now stored within $memoryInfo[1].

Edited September 13, 2017 by RC86

Share this post

Link to post

Share on other sites

SlackerAl 28

SlackerAl 28

Were you expecting your $newArray to pick up the data from the function? That won't happen as you have $newArray scoped as local within the function. Hence, I added some "test" values to $newArray when you define it as local within the main (although as far as I am aware variables defined in the main are always scoped as global unless specifically scoped as local within a function definition).

Why do you think this will display anything? You do not add anything to $newArray

Sorry I'm probably bad at explaining - I was trying to use the array contained in element $memoryInfo[1] and assign it a new array so i could then access its individual elements. But i was showing that this does not work using those lines - so is there another way it can be done?

Similar Content

To save myself a "search" nightmare, I'm trying to wrap my head around 3D arrays.
Example: In "No Limit Hold'em", if I only play kings "KK" and queens "QQ"
and I only play them from the positions of the "Button" or "Blinds"
and do one thing if it's raised ahead or another if not raised.
I know that this example would be simple as a 2D array but if I'm dealing with 77 possible hands in 9 possible positions and 6 possible conditions then I'm dealing with almost 700 data lines.
Lastly, if I have a variables to represent the hand like $hand = "QQ"
and $position = "Button" and $ahead = "Raised", could the 3D array simplify my search, or should I just stick to the 2D array ??
Thank you in advance for any thoughts...

So I have a loop that keeps reading data from an array and searching it for the same value. If the value is no there it does work then adds the value to the array to prevent it from doing the same work.
If _ArraySearch($ID,$filearray[$i]) = -1 Then
Work....
_ArrayAdd($ID,$filearray[$i])
EndIf
This is in a for loop hence $i
So what is happening is the code works great for several hours. After a period of time _ArraySearch($ID,$filearray[$i]) will result in -1 even if $ID = $filearray. So it ready as if there is no data in the array. Anyone have this problem?

Also I am just running in using F5 not compiling it and running it if that makes a difference.

I am reading a CSV file which is tab seperated as below.
Local $aArray = FileReadToArray($file)
And now, I am splitting this main array record wise so that Array contains internally another arrow to represent each row.
For $i = 0 to (UBound($aArray) - 1)
;MsgBox(0,"",$aArray[$i])
$aArray[$i] = StringSplit(StringStripCR($aArray[$i]), Chr(9),2);Chr(9) for tab
;_ArrayDisplay($aArray[$i])
Next
Afther that, _ArrayDIsplay is able to see the individual internal arrays.
_ArrayDisplay($aArray[1])
But If I try to access the individual element of it as below.It is not showing any result.
MsgBox(0,"",$aArray[1][1])
Any suggestion, below is the sample csv file.
New Text Document.csv