BEWARE of FileSystem.FilePutObject

29. February 2012 15:45 by Mrojas in File, VB6 Migration  //  Tags: , , , , , , ,   //   Comments (0)

When you are migrating from VB6 to VB.NET most of the Put statements will be migrated to 

FileSystem.FilePutObject http://msdn.microsoft.com/en-us/library/z07he9as.aspx

The problem with this is that if you need that the files generated by your application to be compatible byte per byte
with your VB6 generated files you must put special attention.

Take a look at this example: 

Module Module1

    Sub Main()
              Dim str = "TEXTDATA"
              FileSystem.FileOpen(1, "c:\temp\file1.dat", OpenMode.Random, OpenAccess.Write, , 30)
              FileSystem.FilePutObject(1, str, 2)
              FileSystem.FileClose(1)
    End Sub

End Module

 

Module Module1

    Sub Main()
              Dim str = "TEXTDATA TEXTDATA TEXTDATA"
              FileSystem.FileOpen(1, "c:\temp\file1.dat", OpenMode.Random, OpenAccess.Write, , 30)
              FileSystem.FilePut(1, str, 2)
              FileSystem.FileClose(1)
    End Sub

End Module

 

The difference might seem minimal but it can be hard to detect.

The different byte is caused by using the FilePutObject instead of FilePut method