Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > File I/O and Registry > Searching a sequential file for a data match


Reply
 
Thread Tools Display Modes
  #1  
Old 07-11-2003, 12:09 PM
beanodandy beanodandy is offline
Newcomer
 
Join Date: Jul 2003
Posts: 3
Default Searching a sequential file for a data match


I am using a sequential file in VB6 where a user will input values into text boxes (eg txtID - C100, txtName – Jones, txtStatus – Current) and then append the details to a file (code so far).

Private Sub cmdFile_Click()

Dim FileTransfer As String

FileTransfer = txtID & " " & txtName & " " & txtStatus

Open "test.txt" For Append As #1
Print #1, FileTransfer
Close #1

txtRequest = ""
txtName = ""
txtStatus = ""

End Sub

This works fine but, I want to set up another command button where a user will enter a txtStatus value in a separate text box, and then the line details for the first located instance for that status will populate the previous text boxes (or if this is too complicated appear in a label). I also need to know how to locate the next instance for that status.

Any code would be much appreciated, or any sites that could help with my problem. Thanks in anticipation.
Reply With Quote
  #2  
Old 07-14-2003, 12:38 AM
loquin's Avatar
loquin loquin is offline
Google Hound

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Arizona, USA
Posts: 12,386
Default

So, you need to Open the textfile for Input, and loop through reading a line of text, checking the status, if the status read matches the entered status Update the Textboxes & exit the loop.

Code:
Dim strLine as String, strData() as String Open "test.txt" For Input As #1 Do While Not EOF (#1) And strStatus <> txtStatus.Text Line Input #1, strLine ' Read the entire line into the string strData = Split(strLine," ") ' Split the data into component fields If strData(2) = me.txtStatus.Text then me.txtRequest.Text = strData(0) me.txtName.Text = strData(1) End If Loop
I hope the name doesn't include a space, else the split won't be able to differentiate between a space used as a field delimitor and one used to separate first & last names. IF you use a comma to separate the fields, you could read the data directly into variables using the input command
Code:
Line Input #1, strRequest, strName, strStatus
__________________
Lou
"I have my standards. They may be low, but I have them!" ~ Bette Middler
"It's a book about a Spanish guy called Manual. You should read it." ~ Dilbert
"To understand recursion, you must first understand recursion." ~ unknown
Reply With Quote
  #3  
Old 07-14-2003, 07:08 AM
mmmaah mmmaah is offline
Freshman
 
Join Date: Jul 2003
Posts: 34
Question

Why don't you use a database and then play around with sql. It's just so ease....
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Installation Problem - PLs help urgenlty dpdsouza Installation / Documentation 4 12-02-2004 07:09 PM
Doesn't want to register! MikeyM Installation / Documentation 5 03-02-2003 08:22 PM
File Searching / Recursion question Mowzee General 4 10-30-2002 09:26 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->