ByNary010101
Programmer
I am building an application using VB6 SP6 and have a question about using UDT's in functions. Listed below is some sample code outlining how I would like to use the UDT's
frmContact- Contains 4 textboxes (First Name, Last Name, Phone Number, E-mail Address) and a command button (Save)
Contact- this is an ActiveX DLL component that encapsulates the business (clsContact) and data access (clsContactData) logic for the insertion
clsContact
clsContactData
udtContact
First question is where should I declare udtContact so that I can use the UDT in both the Form and in DLL??
Second question is how do I pass the entire contents of the UDT to the various functions, for some reason this just isn't clicking with me??
I hope this makes sense. Thanks.
frmContact- Contains 4 textboxes (First Name, Last Name, Phone Number, E-mail Address) and a command button (Save)
Code:
General Declarations
Private objContact as New clsContact
Private Sub cmdSave_Click
Dim uContact as udtContact
With uContact
.FirstName = text1
.LastName = text2
.PhoneNo = text3
.Email = text4
End With
If objContact.AddContact(uContact) = True Then
Clear the form
Else
MsgBox "Data Not Valid"
End If
End Sub
Contact- this is an ActiveX DLL component that encapsulates the business (clsContact) and data access (clsContactData) logic for the insertion
clsContact
Code:
Option Explicit
Private objContactData as New clsContactData
Public Function AddContact(uContact as udtContact) as Boolean
If objContactData.AddContactData(uContact) = True Then
AddContact = True
Else
AddContact = False
End If
End Function
clsContactData
Code:
Option Explicit
Public Function AddContactData(uContact as udtContact) as Boolean
Declare the Connection and Command objects
Execute the Insert Statement
If Inserted Then
AddContactData = True
Else
AddContactData = False
End If
End Function
udtContact
Code:
Public Type udtContact
FirstName as String
LastName as String
PhoneNo as String
Email as String
End Type
First question is where should I declare udtContact so that I can use the UDT in both the Form and in DLL??
Second question is how do I pass the entire contents of the UDT to the various functions, for some reason this just isn't clicking with me??
I hope this makes sense. Thanks.