Solved

Question using LSET

Posted on 2006-10-24
8
410 Views
Last Modified: 2008-02-01
I want to read the contents of a file into a UDT that is basically a "buffer" and then use LSET to move it into a UDT that has all the fields layed out properly. The UDT I am reading the line into has just a single variable defined as a fixed-length string the length of the data record...

Public Type KPAyData
   Buffer As String * 4340
End Type

Public PayrollBuffer as KPayData

The data is payroll information. As such, it has a number of repeating fields for earnings, taxes, deductions, etc. I have defined a UDT for each of these repeating groups of fields, and used an array of that type in the appropriate place in the UDT that defines all the data. A small example is as follows...

Public Type PayrollTaxDeduction
  TaxClass As String * 1
  TaxState  As String * 6
  TaxLocality As String * 10
  TaxAmount As String * 12
End Type
...

Public Type KPayType
  EmployeeID As String * 11
  EmployeeSSN As String * 9
  ...
  TaxDeductions(1 to 10) As PayrollTaxDeduction
  ...
End Type

Public PayrollRecord as KPayType

If I do a Len() and LenB() on the types, the lengths come out correctly, but when I try to LSet PayrollRecord = PayrollBuffer, I get a Type Mismatch error. I am suspecting that using the array of UDTs in KPayType may be causing the error, but not certain. Can someone either confirm that or give me another avenue to pursue in determining why I am getting the error.

Also, if you can provide an alternative way to do this, I would appreciate it. There are 75 repeating groups just for deductions and each group contains five fields. I would hate to have to hard-code all of those (641 fields altogether).

Regards,
Doug
0
Comment
Question by:dbbishop
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17796819
vb6 or vb.net?
in vb6, this should work, but in vb.net this is no longer allowed like this afair
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17796826
0
 
LVL 5

Expert Comment

by:lunchbyte
ID: 17796841


I do not think you can do lset to type name (the name of the type not the type items).

this is ok.
lset payrollrecord.employeeid = your value

this is not ok
LSet PayrollRecord = PayrollBuffer

consider this
dim str as string
str = space(641)

lset str = payrollrecord.employeeid & payrollrecord.employeessn & your other fields
0
 
LVL 26

Accepted Solution

by:
EDDYKT earned 500 total points
ID: 17796897
CopyMemory?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 20

Expert Comment

by:hes
ID: 17797439
As EDDYKT use the copymemory to move your string to the udt
0
 
LVL 15

Author Comment

by:dbbishop
ID: 17797539
angelIII:
vb6 - I am aware that .net does not support LSet for UDTs.

lunchbyte:
You can lset UDT to UDT. I have done it many, many times using this method. I have just never had another UDT (or array of UDTs) within the receiving UDT before. Furthermore, there are 641 fields, not bytes. The record length is 4340 bytes. Besides, I am wanting to go the other way. PayrollBuffer.Buffer receives the data from the record and I want to copy it into PayrollRecord.
0
 
LVL 5

Expert Comment

by:lunchbyte
ID: 17797755
well, I learn something new.

Sorry if I was no help. :(
0
 
LVL 15

Author Comment

by:dbbishop
ID: 17798094
lunchbyte: hang in there-better luck next time :-)

CopyMemory worked like a champ.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now