If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

VB6 to VB.Net " FileGet" conversion problem

I have been working on converting an old application from VB 6.0 to VB.Net. I have used the VB.Net 2005 conversion tool, but it still requires more editing on my part to have it function properly. My problem deals with taking a .dat file and inputing the data into an array TestRecord(2) using the FileGet function.

But after I used VB.Net 2005 conversion tool and rewrote the code it still does not work.
FileName = "c:\Impact-E\TestFiles\" & Text1.Text & ".dat"
FileOpen(3, FileName, OpenMode.Random, , , Len(TestRecord(1)))
FileGet(3, TestRecord(2), I) 'Error occurs on this line

The VB.Net code will open and begins to read the data, but then gives me an error #5. Saying its unable to read beyond the end of the stream.

The Test Records variables are in a structure named "Record", with 37 variables. The file also has 37 variables which are to be written to TestRecord(2).
"Public TestRecord(4) As record"

The "I" variable value is "1" when the error occurs. The "I" is part of a For loop to calculate the number of records in the file. 1 record = 37 data variables. The file I am trying to access only has one record.

Code:

For I = 1 To 3000
On Error Resume Next
FileGet(3, TestRecord(2), I) 'Error Occurs
If Err.Number <> 0 Then 'check to validate correct file
'Err message
End If
If EOF(3) Then GoTo Here
Next I
Here: FileClose(3)

Below is the Structure variables:

Code:

Structure record
Dim DateTime As Date 'Date & time of test.
<VBFixedString(20),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr,SizeConst:=20)> Public StrName As String 'Structure name
Dim StrType As Short 'Structure type
Dim TraceMod As Short 'Trace mode
Dim TrigMod As Short 'Trigger mode
<VBFixedString(12),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr,SizeConst:=12)> Public RecordNam As String 'Record Name
Dim RecordNum As Short 'Record number
<VBFixedString(40),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr,SizeConst:=40)> Public Description As String 'Record Description
Dim Dim1 As Short 'First dimension
Dim Dim2 As Short 'Second dimension (plate w/overlay or rect. column.
Dim DistA As Short 'Distance betw. sensors for wave speed meas.
Dim PWavSp As Short 'P-Wave speed in structure
Dim OPWavSp As Short 'P-Wave speed in overlay
Dim Poisson As Single 'Dynamic Poisson's Ratio
Dim RPWavSp As Single 'R-P wave speed ratio
Dim NSamp As Short 'Number of points in digitized record.
Dim WavSpSamp As Short 'Number of points in wave speed graph.
Dim TrigDel As Short 'Trigger delay
Dim Voltg As Single 'Voltage
Dim TrigV As Single 'Trigger voltage
Dim TimBetw As Single 'Time between samples (1 to 10 micr.-sec)
Dim ClipLvl As Single 'Clip level
Dim VScale As Single 'IE Waveform vert. scalefactor
Dim VScaleA As Single 'WavSp upper vert. scalefactor
Dim VScaleB As Single 'WavSp lower vert. scalefactor
Dim FScale As Short 'Max frequency in amplitude graph.
Dim CutRWv As Short 'Point at which R-Wave is cut (=0 if not cut).
<VBFixedArray(2048)> Dim TransSig() As Single 'Array for storing digitized time-disp data.
Dim Curs0 As Single 'Position of cursor 0
Dim Curs1 As Single 'Position of cursor 1
Dim Curs2 As Single 'Position of Cursor 2
Dim Curs3 As Single 'Position of Cursor 3 (Norm. Spectrum)/
Dim ConTime_Renamed As Single 'Contact Time
Dim Spare3 As Single 'Spare
Dim CardTyp As Short '=1 for Keithley Card, 2 for Gage Card, 4 for Serial Port Card
Dim LoFilter As Short '=1 if LoFilterOn = True, = 0 if False
Dim FiltCutOff As Short 'Frequency used to filter low frequencies

Im not sure what you mean by VB 6 Type definition, but i have pasted the VB 6 Record declarations.

I must point out that the declaration for the DateTime was converted to an Object in VB.Net 2005. However, it was giving me an error saying the structure with field 'DateTime' of type 'Object" was not valid. So I changed the declaration to [DateTime As Date]. Could that be of any significance?

VB 6

Code:

