I have designed a form to open a .txt file, read the values and display them into the forms label controls. My problem is that I cant figure out how to advance to read the next record when I click on the next record btn. I am able to read the first 9 lines that are written to the file, but nothing after that. I need to be able to read lines 10 thru 19 and display them in the forms labels when the btnNext is clicked, Then display the next set of values lines 20 thru 29 when btnNext is clicked again. I think I need to figure out a way to increment the record count and reader.
Below is a sample of the .txt file I am opening as well as the forms code.
Any help or suggestions would be greatly appreciated. Thanks
Example of file lay out:
Option Strict On Imports System.IO Public Class frmMain Inherits System.Windows.Forms.Form Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ' Let the user select a file to open. Pass the selected file to the ReadFile procedure. With ofdOpenFile .Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*" .Title = "Select a File to Open" If .ShowDialog = Windows.Forms.DialogResult.OK Then If .FileName <> String.Empty Then ReadFile(.FileName) Else MessageBox.Show("No file selected.", "Error") End If End If End With End Sub Sub ReadFile(ByVal strFileName As String) ' Read the contents of the specified file into the UnitsSold array. Dim inputFile As StreamReader Dim intCount As Integer = 1 ' Declare variables. Dim intN As Integer Dim strFirst As String Dim strMiddle As String Dim strLast As String Dim intEmpNum As Integer Dim strDept As String Dim strPhone As String Dim intExt As Integer Dim strEmail As String ' Open the file. inputFile = File.OpenText(strFileName) ' Read the data. For intCount = 1 To 1 ' Read the record from the file. intN = CInt(inputFile.ReadLine()) strFirst = inputFile.ReadLine() strMiddle = inputFile.ReadLine() strLast = inputFile.ReadLine() intEmpNum = CInt(inputFile.ReadLine()) strDept = inputFile.ReadLine() strPhone = inputFile.ReadLine() intExt = CInt(inputFile.ReadLine()) strEmail = inputFile.ReadLine() ' Display the input data on the record form. lblN.Text = intN.ToString() lblFirst.Text = strFirst.ToString() lblMiddle.Text = strMiddle.ToString() lblLast.Text = strLast.ToString() lblEmpNum.Text = intEmpNum.ToString() lblDept.Text = strDept.ToString() lblPhone.Text = strPhone.ToString() lblExt.Text = intExt.ToString() lblEmail.Text = strEmail.ToString() Next intCount ' Close the file. inputFile.Close() End Sub Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click ' Here is where I need some help! End Sub End Class