Array in array returned by function 
Author Message
 Array in array returned by function

Hi,

I'd like to write a function that returns two different (in size too!)
arrays.

This function has to split everything in a certain directory into one array
that contains all directorynames and one array that contains all filenames.
I know it isn't possible to make a function that returns an array, but I
thought it might be possible using the Variant type.

The problem is that there have to be 2 different arrays returned. Does
anyone know if it is possible to create a Variant (used as an array) that
contains 2 other arrays (different size, not just both 30 or something like
that) ?



Wed, 17 Nov 1999 03:00:00 GMT  
 Array in array returned by function

Jorn,

        You can return as many arrays (or other variables) as you
like.  Just dim them in your calling routine and pass them by
reference like so:

Sub CallingRoutine()
Dim la_Array1() as String, la_Array2() as integer

        Call OtherRoutine(la_Array1, la_Array2)

        ' By the time you get here,  la_Array1 will contain the
        ' strings "0" thru "9";   la_Array2 will contain the integers
        ' 0 thru 99.

End Sub

Sub OtherRoutine(aa_Array1, aa_Array2)
Dim i as integer

        For i = 0 to 9  
                Redim Preserve aa_Array1(i)
                aa_Array1(i) = cstr(i)
        Next

        For i = 0 to 99
                Redim Preserve aa_Array2(i)
                aa_Array2(i) = i
        Next

End Sub



Quote:
>Hi,

>I'd like to write a function that returns two different (in size too!)
>arrays.

>This function has to split everything in a certain directory into one array
>that contains all directorynames and one array that contains all filenames.
>I know it isn't possible to make a function that returns an array, but I
>thought it might be possible using the Variant type.

>The problem is that there have to be 2 different arrays returned. Does
>anyone know if it is possible to create a Variant (used as an array) that
>contains 2 other arrays (different size, not just both 30 or something like
>that) ?

Thanks,
Dave Verschleiser
Q&D Software Development - http://www.q-d.com
Creators of WebForms, WebMania, and Bookmark Magician
=======================================================
For the best SHAREWARE on the Net, check out:
** The Shareware Central Interactive Catalog **
** http://www.q-d.com/swc.htm **
Shareware authors -- find out how to obtain a listing!
=======================================================


Wed, 17 Nov 1999 03:00:00 GMT  
 Array in array returned by function


says...

Quote:

> I'd like to write a function that returns two different (in size too!)
> arrays.

> This function has to split everything in a certain directory into one array
> that contains all directorynames and one array that contains all filenames.
> I know it isn't possible to make a function that returns an array, but I
> thought it might be possible using the Variant type.

How about using a collection?  

Sub FillStrings()
Dim Directories As New Collection
Dim Files As New Collection
Result=FillString(Directories,Files)
End Sub

Public Function FillString(Directories as Collection, Files As
Collection)
For each Directory...
Directores.Add Directoryname
For each File
Files.Add Directoryname
FillString = Directories.Count
End Function



Thu, 25 Nov 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Passing array from VB to DLL and returning array

2. Return entire array from a function

3. returning an array from a function

4. Syntax for function to return an array

5. Domain Aggregate function to return Collection/array

6. Returning an array from a function

7. Returning an Array from a function

8. Array return in function

9. Function doesn't return an array in vb (Script) in Outlook

10. Returning array from function

11. question on passing and returning arrays from functions

12. Function to return 2d array or disconnected dr

 

 
Powered by phpBB® Forum Software