is it possible to return a user-defined data type

J

John T Ingato

is it possible to return a user-defined data type?

Such as

type coordinates
x as long
y as long
end type

function doNothing() as coordinates

code......
..........
doNothng.x = 10
doNothing.y = 20

end function

or maybe creat a new user type inside the proceedure, assign values to its
members then set the return var to the user var???
Help please
 
C

Cindy M -WordMVP-

Hi John,
is it possible to return a user-defined data type?
You can do that. You can also (when appropriate module or project level)
[array] variable to hold the type instanceand pass it to the function by
ref, or if the scope allows, just pick it up anywhere. Whatever approach
makes the most sense in the current context. See the example below (note that
you neglect to assign the function a value at the end, which is why you may
have been having problems):

Option Explicit

Type coordinates
x As Long
y As Long
End Type

Sub Test()
Dim a As coordinates

FillData a
Debug.Print a.x & vbTab & a.y

Dim b As coordinates
b = FillData2
Debug.Print b.x; vbTab; b.y
End Sub

Function FillData(n As coordinates)
n.x = 1
n.y = 2
End Function

Function FillData2() As coordinates
Dim a As coordinates

a.x = 3
a.y = 10
FillData2 = a
End Function

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top