| | |
Help with Advancing to Next Record, read line continued iteration problem
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2008
Posts: 1
Reputation:
Solved Threads: 0
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:
Record Number
First Name
Middle Name
Last Name
Employee Number
Dept
Phone
Extension
Email
__________
File Values
_________
462
Mike
B
Davis
1122
Accounting
322-0009
112
mike@aol.com
612
Sam
L
Jackson
1048
Administration
966-7589
2
sam@aol.com
398
Lin
P
Daniels
1014
Marketing
966-2217
5
Lin@aol.com
___________
Code Example:
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:
Record Number
First Name
Middle Name
Last Name
Employee Number
Dept
Phone
Extension
__________
File Values
_________
462
Mike
B
Davis
1122
Accounting
322-0009
112
mike@aol.com
612
Sam
L
Jackson
1048
Administration
966-7589
2
sam@aol.com
398
Lin
P
Daniels
1014
Marketing
966-2217
5
Lin@aol.com
___________
Code Example:
VB.NET Syntax (Toggle Plain Text)
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
Last edited by noseforwine; Dec 6th, 2008 at 9:48 pm.
•
•
Join Date: Dec 2002
Posts: 461
Reputation:
Solved Threads: 56
The reason is because in your ReadFile you are opening the file, reading a set of data and then closing the file. The next time you use it, it is reading the same record.
Move the Input.Close() to a button to close it and also in FormClosing. However, this is only going to let you go one way in the file, top to bottom, and you will not be able to make changes to the file.
Why not use a database or CSV?
Move the Input.Close() to a button to close it and also in FormClosing. However, this is only going to let you go one way in the file, top to bottom, and you will not be able to make changes to the file.
Why not use a database or CSV?
Last edited by waynespangler; Dec 7th, 2008 at 6:33 am.
Wayne
It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: My Calculator
- Next Thread: Help with Visual Studio 2008
| Thread Tools | Search this Thread |
.net .net2008 2008 access account advanced application array basic beginner browser button buttons center click code combo cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic excel exists fade filter forms generatetags gridview html images input insert intel internet listview map mobile module monitor msaccess net number objects open panel passingparameters pdf picturebox picturebox2 port position print printing problem regex right-to-left save search searchvb.net select serial settings shutdown socket sqldatbase sqlserver survey table temperature textbox timer timespan transparency txttoxmlconverter update user usercontol vb vb.net vb.netformclosing()eventpictureboxmessagebox vba vbnet visual visualbasic visualbasic.net visualstudio.net visualstudio2008 web winforms wpf wrapingcode xml year





