Right guys, I'm really new to this but I'm getting along ok, but I've hit a block.
I need to be able to know how to search a text file in VB for a particular line and then display it.
the files I'm trying to use are set up as: ID, Name, Address, Birthday, Pay-Roll Type
So I need to know how to search the file for the ID number and then display the rest of that line
I can read a file from beginning to end but this I am clueless about, thanks
It's for a system to add, display, update and remove workers
Easy...just test the values immediately after you do each read. Stop reading when you find what you're looking for. Here's a code snippet to get you started:
Dim intId As Integer
Dim strname As String
Dim strAddress As String
Dim strBirthDate As String
Dim strPayrollType As String
Open App.Path & "\FileReadingFun.txt" For Input As 1
If Not EOF(1) Then
Input #1, intId, strname, strAddress, strBirthDate, strPayrollType
If intId = 2 Then ' or whatever you test for
Debug.Print CStr(intId); strname; strAddress; strBirthDate; strPayrollType
' or whatever you're going to do with your data
Loop Until EOF(1)
Depending on how you open and read your file, you have various options as far as writing changes and such. You'll have to figure that part out yourself. I suggest you spend some time looking at the OPEN statement in the VB Help File.
That being said, I would question your choice of using a regular text file to do this. Have you considered using a DBMS such as MSAccess, mySQL or MSSQL? Or, if that's not an option, how about reading your entire text file into an ADO Recordset object in memory, doing your manipulations there, then write the whole dataset back to a text file when you're done? There are lots of options.