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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conversion of user-defined types

Status
Not open for further replies.

Fordham99

Programmer
Feb 27, 2004
3
US
Here is my issue in a nutshell. A customer of mine has an ascii file filled with records. Every record is 256 bytes long, so I have setup types (using the vba TYPE statement) for each type of record there is.

The problem is, I have no way of knowing which type a record is until I read it into memory from the file. The indicator is the first 5 characters of the record are a code telling me which type to use. Is there a function that performs a direct memory copy from a variable of one type to a variable of another type.

Currently I am reading the data into the most common record type and then checking the code. If the type is incorrect, I write the data out to a temporary file and read it back in again to the correct type. This is (obviously) VERY inefficient because of all the useless disc reads/writes.

I have done linux programming and used the memcpy and bcopy functions. Do such functions exist in windows anywhere?

Any help would be greatly appreciated.
 
Setting up user defined types to handle ascii records seems awkward. Are you familiar with the FileSystem object?
 
I am not familiar with the filesystem object. The reason I went with user defined types is because each line in the ascii file is exactly 256 bytes long and I can read it in a binary fashion (my user-defined types are all strings of specific lengths). I was actually searching for information on a different problem and I ran across this API function:

Public Declare Sub sapiCopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(hpvDest As Any, _
hpvSource As Any, _
ByVal cbCopy As Long)

Which seems to be the exact function I was looking for. It seems I ended up answering my own question.

If you have an idea for a better method of reading an ascii file I am wide open to any other options.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top