3

I am converting a project from vb6 to vb.net.
I converted most of the part but stuck on a line.

VB6 code :

    Do While Not EOF(FileO)
        Get #FileO, , ByteBuffer
        If Loc(FileO) < LOF(FileO) Then
            ByteCounter = ByteCounter + 64
        End If
    Loop

VB.NET Code :

  Do While Not EOF(FileO)
            Get(#FileO, , ByteBuffer) '----------> PROBLEM HERE
            If Loc(FileO) < LOF(FileO) Then
                ByteCounter = ByteCounter + 64
            End If
        Loop

I am getting problem over the get statement.
Get(#FileO, , ByteBuffer)

Error I am facing is :

Error BC30829 'Get' statements are no longer supported. File I/O functionality is available in the 'Microsoft.VisualBasic' namespace.

What is replacement for GET statement?? How to apply?
Thanx :)

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
Hitesh Shroff
  • 71
  • 1
  • 1
  • 9
  • 10
    Take a look for the reference: [BC30829 Get statement deprecation](https://learn.microsoft.com/en-us/dotnet/visual-basic/misc/bc30829). You should use `System.IO` for file operations, e.g. `ReadAllLines`, `ReadAllBytes`, etc. – Tetsuya Yamamoto Oct 23 '18 at 07:32
  • Ideally, the code should be reworked to use System.IO. Pursuant to an answer based on System.IO, it would be helpful if you provided a full code sample (replete with variable definitions). – R.J. Dunnill Oct 25 '18 at 16:35
  • Voting to reopen. The C# equivalent is NOT the VB.net equivalent. And the problems are not equivalent problems. – jmoreno Nov 02 '18 at 20:08

2 Answers2

1
 Option Explicit On

 Imports System
 Imports System.IO

 Module Module1
     Sub Main()
         Dim ByteBuffer As Byte()

         Using myFile As BinaryReader = New BinaryReader(File.Open("TESTFILE.BIN", FileMode.OpenOrCreate))
             While myFile.BaseStream.Position < myFile.BaseStream.Length
                 ByteBuffer = myFile.ReadBytes(64)
             End While

             myFile.Close()
         End Using
     End Sub

End Module
R.J. Dunnill
  • 2,049
  • 3
  • 10
  • 21
0

As a jump start - you should use your ide and the object browser to see what you can get from this:

// make sure the read buffer is big enough
string testReadData = "".PadRight(128);
int filenumber = VB6FileSystem.FreeFile();
VB6FileSystem.FileOpen(filenumber, @"c:\temp\test.dat", VB.OpenMode.Random, RecordLength: 128);
// Write some test data ....
VB6FileSystem.FilePut(filenumber, "Testdaten 1", 1, true);
VB6FileSystem.FilePut(filenumber, "Testdaten 4", 4, true);
VB6FileSystem.FilePut(filenumber, "Testdaten 14", 14, true);
// Read some data ...
VB6FileSystem.FileGet(filenumber, ref testReadData, 14, true);
VB6FileSystem.FileClose(filenumber);

I think, you can grasp it

nabuchodonossor
  • 2,095
  • 20
  • 18