Showing posts with label reader. Show all posts
Showing posts with label reader. Show all posts

Sunday, 22 July 2012

Binary reader in vb.net

Binary Reader Object works at lower level of Streams. BinaryReader is used for read premitive types as binary values in a specific encoding stream. Binaryreader Object works with Stream Objects that provide access to the underlying bytes. For creating a BinaryReader Object , you have to first create a FileStream Object and then pass BinaryReader to the constructor method .

Dim readStream As FileStream

readStream = New FileStream("c:\testBinary.dat", FileMode.Open)

Dim readBinary As New BinaryReader(readStream)

The main advantages of Binary information is that stores files as Binary format is the best practice of space utilization.
Download Source Code
Print Source Code

Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
        Dim readStream As FileStream
        Dim msg As String
        Try
readStream = New FileStream("c:\testBinary.dat", FileMode.Open)
            Dim readBinary As New BinaryReader(readStream)
            msg = readBinary.ReadString()
            MsgBox(msg)
            readStream.Close()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Class


BinaryWriter you can use in the same way to write as binary.

Friday, 20 July 2012

StreamReader in vb.net

In this tutorial, you learn how to read the text from a text file using the StreamReader. using StreamReader  you can read file and write file append the text to file .

copy and paste below Code:

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If System.IO.File.Exists(TextBox1.Text) = True Then
            Dim objreader As New System.IO.StreamReader(TextBox1.Text)
            TextBox2.Text = objreader.ReadToEnd
            objreader.Close()
        Else
            MessageBox.Show("That file does not exist!")
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox2.Clear()
    End Sub

End Class

Wednesday, 25 January 2012

How to make text file reader in vb.net?


How to make my own text file reader in vb.net?
Step1:
Open Microsoft visual studio
Step2:
Create file newà windows applicationàrename it as text file reader
Step3:
Drag and drop the list box, three buttons,
Step4:
Change the form properties as you wish
Step5:
Copy the below code and paste in code window
Public Class Form1

    Private SubButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesButton1.Click

        Using FD As New OpenFileDialog()
            FD.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
            If FD.ShowDialog = Windows.Forms.DialogResult.OK Then
                ListBox1.Items.Clear()
                ListBox1.Items.AddRange(IO.File.ReadAllLines(FD.FileName))

            End If
        End Using
    End Sub
  
    Private SubButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesButton2.Click
        Close()
    End Sub

    Private SubButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesButton3.Click
        ListBox1.Text = ""
    End Sub

    Private SubForm1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
        ListBox1.Text = ""
    End Sub
End Class
Output:

Read the text file just click the read button to read.