Say I have a data file that was created in VB6 like this:
Dim arr As Variant
Dim unit As Integer
Dim i As Integer
unit = FreeFile
Open "SomeFile.dat" For Binary As unit
ReDim arr(1 To 10)
For i = 1 To 10
arr(i) = i
Put #unit, , arr
I'm attempting to use the Microsoft.VisualBasic namespace to read the contents of this file by using the FileGetObject routine. However, FileGetObject fails with an IndexOutOfRangeException. My guess is it fails because it cannot handle non-zero-based arrays. Does anyone have a way to read a one-based array from a VB6 data file in .NET?
Here's my VB.NET code:
Dim mFileNumber as Integer = FreeFile()
FileOpen(mFileNumber, "SomeFile.dat", OpenMode.Binary, OpenAccess.Read)
Dim arr as Object
Note that the actual files I'm reading are much more complicated than this example, as they could contain nested arrays and either 0- or 1-based multidimensional arrays.
Thank you very much for your help,
Your issue is not whether the array is a 1 or 0 based array. The array index is not stored in the file, just the array data. If you load the array in C based language it will be a zero-based array (0 to 9). Are you sure tat it is not just getting all the data and then erroring out at the end of the file? Try opening the file in random mode and looping and see where your error occurs:
Try Dim fileHandle As Integer = 1 Dim c As String FileSystem.FileOpen(fileHandle, My.Computer.FileSystem.SpecialDirectories.Desktop & "\test.dat", OpenMode.Random) For i = 1 To 10 FileSystem.Seek(fileHandle, i) FileSystem.FileGetObject(fileHandle, c) MsgBox(c) Next FileSystem.FileClose(fileHandle) Catch ex As Exception MsgBox(ex.Message) End Try
Any chance you can offer a sample file to play with? I'm guessing any solution will require reading the data into a stream and then coding something to do the conversion.