Update a structure when another structure changes

  • Thread starter Thelonious Monk
  • Start date
T

Thelonious Monk

Is there a way to update two structures when you use a FileGet to read a
record? For example:

Public Structure MyRecordStructure
<VBFixedString(517)> Dim All_Of_Record as String
End Structure

Public Structure Record1_Structure
<VBFixedString(1)> Dim Record_Type as String
<VBFixedString(30)> Dim CustomerName as String
<VBFixedString(486)> Dim Rest_Of_Record as String
End Structure

Public Structure Record2_Structure
<VBFixedString(1)> Dim Record_Type as String
<VBFixedString(8)> Dim CustomerNumber as String
<VBFixedString(30)>Dim CustomerAddress as String
<VBFixedString(478)> Dim Rest_Of_Record as String
End Structure
 
T

tomb

Thelonious said:
Is there a way to update two structures when you use a FileGet to read a
record? For example:

Public Structure MyRecordStructure
<VBFixedString(517)> Dim All_Of_Record as String
End Structure

Public Structure Record1_Structure
<VBFixedString(1)> Dim Record_Type as String
<VBFixedString(30)> Dim CustomerName as String
<VBFixedString(486)> Dim Rest_Of_Record as String
End Structure

Public Structure Record2_Structure
<VBFixedString(1)> Dim Record_Type as String
<VBFixedString(8)> Dim CustomerNumber as String
<VBFixedString(30)>Dim CustomerAddress as String
<VBFixedString(478)> Dim Rest_Of_Record as String
End Structure
.
.
.
.
Dim MyInputRecord as MyRecordStructure
Dim Record_Type1 as Record1_Structure
Dim Record_Type2 as Record2_Structure

.
.
.
InputCh = FreeFile
FileOpen(InputCh, "c:\this\is\my\file", OpenMode.Random,
OpenAccess.Default, OpenShare.Shared, 517)
Do While Not EOF(InputCh)
FileGet(InputCh, MyInputRecord)
'
' Map the contents of MyInputRecord to Record_Type1 and
Record_Type2
'
.
.
.
End While

The FileGet method reads information into a structure that you have
declared. What I'm trying to accomplish is an automatic mapping of one
record structure (MyInputRecord) to Record_Type1 and Record_Type2, similar
to how languages such as COBOL does it. Each record in my file is 517
characters in length without any termination in the record (i.e. no
CHR(13)). Can someone offer any useful suggestions?

Thanks!
mid(str1,start,length)

T
 
T

Thelonious Monk

tomb said:
mid(str1,start,length)

T

I would have to write a Mid statement for each field. I have a bunch. I
would like the process to be done automatically, if possible.
 
G

GhostInAK

Hello Thelonious,

Since, as you say, you have fixed-length records.. how about just one structure..
The one that has the most level of detail.
Then you can add properties and/or methods for accessing the data in any
way you choose. You might even create your other structures (if you really
have need of them) and provide conversion functions off the main struct..
like MainStruct.ToSomeOtherStruct().. which would provide a copy of the data
in a diff format.

-Bo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top