How to read a .txt file in vb.net
Just to show how to read a txt or .dat file in vb.net
AI
AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Source Code
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1"> <tr> <td width="50%">Private Sub btnReadTextFile_Click(ByVal sender _ As System.Object, ByVal e As System.EventArgs) _ Handles btnReadTextFile.Click</td> <td width="50%"><font color="#008000">'first lets create a form, add a command button on it and create a txt file called my textfile.txt and save it in C:\<br> paste this code into the click event of the command button<br> </font></td> </tr> <tr> <td width="50%">Dim Strmyfile As String = FreeFile()<br> Dim strLine As String</td> <td width="50%"><font color="#008000">' first variable to hold our freefile you can<br> 'replace it with a number if you wish<br> </font></td> </tr> <tr> <td width="50%">FileOpen(Strmyfile, "C:\FRONTPG.LOG", _ OpenMode.Input, OpenAccess.Read, _<br> OpenShare.Shared, -1)<br> </td> <td width="50%"><font color="#008000">'once the file is opened <br> 'loop through every line and copy them to our<br> 'variable<br> </font></td> </tr> <tr> <td width="50%">Do While Not EOF(Strmyfile)<br> strLine = LineInput(Strmyfile)<br> MsgBox(strLine)</td> <td width="50%"><font color="#008000">'copy the results to <br> 'messagebox to show it<br> </font></td> </tr> <tr> <td width="50%"> Loop<br> End Sub</td> <td width="50%"><font color="#008000">Hit F5 to run the app</font></td> </tr> <table>
Original Comments (3)
Recovered from Wayback Machine