FilePut/FileGetというのがあって便利
public Class Form1 'バイナリファイル読み書きの練習 Public Structure Person Public Name As String Public Age As Short End Structure Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'System.IOクラス 'BinaryWriter/Reader使用 Const filename = "F:\VB2005練習\バイナリファイル処理\test.dat" Dim i As Integer = 5554444 Dim db As Double = Math.PI '書き込み Dim BFile As New System.IO.BinaryWriter(New System.IO.FileStream(filename, IO.FileMode.Create)) BFile.Write(i) BFile.Write(db) BFile.Close() '読み込み Dim i_r As Integer Dim db_r As Double Dim BRFile As New System.IO.BinaryReader(New System.IO.FileStream(filename, IO.FileMode.Open, IO.FileAccess.Read)) i_r = BRFile.ReadInt32() '読み込み時は型を指定しないといけない db_r = BRFile.ReadDouble() BRFile.Close() Debug.WriteLine(i_r) Debug.WriteLine(db_r) End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 'Microsoft.Visualbasic.FileSystemクラス 'FilePut/Get使用 Const filename = "F:\VB2005練習\バイナリファイル処理\test2.dat" Dim i As Integer = 5554444 Dim db As Double = Math.PI '書き込み Dim n As Integer = FreeFile() FileOpen(n, filename, OpenMode.Binary) FilePut(n, i) FilePut(n, db) FileClose(n) '読み込み Dim i_r As Integer Dim db_r As Double n = FreeFile() FileOpen(n, filename, OpenMode.Binary, OpenAccess.Read, OpenShare.LockWrite) FileGet(n, i_r) FileGet(n, db_r) FileClose(n) Debug.WriteLine(i_r) Debug.WriteLine(db_r) End Sub