Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Returning Values From a User-Defined Type


I am trying to get a function to return the values stored in a
user-defined type. The type has two fields: the first field is a Double
and the second field is an Integer.

I realize functions can return more than one value by declaring them as
arrays or by using the Array() function, but can UDT's be used in this
manner? I remember seeing code that returns the values of a UDT, so I
believe this IS possible.

Here is a simple example VBA:


Code:
--------------------

' DECLARE USER DEFINED TYPE
Private Type typDblInt

typDblInt0 As Double
typDblInt1 As Integer

End Type

' DECLARE SIMPLE FUNCTION USING USER DEFINED TYPE
Function UDFTest(dNum, iNum) As typDblInt

Dim typDblIntTmp As typDblInt

typDblIntTmp.typDblInt0 = dNum
typDblIntTmp.typDblInt1 = iNum


UDFTest = typDblIntTmp

End Function
--------------------

When I type this function into my spreadsheet I get #VALUE!. I've tried
entering the function into a single cell, two adjecent cells, and as a
normal function or as an array function (Ctrl+Shift+Enter). Still
#VALUE!. *sigh*

So is it possible to get a function to return the field values of a
user defined type? THANKS for the HELP!

P.S. To answer a few obvious ?'s you may be thinking: "Why do you want
to do this ?" B/c I want to return multiple values of different data
types (not just Double and Integer but also String and Boolean).

"Why not decalre a Variant array?" B/c I don't want to take the
performance hit of using Variant (the function will be used 100's of
times on a very slow pc). And I want to strongly type the inputs, which
variant doesn't allow.

"If you want to strongly type, why not use a Class Module?" B/c I don't
want my VBA code to create a COM interface if it doesn't have to, and I
believe there is a performance hit using a Class Module.

THANKS AGAIN VERY MUCH FOR THE HELP! :)


--
BobbyMurcerFan
------------------------------------------------------------------------
BobbyMurcerFan's Profile: http://www.excelforum.com/member.php...o&userid=11107
View this thread: http://www.excelforum.com/showthread...hreadid=526255

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Returning Values From a User-Defined Type

So is it possible to get a function to return the field values of a
user defined type? No. - neither as an array formula entered in two

cells or a single formula in a single cell.

--
Regards,
Tom Ogilvy

"BobbyMurcerFan"
<BobbyMurcerFan.25786n_1143245402.1466@excelforu m-nospam.com wrote in
message news:BobbyMurcerFan.25786n_1143245402.1466@excelfo rum-nospam.com...

I am trying to get a function to return the values stored in a
user-defined type. The type has two fields: the first field is a Double
and the second field is an Integer.

I realize functions can return more than one value by declaring them as
arrays or by using the Array() function, but can UDT's be used in this
manner? I remember seeing code that returns the values of a UDT, so I
believe this IS possible.

Here is a simple example VBA:


Code:
--------------------

' DECLARE USER DEFINED TYPE
Private Type typDblInt

typDblInt0 As Double
typDblInt1 As Integer

End Type

' DECLARE SIMPLE FUNCTION USING USER DEFINED TYPE
Function UDFTest(dNum, iNum) As typDblInt

Dim typDblIntTmp As typDblInt

typDblIntTmp.typDblInt0 = dNum
typDblIntTmp.typDblInt1 = iNum


UDFTest = typDblIntTmp

End Function
--------------------

When I type this function into my spreadsheet I get #VALUE!. I've tried
entering the function into a single cell, two adjecent cells, and as a
normal function or as an array function (Ctrl+Shift+Enter). Still
#VALUE!. *sigh*

So is it possible to get a function to return the field values of a
user defined type? THANKS for the HELP!

P.S. To answer a few obvious ?'s you may be thinking: "Why do you want
to do this ?" B/c I want to return multiple values of different data
types (not just Double and Integer but also String and Boolean).

"Why not decalre a Variant array?" B/c I don't want to take the
performance hit of using Variant (the function will be used 100's of
times on a very slow pc). And I want to strongly type the inputs, which
variant doesn't allow.

"If you want to strongly type, why not use a Class Module?" B/c I don't
want my VBA code to create a COM interface if it doesn't have to, and I
believe there is a performance hit using a Class Module.

THANKS AGAIN VERY MUCH FOR THE HELP! :)


--
BobbyMurcerFan
------------------------------------------------------------------------
BobbyMurcerFan's Profile:

http://www.excelforum.com/member.php...o&userid=11107
View this thread: http://www.excelforum.com/showthread...hreadid=526255



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Returning Values From a User-Defined Type


Thanks Tom. Not the answer I was hoping for, but I DO appreciate it. ;)


--
BobbyMurcerFan
------------------------------------------------------------------------
BobbyMurcerFan's Profile: http://www.excelforum.com/member.php...o&userid=11107
View this thread: http://www.excelforum.com/showthread...hreadid=526255

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Excel Programming 1 October 31st 05 08:20 PM
"User-defined type not defined" message in Excel RW1946 Excel Discussion (Misc queries) 0 August 31st 05 12:14 PM
Workspace faux user-defined type not defined Chris S[_2_] Excel Programming 3 November 11th 04 05:51 PM
User-defined data type; Error: Only User-defined types... tiger_PRM Excel Programming 1 July 18th 04 03:32 PM
Word.Document - user defined type not defined jowatkins[_7_] Excel Programming 0 January 20th 04 08:46 AM


All times are GMT +1. The time now is 08:59 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"