Jump to content

Function which returns several arrays


Go to solution Solved by mLipok,

Recommended Posts

Posted
I have a function that reads the XLS file. 
This file contains a number of predefined Sheets.
Each Sheet I read and I put in a separate array.
I want to return each Sheet as a separate variable of type Array. 
 
Question:
How, at the same time, as a result of a function, return several arrays ?
 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Moderators
Posted

mLipok,

You can store arrays within another array, so you should be able to return that outer array - but I have never tried it. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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:

  Reveal hidden contents

 

Posted
I can say the same thing 
I thought not even tried, as soon as I know - work in progress.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Solution
Posted

Example:

#include <array.au3>


Global $aTest = _TestNestedArray()

_ArrayDisplay($aTest[0],'$aTest[0]')
_ArrayDisplay($aTest[1],'$aTest[1]')


Func _TestNestedArray()
    Local $aFirstArray[2] = ['a', 'b']
    Local $aSecondArray[2] = ['A', 'B']
    Local $aOuterArray[2] = [$aFirstArray, $aSecondArray]
    Return $aOuterArray
EndFunc   ;==>_TestNestedArray

Answer:

How you see now I know how to do that.

 

Best Regards

mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Moderators
Posted

mLipok,

Delighted it worked - I thought it would. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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:

  Reveal hidden contents

 

Posted

mLipok,

Just goofing around...

#include <array.au3>

local $aCars[4][2] = [ _
                        ['Toyota',''], _
                        ['Ford',''], _
                        ['Mazeratti',''], _
                        ['Yugo',''] _
                        ]

local $aOptionsMazerrati[4] = ['Red','Chrome Wheels','Delux Stereo','Leather']

for $1 = 0 to ubound($aCars) - 1
    if $aCars[$1][0] = 'Mazeratti' then $aCars[$1][1] = $aOptionsMazerrati
Next

_arraydisplay($aCars,'Cars')
_arraydisplay($aCars[2][1],'Options for Mazerrati')

; write array contents to console
ConsoleWrite(@lf & '! Cars' & @LF)
for $1 = 0 to ubound($aCars) - 1
    ConsoleWrite($aCars[$1][0] & @LF)
    if isarray($aCars[$1][1]) then
        $aTmp = $aCars[$1][1]   ; assign array to temp array because syntax does not allow it to be addressed directly
        for $2 = 0 to ubound($aTmp) - 1
            consolewrite(@tab & $aTmp[$2] & @lf)
        Next
    endif
Next

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Posted
kylomas
 
Your example aroused my curiosity, 
I was wondering about a feature that using recursion, displays the contents of a nested array even up to level 10. 
These were the thoughts, purely theoretical, but quite feasible. 
 
Thanks for stimulating my imagination. 
 
mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...