D B
asked on
n-Tier Application
I recently picked up the book Business Objects for Visual BASIC 6.0 published by Wrox. I must admit it provides some interesting reading and some concepts which I've not used before, primarily the use of UDTs to pass data. However, it is in this area that I am experiencing problems.
I have one block of code that is:
Private Function GetState() As String
Dim udtData As EmployeeData
LSet udtData = mudtProps
GetState = udtData.Buffer
End Function
mudtProps is a 'normal' UDT with individual properties that make up an employee (name, employee ID, etc.). udtData/EmployeeData is a UDT with a single property, Buffer. Buffer is defined as String * 972. When I run this code, I get a Compile Error: Type Mismatch.
When I go into immediate mode and use the Lenb() function on udtData, mudtProps and udtData.Buffer, they all come out the same length, 972. The error occurs on the LSET line.
Any ideas? If we get somewhere positive on this thread, I may have another question or two along the same lines, primarily, is there an EASY way to calculate the length of the buffer for the individual primary UDTs? Some seem straight-forward, but I've got some that have variant, boolean, string, long, integer and what-not different data types within the properties.
Is doinga Lenb() on the 'Primary' UDT and using that value as the value of the buffer a safe way to go or are there other factors you need to take into account?
I have one block of code that is:
Private Function GetState() As String
Dim udtData As EmployeeData
LSet udtData = mudtProps
GetState = udtData.Buffer
End Function
mudtProps is a 'normal' UDT with individual properties that make up an employee (name, employee ID, etc.). udtData/EmployeeData is a UDT with a single property, Buffer. Buffer is defined as String * 972. When I run this code, I get a Compile Error: Type Mismatch.
When I go into immediate mode and use the Lenb() function on udtData, mudtProps and udtData.Buffer, they all come out the same length, 972. The error occurs on the LSET line.
Any ideas? If we get somewhere positive on this thread, I may have another question or two along the same lines, primarily, is there an EASY way to calculate the length of the buffer for the individual primary UDTs? Some seem straight-forward, but I've got some that have variant, boolean, string, long, integer and what-not different data types within the properties.
Is doinga Lenb() on the 'Primary' UDT and using that value as the value of the buffer a safe way to go or are there other factors you need to take into account?
also, can we see the defintion of the EmployeeData type?
AW
AW
what gets me about your problem is that LSet does not do any type checking. It does a pure memory copy. Hence the type Mismatch error message does not make sense.
AW
AW
ASKER
Public Type EmployeeProps
TelEmpID As Long
LName As String * 50
FName As String * 50
MI As String * 2
CommonName As String * 20
Title As String * 50
Location As Long
Department As Long
EmpId As String * 12
Comments As String * 100
HireDate As Variant
SSN As String * 9
BirthDate As Variant
Password As String * 20
IsDirector As Boolean
IsHREmployee As Boolean
TermDate As Variant
WorkEMail As String * 50
PrimaryWorkPhoneNumber As String * 10
PersonalEMail As String * 50
IsOnLeave As Boolean
ImageID As Long
Facility As Long
KPERSEligibilityDate As Variant
KPERSMembershipDate As Variant
IsActive As Boolean
SecurityLogID As Long
IsNew As Boolean
IsDeleted As Boolean
IsDirty As Boolean
End Type
Public Type EmployeeData
Buffer As String * 486 (Also tried 972, which makes LenB() return 1944)
End Type
TelEmpID As Long
LName As String * 50
FName As String * 50
MI As String * 2
CommonName As String * 20
Title As String * 50
Location As Long
Department As Long
EmpId As String * 12
Comments As String * 100
HireDate As Variant
SSN As String * 9
BirthDate As Variant
Password As String * 20
IsDirector As Boolean
IsHREmployee As Boolean
TermDate As Variant
WorkEMail As String * 50
PrimaryWorkPhoneNumber As String * 10
PersonalEMail As String * 50
IsOnLeave As Boolean
ImageID As Long
Facility As Long
KPERSEligibilityDate As Variant
KPERSMembershipDate As Variant
IsActive As Boolean
SecurityLogID As Long
IsNew As Boolean
IsDeleted As Boolean
IsDirty As Boolean
End Type
Public Type EmployeeData
Buffer As String * 486 (Also tried 972, which makes LenB() return 1944)
End Type
ASKER
btw, I can check mudtProps and all the properties are correctly set.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
When you want to mess with cross casting data types you need to avoide variants (How big is a vaiant? - that depends)
I changed Boolean to long becuase of memory size confusion with interger data types. But Boolean and integer data types may/may not work you need to try.
I changed Boolean to long becuase of memory size confusion with interger data types. But Boolean and integer data types may/may not work you need to try.
Confirmed as working, so just change the Variant data type to Date or some other fixed length type.
Hope this helps:~)
Option Explicit
Private Type EmployeeProps
TelEmpID As Long
LName As String * 50
FName As String * 50
MI As String * 2
CommonName As String * 20
Title As String * 50
Location As Long
Department As Long
EmpId As String * 12
Comments As String * 100
HireDate As Date
SSN As String * 9
BirthDate As Date
Password As String * 20
IsDirector As Boolean
IsHREmployee As Boolean
TermDate As Date
WorkEMail As String * 50
PrimaryWorkPhoneNumber As String * 10
PersonalEMail As String * 50
IsOnLeave As Boolean
ImageID As Long
Facility As Long
KPERSEligibilityDate As Date
KPERSMembershipDate As Date
IsActive As Boolean
SecurityLogID As Long
IsNew As Boolean
IsDeleted As Boolean
IsDirty As Boolean
End Type
Private Type MD
Buffer As String * 932
End Type
Private Sub Form_Load()
Dim EP As EmployeeProps
Dim ED As MD
MsgBox "Len of EP=" + CStr(LenB(EP))
EP.Comments = "Fred"
'
LSet ED = EP
EP.Comments = "X"
'
LSet EP = ED
'
MsgBox EP.Comments
'
End Sub
Hope this helps:~)
Option Explicit
Private Type EmployeeProps
TelEmpID As Long
LName As String * 50
FName As String * 50
MI As String * 2
CommonName As String * 20
Title As String * 50
Location As Long
Department As Long
EmpId As String * 12
Comments As String * 100
HireDate As Date
SSN As String * 9
BirthDate As Date
Password As String * 20
IsDirector As Boolean
IsHREmployee As Boolean
TermDate As Date
WorkEMail As String * 50
PrimaryWorkPhoneNumber As String * 10
PersonalEMail As String * 50
IsOnLeave As Boolean
ImageID As Long
Facility As Long
KPERSEligibilityDate As Date
KPERSMembershipDate As Date
IsActive As Boolean
SecurityLogID As Long
IsNew As Boolean
IsDeleted As Boolean
IsDirty As Boolean
End Type
Private Type MD
Buffer As String * 932
End Type
Private Sub Form_Load()
Dim EP As EmployeeProps
Dim ED As MD
MsgBox "Len of EP=" + CStr(LenB(EP))
EP.Comments = "Fred"
'
LSet ED = EP
EP.Comments = "X"
'
LSet EP = ED
'
MsgBox EP.Comments
'
End Sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
inthedark: Thanks, I got it working. I really do not know what I was thinking when I defined the dates as Variant. Anyway, thanks for the help.
dancebert: Thanks for the "food for thought." In the past, I've developed 3-tier applications but have never actually separated the compnents into different projects. In other words, I've kept the business rules in the objects, and I have a data accessor class that all DB throughput goes through, but now have an application I am working on that makes more sense to have separate ActiveX components. I have never used UDTs in the way Rocky suggests, to pass data, but it was quick and easy to learn and I have had 0 experience with property bags. However, it may be the way to go in future development since I seem to recall reading that .NET does not support the LSet function in this way.
dancebert: Thanks for the "food for thought." In the past, I've developed 3-tier applications but have never actually separated the compnents into different projects. In other words, I've kept the business rules in the objects, and I have a data accessor class that all DB throughput goes through, but now have an application I am working on that makes more sense to have separate ActiveX components. I have never used UDTs in the way Rocky suggests, to pass data, but it was quick and easy to learn and I have had 0 experience with property bags. However, it may be the way to go in future development since I seem to recall reading that .NET does not support the LSet function in this way.
PS UDT's are so passee with ntier apps. MS don't have the answer either. I created an handbag object which could host other objects, including itself. So like a databses, you have databases, then tables, then rows. So I invented an infinetately recusable object to recordsets could host databases, etc. In fact you can dynamically create fiields, objects, anything in your handbag. The cool thing is that the object then translates to xml so that it may hop between systems, or even OS platforms. And the beauty is that you only need one handler for any kind of data. So you invent a facility for say your employee xUDT, like expose as a spreadsheet, the all objects you ever created also inherit this new feature.
And then take a leap...
And then take a leap...
ASKER
FYI, if anybody is interested, in the above example, the length of the EmployeeData (MD) buffer string should be 932 / 2 or 466. That comes out to a binary length of 932 (strings are Unicode in VB, which is two bytes).
I am a great fan of Rocky's book, and have a copy right here.
AW