How to Pen a File in VB.NET With a Specific Application

How to Pen a File in VB.NET With a Specific Application thumbnail
Read or write to your file in a VB.NET application.

Visual Basic (VB) is an object-oriented programming language. .NET framework supports various languages and libraries for users to develop Windows applications, mobile applications and office applications. In VB.NET, you can open a file such as text, Word or Excel and read or write to it. You can also connect and open a database file. You can retrieve, update or delete the records of the database file. Using the StreamReader Class, you can swiftly develop an application with the ability to open a file.

Instructions

    • 1

      Click “Start,” “All Programs” and “Visual Studio 2010” to open it. Click “File” and “New” to create a new project. Select “Visual Basic” as the programming language on the left pane of the dialog. Select “Windows Form Application” on the right pane. Enter a name for the project. Specify a folder to contain the project files by clicking “Browse.”

    • 2

      Click “Form1.vb” on the Solution Explorer. Switch to the "Design" view. Click “Toolbox” and choose “Button.” Click the blank area of the form and drop the button. Change the text of the button on the Properties to “button1.” Similarly drag a textbox to the form and rename it "textbox1."

    • 3

      Double-click the form to enter the code window.
      Include “System.IO” as StreamReader is a class in system.io:
      Import System.IO
      Define variables via code:
      Dim Filename As String=”C:/text/text1.txt”
      Dim Sreader As New System.IO.StreamReader (Filename)

    • 4

      Double-click "button1" and enter the following code between Sub and End Sub:
      textBox1.Text=Sreader.ReadToEnd
      Sreader.Close ()
      This code will read all the contents from the text1.txt and show them on text box “textbox1.” The streamreader object will close when the action finishes.

Related Searches:

References

  • Photo Credit Comstock/Comstock/Getty Images

Comments

Related Ads

Featured