Greetings,
I have a database which, among other things, contains several tables that
store information regarding 'real world' objects.
I have a visual basic application, and within that application I have
defined user-defined types that correspond to the aforementioned database
tables. I query the database and create UDT's based on the contents of the
database tables. I then store the UDT objects in arrays, one array per
object type.
The problem I am having is creating generic functions to manipulate and
manage these UDT's.
As an example, I want to create a function that will search the arrays and
return a UDT. The array to search would be determined based on several
function parameters. I have tried creating the function to return an
Object, a Variant, or even a class that I defined specifically to hold the
UDT's, but none of it works, as I get error messages relating to
late-binding, coercing Objects or Variants to UDTs, etc.
BEGIN PSEUDOCODE
''''''' Defined in module A '''''''
Public Type A
s as String
End Type
Public Type B
s as String
End Type
Public Enum UDTType
TypeA = 0
TypeB = 1
End Enum
''''''' End module A '''''''
''''''' Defined in module B '''''''
public TypeAArray() as TypeA
public TypeBArray() as TypeB
Sub Main()
' Query database for contents of TableA (containing data that fits into
Type A)
' Resize and Populate TypeAArray with TypeA UDTs
' Query database for contents of TableB (containing data that fits into
Type B)
' Resize and Populate TypeBArray with TypeB UDTs
' Some function that manipulates the UDTs
ManipulateUDT
End Sub
Function FindUDT(RequestedType as UDTType, RequestedTypeUniqueIdentifier as
Long) as ??
' Based on RequestedType and RequestedTypeUniqueIdentifier, locate a
specific UDT in one of the arrays
' Return the requested type
End Function
Sub ManipulateUDT()
Dim TypeA as A
Dim TypeB as B
Dim UniqueID as Long
UniqueID = 1
' HOW DO I GET THIS TYPE OF RESULT
TypeA = FindUDT( TypeA, UniqueID )
End Sub
''''''' End in module B '''''''
END PSEUDOCODE
My question is two-fold.
1. Is there a common method of working with UDT's in a generic manner, ie, I
want to be able to pass around UDTs without knowing exactly what they are at
design time.
2. Is it really worth my time to try using Types as opposed to Classes?
Originally I had thought that perhaps types would have value copy semantics,
and would also be 'less expensive' than classes, but I have already proven
myself wrong on the copy semantics, and am wondering now about the cost of
classes vs types. Thoughts?
Thanks for any help offered.
Ken Halter - 24 May 2005 21:50 GMT
> Greetings,
>
> I have a database which, among other things, contains several tables that
> store information regarding 'real world' objects.
Convert them to class modules and your problems will disappear <g> Here's a
quicky page that shows how easy it is.
Converting a User Defined Type to a Class Module
http://www.vbsight.com/UDT_Class.htm

Signature
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Sign up now to help keep VB support alive - http://classicvb.org/petition
Please keep all discussions in the groups