Free Visual Basic 2010 Source Code VB2010
How to Read a Text TXT File








HOW TO READ FROM A TEXT FILE USING VISUAL BASIC 2010 (VB 2010)


DESCRIPTION

This Visual Basic 2010 code is a simple source code example of reading from a TEXT file using Visual Basic 2010.


THE VB2010 SETUP

Add the following lines to your 'Module1' code (add the Imports as the first lines above Module1 - ie at the very top!)

Imports System
Imports System.IO
Imports System.Collections

Module 1:
Public MyFileName As String
Public MyNewLine(1000) As String


THE FREE VISUAL BASIC 2010 VB 2010 SOURCE CODE

Copy and Paste this code wherever you need it:

'.....Free Source Code from www.freevb2010code.com
'.....Note that MyFileName should include the path to be safe
MyFileName="c:\myfile.txt"
'.....Open the file
'.....Note that the first parameter assigns a file number, the second parameter specifies the file to open and the third specifies the File Open Mode - ie Input = read mode
FileOpen(1, OpenFileDialog1.MyFileName, _OpenMode.Input)
'.....Now read the line(s) of text from the file until End of File (EOF) is reached
z=0 '.....Start the counter at zero
'.....Read the line of data (READ TEXT)
Do Until EOF(1)
MyNewLine(z) = LineInput(1)
z=z+1 '.....increment the counter
Loop

'.....An array of text strings has been created each line of the array holds a line from the text file..
'.....Close the file
FileClose(1)




Home to freevb2010code.com
VB2010 How to write to a CSV file
VB2010 How to write to a TEXT file
VB2010 How to read from a CSV file
VB2010 How to read from a TEXT file
VB2010 How to find a User Name
VB2010 How to fill a ListView
VB2010 How to write a ListView data table to a CSV file
VB2010 How to call another program
VB2010 How to copy and paste to the Windows Clipboard
VB2010 How to sort an array
VB2010 How to concatenate / join strings / text


Copyright SGDesigns (c)2010

Our aim is to provide simple concise and easy to follow Free Visual Basic 2010 Source Code for the casual programmer in VB2010. We hope you find the Visual Basic 2010 code example uselful. This VB 2010 code shows a simple method of how to read lines from a text file using Visual Basic 2010.





counter