Option Explicit
Type record
DateTime As Variant 'Date & time of test.
StrName As String * 20 'Structure name
StrType As Integer 'Structure type
TraceMod As Integer 'Trace mode
TrigMod As Integer 'Trigger mode
RecordNam As String * 12 'Record Name
RecordNum As Integer 'Record number
Description As String * 40 'Record Description
Dim1 As Integer 'First dimension
Dim2 As Integer 'Second dimension (plate w/overlay or rect. column.
DistA As Integer 'Distance betw. sensors for wave speed meas.
PWavSp As Integer 'P-Wave speed in structure
OPWavSp As Integer 'P-Wave speed in overlay
Poisson As Single 'Dynamic Poisson's Ratio
RPWavSp As Single 'R-P wave speed ratio
NSamp As Integer 'Number of points in digitized record.
WavSpSamp As Integer 'Number of points in wave speed graph.
TrigDel As Integer 'Trigger delay
Voltg As Single 'Voltage
TrigV As Single 'Trigger voltage
TimBetw As Single 'Time between samples (1 to 10 micr.-sec)
ClipLvl As Single 'Clip level
VScale As Single 'IE Waveform vert. scalefactor
VScaleA As Single 'WavSp upper vert. scalefactor
VScaleB As Single 'WavSp lower vert. scalefactor
FScale As Integer 'Max frequency in amplitude graph.
CutRWv As Integer 'Point at which R-Wave is cut (=0 if not cut).
TransSig(0 To 2048) As Single 'Array for storing digitized time-disp data.
Curs0 As Single 'Position of cursor 0
Curs1 As Single 'Position of cursor 1
Curs2 As Single 'Position of Cursor 2
Curs3 As Single 'Position of Cursor 3 (Norm. Spectrum)/
ConTime As Single 'Contact Time
Spare3 As Single 'Spare
CardTyp As Integer '=1 for Keithley Card, 2 for Gage Card, 4 for Serial Port Card
LoFilter As Integer '=1 if LoFilterOn = True, = 0 if False
FiltCutOff As Integer 'Frequency used to filter low frequencies
End Type

Yes, the DateTime field is the problem. VB6 stores the DateTime Variant as 10 bytes. You may use the following structure to read the file in VB.NET, but I don't know how to convert the DateTime Byte() array into a .NET Date:

Code:

Structure record
<VBFixedArray(9)> _
Dim DateTime As Byte() 'Date & time of test.
<VBFixedString(20)> _
Dim StrName As String 'Structure name
Dim StrType As Short 'Structure type
Dim TraceMod As Short 'Trace mode
Dim TrigMod As Short 'Trigger mode
<VBFixedString(12)> _
Dim RecordNam As String 'Record name
Dim RecordNum As Short 'Record number
<VBFixedString(40)> _
Dim Description As String 'Record description
Dim Dim1 As Short 'First dimension
Dim Dim2 As Short 'Second dimension (plate w/overlay or rect. column.
Dim DistA As Short 'Distance betw. sensors for wave speed meas.
Dim PWavSp As Short 'P-Wave speed in structure
Dim OPWavSp As Short 'P-Wave speed in overlay
Dim Poisson As Single 'Dynamic Poisson's Ratio
Dim RPWavSp As Single 'R-P wave speed ratio
Dim NSamp As Short 'Number of points in digitized record.
Dim WavSpSamp As Short 'Number of points in wave speed graph.
Dim TrigDel As Short 'Trigger delay
Dim Voltg As Single 'Voltage
Dim TrigV As Single 'Trigger voltage
Dim TimBetw As Single 'Time between samples (1 to 10 micr.-sec)
Dim ClipLvl As Single 'Clip level
Dim VScale As Single 'IE Waveform vert. scalefactor
Dim VScaleA As Single 'WavSp upper vert. scalefactor
Dim VScaleB As Single 'WavSp lower vert. scalefactor
Dim FScale As Short 'Max frequency in amplitude graph.
Dim CutRWv As Short 'Point at which R-Wave is cut (=0 if not cut).
<VBFixedArray(2048)> _
Dim TransSig() As Single 'Array for storing digitized time-disp data.
Dim Curs0 As Single 'Position of cursor 0
Dim Curs1 As Single 'Position of cursor 1
Dim Curs2 As Single 'Position of Cursor 2
Dim Curs3 As Single 'Position of Cursor 3 (Norm. Spectrum)
Dim ConTime As Single 'Contact Time
Dim Spare3 As Single 'Spare
Dim CardTyp As Short '=1 for Keithley Card, 2 for Gage Card, 4 for Serial Port Card
Dim LoFilter As Short '=1 if LoFilterOn = True, = 0 if False
Dim FiltCutOff As Short 'Frequency used to filter low frequencies
End Structure

Thank you for showing me the correct structure to read the file. I do not need to have the DateTime array in .Net Date. I only changed the array to Date because i thought it was the correct solution. Thanks again for the the help.