Imports System.IO
Structure Product
Dim ProdID As String
Dim ProdDescription As String
Dim ListPrice As Single
Dim Available As Boolean
Dim MinStock As Integer
End Structure
public class Test
public Shared Sub Main
Dim objBR As BinaryReader
Dim objFS As FileStream
Dim objProduct As New Product
objFS = New FileStream("Records.bin", FileMode.Open, FileAccess.Read)
objBR = New BinaryReader(objFS)
objBR.BaseStream.Seek(0, SeekOrigin.Begin)
While objFS.Position < objFS.Length
objProduct = Nothing
With objProduct
.ProdID = objBR.ReadString
.ProdDescription = objBR.ReadString
.ListPrice = objBR.ReadSingle
.Available = objBR.ReadBoolean
.MinStock = objBR.ReadInt32
End With
ShowRecord(objProduct)
End While
objBR.Close()
objFS.Close()
End Sub
Private Shared Sub ShowRecord(ByVal objRecord As Product)
Console.WriteLine(objRecord.ProdDescription)
Console.WriteLine(objRecord.ListPrice.ToString)
Console.WriteLine(objRecord.Available)
Console.WriteLine(objRecord.MinStock.ToString)
End Sub
End class
|