Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Types and classes 1

Status
Not open for further replies.

nigz

Programmer
Jun 15, 2001
60
GB
Hi - I want to use the following type in a class - but I can't seem to get the syntax right. VB6 won't let me declare a public variable of type FormRecordsets and the following code, although it doesn't fall over doesn't work either. I would be grateful of any pointers, thanks!

Public Type FormRecordsets
rec4dbcOrgName As ADODB.Recordset
rec4dbcRole As ADODB.Recordset
rec4dgdMain As ADODB.Recordset
End Type

Public Property Let udtFormRecordsets(vData As FormRecordsets)
mvarudtFormRecordsets = vData
End Property


Public Property Get udtFormRecordsets() As FormRecordsets
udtFormRecordsets = mvarudtFormRecordsets
End Property

Regards

Nigel

 
probably it is just incomplete, but you do not show a database declaration. Often, classes are just instantiated on startup, so the db decl. would need to preceede the class declaration & instantation.

W/o knowiing the overall process, commentary on this is difficult. It is somewhat outside of my experience to use multiple recordsets as the content of a UDT. The reation and instantiation of the db/rst is an 'expensive' operation, and thus often set up to minimixe the number of occurances. Embedding the recordset in a udt in a class all increase the 'expense' of the object in some ways, so you should be quite sure this is the way you want to approach your soloution.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
This is from MSDN

This example uses the Type statement to define a user-defined data type. The Type statement is used at the module level only. If it appears in a class module, a Type statement must be preceded by the keyword Private. If you choose to battle wits with the witless be prepared to lose.
[machinegun][ducky]
 
Try using SET instead of LET in the property declaration:

Public Property Get Data() As ADODB.Recordset

Set Data = mData

End Property

Public Property Set Data(Data As ADODB.Recordset)

Set mData = Data

End Property
 
In a nutshell, you can't define a public type in a class. Interestingly, interpreting the error message suggests that you should be able to declare the Type in a module and work that way. In practise, you get the following: "Only public user defined types defined in public object modules can be used as parameters or return types for public procedures of class modules or as fields of public user defined types". Uh-huh, right. Handily, the Help button on the compile error message box doesn't take me anywhere.

Do you have a compelling reason for using a Type? Or could you make it into a data-only Class, which would work? I believe that the recommendation is that use of Types is restricted to creating analogues of C/C++ structs for API calls and classes for everything else.

HTH,

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top