• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

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?
0
dbbishop
Asked:
dbbishop
  • 4
  • 4
  • 3
  • +1
2 Solutions
 
Arthur_WoodCommented:
can you show us the definition of your mudtProps variable.

I am a great fan of Rocky's book, and have a copy right here.

AW
0
 
Arthur_WoodCommented:
also, can we see the defintion of the EmployeeData type?

AW
0
 
Arthur_WoodCommented:
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
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
dbbishopAuthor Commented:
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

0
 
dbbishopAuthor Commented:
btw, I can check mudtProps and all the properties are correctly set.
0
 
inthedarkCommented:
This shows how it can work:

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 Long
    SSN                         As String * 9
    BirthDate                   As Long
    Password                    As String * 20
    IsDirector                  As Long
    IsHREmployee                As Long
    TermDate                    As Long
    WorkEMail                   As String * 50
    PrimaryWorkPhoneNumber      As String * 10
    PersonalEMail               As String * 50
    IsOnLeave                   As Long
    ImageID                     As Long
    Facility                    As Long
    KPERSEligibilityDate        As Long
    KPERSMembershipDate         As Long
    IsActive                    As Long
    SecurityLogID               As Long
    IsNew                       As Long
    IsDeleted                   As Long
    IsDirty                     As Long
End Type

Private Type MD
    Buffer As String * 920
End Type

Private Sub Form_Load()
Dim EP As EmployeeProps
Dim ED As MD


EP.Comments = "Fred"
'
LSet ED = EP
EP.Comments = "X"
'
LSet EP = ED
'
MsgBox EP.Comments


End Sub
0
 
inthedarkCommented:
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.
0
 
inthedarkCommented:
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
0
 
dancebertCommented:
I too am a fan of Rocky's book, learned a lot from it.  I've used his BrokenRules class ever since I read this book.

However, his use of UDTs to pass data is a BAD IDEA.  He uses the VB memory read/write functions in ways the Microsoft documentation EXPLICITLY advises against because the results are occasionally unpredictable.  Rocky's justification for passing UDTs is that it's the fastest way.  VB was designed for speed of develoment, not speed of execution.  PropertyBags are almost as fast as UDTs and have none of the bad side effects.  

The other thing wrong with passing UDTs is what happens if one of the field lenght changes.  I'd hate to maintain that ripple effect.

Just my .02
0
 
dbbishopAuthor Commented:
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.

 
0
 
inthedarkCommented:
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...
0
 
dbbishopAuthor Commented:
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).
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now