How to read existing VB6 random access files with VB.net

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<p style="margin:0in 0in 10pt <span style="font-size:small <span style="font-family:Calibri I have 15 yearsâ worth of files (approx. 10,000) that were created using VB6 structures and stored using the random access method.<span style="
I am trying to write a conversion routine that will read the old structures and put them into a new format that is more compatible with the .net environment.<span style="
I have not been able to successfully read any of the old files using the tools available in .net.
<span style=" Each file starts with a header record structure. The header record tells me how many tags are in the file.<span style="
The next record (ie record number 2) is the first tag pointer record in the file.<span style="
There are num_of_tags of the pointer records.<span style="
Each pointer record has the string that holds the tags âliteral name and two long integers that tell where in the file this tags records are.<span style="
Those actual records are stored as History data structures,
<p style="margin:0in 0in 10pt <span style="font-size:small <span style="font-family:Calibri The header record has the form:
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; color:blue; font-size:9.5pt <span style="
Type<span style="font-family:Consolas; font-size:9.5pt <span style="color:#2b91af
Head_record1
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
num_of_tags <span style="color:blue As <span style="color:blue integer
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
record_dt <span style="color:blue As <span style="color:blue variant
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
Type <span style="color:blue As <span style="color:blue integer
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue End <span style="color:blue Type
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt The header is followed by tag structure that has pointers to the actual records for each tag:
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue Type <span style="color:#2b91af tag_Struct
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
Tag_id <span style="color:blue As <span style="color:blue String * 20
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
Start_rec <span style="color:blue As <span style="color:blue Long
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
Last_rec <span style="color:blue As <span style="color:blue Long
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue End <span style="color:blue Type
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt Each tagâs data is stored in records that have the following structure:
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
Type <span style="color:#2b91af History_Data
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
TimeStamp <span style="color:blue As <span style="color:blue Variant
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
value <span style="color:blue As <span style="color:blue Single
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
quality <span style="color:blue As <span style="color:blue String * 8
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue End <span style="color:blue Type
<p style="margin:0in 0in 10pt <span style="font-family:Calibri; font-size:small
<p style="margin:0in 0in 10pt <span style="font-size:small <span style="font-family:Calibri The files all have the same record length of 28
<p style="margin:0in 0in 10pt <span style="font-size:small <span style="font-family:Calibri I have tried reading the data into an object and casting the object into a structure that looks like the old type but that fails.<span style="
I have tried to read the file as binary streams getting one variable at a time but invariably lose track of where it is and start getting junk.
<p style="margin:0in 0in 10pt <span style="font-size:small <span style="font-family:Calibri I do not have any problem with creating new structures in VB.net and reading and writing them to file.<span style="
My problem is reading the old file so that I can convert them in to the new .net structures.
<span style="font-size:small <span style="font-family:Calibri
<p style="margin:0in 0in 10pt I have tried using:
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue Structure <span style="color:#2b91af Head_record1
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue Dim num_of_tags <span style="color:blue As
<span style="color:blue Short
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue Dim record_dt <span style="color:blue As
<span style="color:blue Object
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue Dim Type <span style="color:blue As
<span style="color:blue Short
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue End <span style="color:blue Structure
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue Structure <span style="color:#2b91af New_His_tag_Struct
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<<span style="color:#2b91af VBFixedString(20)> <span style="color:blue
Dim Tag_id <span style="color:blue As <span style="color:blue String

<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue Dim Start_rec <span style="color:blue As
<span style="color:blue Long
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue Dim Last_rec <span style="color:blue As
<span style="color:blue Long
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue End <span style="color:blue Structure
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue Structure <span style="color:#2b91af New_History_Data
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue Dim TimeStamp <span style="color:blue As
<span style="color:blue object
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue Dim value <span style="color:blue As
<span style="color:blue Single
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<<span style="color:#2b91af VBFixedString(8)> <span style="color:blue
Dim quality <span style="color:blue As <span style="color:blue String
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue End <span style="color:blue Structure
<p style="margin:0in 0in 10pt
<font size="3 <font face="Calibri
<p style="margin:0in 0in 10pt <span style="line-height:115%; font-family:"Calibri","sans-serif"; font-size:11pt With FileGet, FileGetObject, and opening the file for random and binary.<span style="
I have also tried using a BinaryReader without any success.
</font></font><font size="3
<p style="margin:0in 0in 10pt
</font>
<p style="margin:0in 0in 10pt
<p style="margin:0in 0in 10pt <span style="font-size:small <span style="font-family:Calibri Can anyone come up with a solution that does not involve writing a VB6 DLL to read these files?
<p style="margin:0in 0in 10pt <span style="font-size:small <span style="font-family:Calibri Thank you in advance! <hr class="sig E. L. Cranford

View the full article
 

Similar threads

D
Replies
0
Views
107
Donald Uko
D
D
Replies
0
Views
175
David William Smith
D
I
Replies
0
Views
156
Innovators World Wide
I
Back
Top