Visual Basic Online Course - VB .NET Read Text File

Visual Basic 2010 - How to Read Text File(s)

VB 2010 Read Text Files
VB .NET Read Text Files
Introduction

In order to read from a Text File then a Text File has to be present (Present = Known Path), the path of a Text File is just like any other path of any file it is String, for example :
C:\Folder\File.txt
The path to the File.txt is (C:\Folder\File-Name.Extension), so the path to the File Text = Path + File-Name + extension. Text Files can be present locally (on the same machine) or from external place (on the web) for example :
ftp://10.0.0.27/Folder/File.txt
As long as this Path is present and accessible then Reading Text File in VB 2010 is just so easy job to do. We can store the path to the Text File into a String variable to use it in our VB 2010 project :
Dim LocalFilePath as String = ("C:\Folder\File.txt")
Dim WebFilePath As String = ("ftp://10.0.0.27/Folder/File.txt")
The problem with Text Files hosted on the web, is that it has to be accessible in order to read it or write it, you have to provide  a User Name and Password to gain access to those files for most of the times because of security issues, unlike reading Text Files from local storage devices, there is no need to provide credentials or authentications to be able to read them.

Reading from Local Text Files in VB 2010

We will use File Reader to read String stored in a Text File,we will use basics of reading Text Files.

  1. Create VB 2010 Windows Form Project (WindowsApplication1) and save it to (D:\)
  2. Add TextBox (Name : TxtFromFile, MultiLine : True)
  3. Create Text File (MyFile.txt) and place it in the project folder Path to MyFile.txt is (D:\WindowsApplication1\Bin\Debug\)
  4. Write to MyFile.txt those two lines :
Hello
Visual Basic Online Course
5) Save and close the file.

Now, the project will :

  • Open the Text File to read on the Form_Load() event
  • Displays the String in the TextBox (TxtFromFile)

Code


Here are some online Visual Basic lessons and courses :

Popular posts from this blog

Visual Basic Online Courses DataGridView Add Edit Delete

VB .NET WebView2 WinForms tips

VB .NET Google Drive Api Source Code Example

Visual Basic 2010 Working With DataBase Full Project Example

DAO in VB .NET MS ACCESS Database

VB NET Check internet connection