VB6 to VB.Net " FileGet" conversion problem


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 9 of 9

Thread: VB6 to VB.Net " FileGet" conversion problem

Hybrid View

  1. #1
    Join Date
    Jan 2007
    Posts
    6

    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.

    The VB 6.0 code works fine as bellow:
    FileName$ = "c:\Impact-E\TestFiles\" & Text1.Text & ".dat"
    Open FileName$ For Random As #3 Len = Len(TestRecord(1))
    Get #3, I, TestRecord(2)

    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.

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Please post the definition of TestRecord. Also, how many records are in the file? What is the value of 'I' when the error occurs?
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Jan 2007
    Posts
    6

    Post

    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

  4. #4
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    What does Len(TestRecord(1)) return in VB.NET? In VB6? I suspect that your VB.NET structure is larger than the record in the file.

    FYI, you may calculate the number of records in the file by dividing the file length by the record length:

    NumberOfRecords = FileLen(FileName) \ Len(TestRecord(1))
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  5. #5
    Join Date
    Jan 2007
    Posts
    6
    I found the values you asked for and I can see that the file is larger than my TestRecord length.

    VB.Net -> Len(TestRecord(1)) = 8370
    VB 6.0 -> Len(TestRecord(1)) = 8378

    VB.Net -> FileLen(FileName) = 8372
    VB 6.0 -> FileLen(FileName) = 8372

    In order to fix this problem, do you think it would be better to make a modification in the TestRecord length or should I make corrections when saving the file?

  6. #6
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    I would try to figure out why Len(TestRecord) is different in VB6 and VB.NET. If you post the VB6 type definition, we can help you figure it out.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  7. #7
    Join Date
    Jan 2007
    Posts
    6
    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

  8. #8
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    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
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  9. #9
    Join Date
    Jan 2007
    Posts
    6
    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.
    Last edited by Mr. Wok; 01-25-2007 at 08:59 AM.

Similar Threads

  1. VB6 Print Problem
    By Probie in forum VB Classic
    Replies: 3
    Last Post: 01-05-2007, 03:37 PM
  2. Replies: 6
    Last Post: 12-11-2002, 05:08 AM
  3. VB6 Calling a VB.Net Dll
    By Graham Russell in forum VB Classic
    Replies: 1
    Last Post: 09-25-2002, 08:13 AM
  4. VB.NET vs VB6
    By Humberto Morales in forum .NET
    Replies: 2
    Last Post: 04-18-2001, 10:46 PM
  5. VB.NET: 3 points of view
    By David Kroll in forum .NET
    Replies: 33
    Last Post: 02-13-2001, 10:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center