Answered by:
Find number of elements and its size Vb.net

Question
-
Hi,
we are trying to read a .dat file which is saved using VB6 random file mode. Each Record Size is 169, Which is further divided into 29 sub values And are success full in reading 4 values out of these 29 values.
is there any tools which can help find the size of data in each element so that it will be possible to retrieve all the values ?
Below is the code with which we were able to retrieve few data. Its a Sample code to identify where the variables are
Module Module1 Structure new_type_spice <VBFixedString(5)> Dim Var0 As String 'Variable size 5 <VBFixedString(30)> Dim Var1 As String 'Variable size 30 Dim Var2 As Long Dim Var3 As Long Dim Var4 As Long Dim Var5 As Long Dim Var6 As Long Dim Var7 As Long Dim Var8 As Long Dim Var9 As Long <VBFixedString(2)> Dim Var10 As String <VBFixedString(12)> Dim Var11 As String '68 length from var1 to var11 and variable size of 12 <VBFixedString(1)> Dim Var12 As String <VBFixedString(1)> Dim Var13 As String <VBFixedString(1)> Dim Var14 As String <VBFixedString(1)> Dim Var15 As String <VBFixedString(1)> Dim Var16 As String <VBFixedString(1)> Dim Var17 As String <VBFixedString(1)> Dim Var18 As String <VBFixedString(1)> Dim Var19 As String <VBFixedString(1)> Dim Var20 As String <VBFixedString(1)> Dim Var21 As String <VBFixedString(1)> Dim Var22 As String <VBFixedString(1)> Dim Var23 As String <VBFixedString(1)> Dim Var24 As String <VBFixedString(1)> Dim Var25 As String <VBFixedString(1)> Dim Var26 As String <VBFixedString(1)> Dim Var27 As String <VBFixedString(40)> Dim Var28 As String 'Variable size of 40 End Structure End Module
Public Class Form1 Dim table1 As DataTable Dim source_file As String = "C:\Users\Developer\Desktop\Speiseliste\Speisen.dat" Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Dim rec As New new_type_spice, Count As Integer If Len(rec) <> 169 Then Dim ans = MsgBox("Length of datatype is : " & Len(rec), vbYesNo) If ans = vbYes Then Exit Sub If ans = vbNo Then Exit Sub End If Dim FileNum = FreeFile() FileOpen(FileNum, source_file, OpenMode.Random, , , 169) Count = 1 Do While Not EOF(FileNum) 'Read the record on the position Count. FileGet(FileNum, rec, Count) Dim row As DataRow = table1.NewRow row(0) = rec.Var0 row(1) = rec.Var1 row(2) = rec.Var2 row(3) = rec.Var3 row(4) = rec.Var4 row(5) = rec.Var5 row(6) = rec.Var6 row(7) = rec.Var7 row(8) = rec.Var8 row(9) = rec.Var9 row(10) = rec.Var10 row(11) = rec.Var11 row(12) = rec.Var12 row(13) = rec.Var13 row(14) = rec.Var14 row(15) = rec.Var15 row(16) = rec.Var16 row(17) = rec.Var17 row(18) = rec.Var18 row(19) = rec.Var19 row(20) = rec.Var20 row(21) = rec.Var21 row(22) = rec.Var22 row(23) = rec.Var23 row(24) = rec.Var24 row(25) = rec.Var25 row(26) = rec.Var26 row(27) = rec.Var27 row(28) = rec.Var28 table1.Rows.Add(row) table1.AcceptChanges() dg.Refresh() Count = Count + 1 Loop FileClose(FileNum) End Sub Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load table1 = New DataTable("Test_Table") Dim column As New DataColumn For i = 0 To 28 Dim column1 As DataColumn = New DataColumn("Column " & i) table1.Columns.Add(column1) Next dg.DataSource = table1 Button2_Click(sender, e) End Sub End Class
below is the screenshot from Hex Editor Application.
here is the .dat file we are trying to access. 1Speisen.dat
Coderv9
- Moved by Dave PatrickMVP Friday, May 31, 2019 11:17 PM looking for forum
Friday, May 31, 2019 9:56 PM
Answers
-
If you're asking a VB.Net question I'd ask for help over here.
https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vbgeneral
otherwise if this is about VB6 then the microsoft forums are long gone so try here or also others you can search for.
http://www.vbforums.com/forumdisplay.php?1-Visual-Basic-6-and-Earlier
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.- Proposed as answer by Richard MuellerMVP, Banned Saturday, June 1, 2019 11:35 AM
- Marked as answer by Richard MuellerMVP, Banned Friday, June 7, 2019 11:54 AM
Friday, May 31, 2019 11:16 PM
All replies
-
If you're asking a VB.Net question I'd ask for help over here.
https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vbgeneral
otherwise if this is about VB6 then the microsoft forums are long gone so try here or also others you can search for.
http://www.vbforums.com/forumdisplay.php?1-Visual-Basic-6-and-Earlier
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.- Proposed as answer by Richard MuellerMVP, Banned Saturday, June 1, 2019 11:35 AM
- Marked as answer by Richard MuellerMVP, Banned Friday, June 7, 2019 11:54 AM
Friday, May 31, 2019 11:16 PM -
is there any tools which can help find the size of data in each element
Variables appear to be fixed size and most of the file is just binary zeroes. (Using Notepad++ hex editor)
$data = Get-Content C:\users\dave\Downloads\1Speisen.dat $pos = 0 while($pos -lt $data.Length) { $rec = $data.Substring($pos,169) $menuitem = $rec.Substring(5,30) $not = $rec.Substring(103,12) "$menuitem $not" $pos += 169 }
Saturday, June 1, 2019 2:17 AM -
HI Dave,
We are looking for a solution in VB.net.
Coderv9
Saturday, June 1, 2019 6:21 AM -
Hi MotoX80,
Thank you for inputs. But the strange part is there are actual data in those field. This is the screenshot from the app that reads this file. It's quite outdated and we wanted to move all the data to VB net platform.
Coderv9
- Edited by Coderv9 Saturday, June 1, 2019 6:24 AM
Saturday, June 1, 2019 6:23 AM -
I take it that you do not have the source code to the original VB6 program. Otherwise your variable names would be more meaningful than VAR1.
Have you tried any of these links? http://www.program-transformation.org/Transform/VisualBasicDecompilers
There does not appear to be anything in your data file that defines the record layout.
Here is the Pizza Margherita record. The 1,2,3,4,1 sequence would appear to be integers and correspond to the K, N, G, B, Kate fields in your image.
The best idea that I have is for you to use your test record. Change each field one by one and see what data changes in the file. That way you can figure out the real record layout and write an extract program to load the data into an XML format or put it into a database.
- Edited by MotoX80 Saturday, June 1, 2019 1:11 PM
Saturday, June 1, 2019 11:55 AM -
HI Dave,
We are looking for a solution in VB.net.
Then I'd ask for help over here.
https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vbgeneral
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.Saturday, June 1, 2019 12:13 PM -
Hi MotoX80,
Finally found a solution from Old VB6 Forum :) Thank you for the time and help on this
http://www.vbforums.com/showthread.php?875221-Read-Dat-file-to-a-table-list-in-List-Box
Coderv9
Saturday, June 1, 2019 5:46 PM