Populating Array member of a User Defined Type.

Jimjam

New member
Local time
Yesterday, 23:42
Joined
Nov 22, 2012
Messages
7
Hello. I have a user defined type that has a member variable that is a string array. I cannot seem to get an instance of that UDT to have it's array member be assigned an array from a FunctionThatReturnsAnArray("blah").

The semi-pseudocode below is a simplified version of what I'm trying to do. Is this a known limitation? Is there something I can do to get it to work or do I have to make an intermediate array to accept the out put of the FunctionThatReturnsAnArray("blah") and then loop through it adding its contents one by one to the UDT's array?


Code:
Type Foo
   sArray() as string
End Type


Public Function fTest 
   'instantiate a standard array vs an array that is part of a UDF...
   Dim sAnotherArray() as string
   'vs...
   Dim myFoo as Foo

   'attempt to assign an array returned from a function to the two arrays...
   sAnotherArray = FunctionThatReturnsAnArray("blah") 'This WORKS
   'vs...
   myFoo.sArray = FunctionThatReturnsAnArray("blah") 'This DOESN'T


End Function
 
this works for me
Code:
Type foo
    sAR() As String
End Type

Function retArray() As String()
Dim sAR() As String
ReDim sAR(1 To 3)

sAR(1) = "A"
sAR(2) = "B"
sAR(3) = "C"
retArray = sAR

End Function

Sub test()
Dim stringArray() As String

Dim f As foo


stringArray = retArray
f.sAR = retArray

End Sub
 
Yes. Very nice. I needed that proof of concept. The problem was not what I had initially thought. Thank you for helping me dispel that.

As it turned out I was trying to assign a string array to an array of user defined types. The fact that I had an array of UDTs that had a UDT array as a member occluded the fact that I was making a simple mistake.

Much thanks DJKarl

Jimjam
 

Users who are viewing this thread

Back
Top Bottom