none
Convert VBA code into code in VB.NET RRS feed

  • Question

  • How to convert the code (bold text) into the one in VB.NET? Thanks!

           KeyScope.Inst.WriteString ":DISPLAY:DATA? BMP"
           byteData = KeyScope.Inst.ReadIEEEBlock(BinaryType_UI1) ' Read the captured waveform screen data
           '
           fn = FreeFile() 'Returns an Integer representing the next file number available for use by the Open statement.
           '
           Open FileNameWPath For Binary Access Write Lock Write As #fn ' Open file for writing the captured waveform screen data.
           Put #fn, , byteData ' Write data.
           '
           Close #fn   ' Close file.

    Friday, August 16, 2019 8:33 AM

Answers

  • You can use FileStream Class
    • Marked as answer by JayWangTPE Tuesday, August 20, 2019 6:16 AM
    Friday, August 16, 2019 8:54 AM
  • Hi,

    First, the namespace System.IO is introduced. You can assign byteData directly, define BinaryWriter objects, and write data to files in binary or stream mode,try my code:

      Private Sub FileContent(ByVal bytedata() As Byte)
            Using fs As FileStream = New FileStream("D:\test.txt", FileMode.Open)
                Dim bw As New BinaryWriter(fs)
                bw.BaseStream.Seek(0, SeekOrigin.End)
                bw.Write(bytedata)
            End Using
        End Sub

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by JayWangTPE Tuesday, August 20, 2019 5:43 AM
    Monday, August 19, 2019 5:50 AM
    Moderator

All replies

  • You can use FileStream Class
    • Marked as answer by JayWangTPE Tuesday, August 20, 2019 6:16 AM
    Friday, August 16, 2019 8:54 AM
  • Hi,

    First, the namespace System.IO is introduced. You can assign byteData directly, define BinaryWriter objects, and write data to files in binary or stream mode,try my code:

      Private Sub FileContent(ByVal bytedata() As Byte)
            Using fs As FileStream = New FileStream("D:\test.txt", FileMode.Open)
                Dim bw As New BinaryWriter(fs)
                bw.BaseStream.Seek(0, SeekOrigin.End)
                bw.Write(bytedata)
            End Using
        End Sub

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by JayWangTPE Tuesday, August 20, 2019 5:43 AM
    Monday, August 19, 2019 5:50 AM
    Moderator
  • Thanks!
    Tuesday, August 20, 2019 6:17 AM