Save Structure to a Binary File : Binary File Write « File Directory « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Date Time
8.Development
9.Event
10.File Directory
11.Generics
12.GUI
13.Internationalization I18N
14.Language Basics
15.LINQ
16.Network Remote
17.Reflection
18.Security
19.Thread
20.Windows Presentation Foundation
21.Windows System
22.XML
23.XML LINQ
VB.Net » File Directory » Binary File WriteScreenshots 
Save Structure to a Binary File
 
Imports System
Imports System.IO
Imports System.Windows.Forms

Public Class MainClass

   Shared Sub Main()
        Dim emp As New Employee

        Dim file_num As Integer = FreeFile()

        FileOpen(file_num, "MYFILE.DAT", OpenMode.Random, _
             OpenAccess.ReadWrite, OpenShare.Shared, _
             Len(emp))

        FilePut(file_num, New Employee(1"A""A"))
        FilePut(file_num, New Employee(2"B""B"))
        FilePut(file_num, New Employee(3"C""C"))
        FilePut(file_num, New Employee(4"D""D"))
        FilePut(file_num, New Employee(5"E""E"))
        FilePut(file_num, New Employee(6"F""F"))


        ' Close the file.
        FileClose(file_num)
   End Sub 
End Class

    Public Structure Employee
        Public ID As Integer
        <VBFixedString(15)Public FirstName As String
        <VBFixedString(15)Public LastName As String

        Public Sub New(ByVal new_id As Integer, ByVal first_name As String, _
         ByVal last_name As String)
            ID = new_id
            FirstName = first_name
            LastName = last_name
        End Sub

        Public Overrides Function ToString() As String
            Return ID & ": " & FirstName & " " & LastName
        End Function
    End Structure

           
         
  
Related examples in the same category
1.Creating a random file
2.Use BinaryWriter to store information into a binary file
3.Gets the underlying stream of the BinaryWriter.
4.BinaryWriter.Seek Method Sets the position within the current stream.
5.BinaryWriter.Write Method Writes an unsigned byte to the current stream and advances the stream position by one byte.
6.BinaryWriter.Write(Byte[]) Writes a byte array to the underlying stream.
7.Writes a region of a byte array to the current stream.
8.Writes a Unicode character
9.Writes a character array
10.Writes a section of a character array
11.Writes a length-prefixed string
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.