borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (real time mschart with scrollbar)Next Topic (How to do change automatically windows?) New Topic New Poll Post Reply
AndreaVB Forum : VB General : Searching a text file for information
Poster Message
Creatica
Level: Protégé

Registered: 01-02-2007
Posts: 4

icon Searching a text file for information

I have a text file with a few lines of data, for example:

---------
John-Smith
Mike-Grey
Susan-Bennet
---------
I want to be able to type in a name (i.e. John, Mike, Susan) and have it look in the file and display the last name.  I can get it to do so with the first line but can not figure out how to have it look line by line.

--------
dim fso as New FileSystemObject
dim ts as TextStream
dim strline as string
dim strFirstName as string

Set ts = fso.OpenTextFile("c:\test.txt", ForReading, True)
strline = ts.ReadLine
ts.Close
strUserData = Split(strline, "-")
--------

Is there a way to have it look at the first line, and if it does not match, look at the next line, then the next, etc.?  Thank you!

~Creatica

01-02-2007 at 10:47 PM
View Profile Send Email to User Show All Posts | Quote Reply
misterxed
Level: VB Lord


Registered: 12-06-2005
Posts: 151
icon Re: Searching a text file for information

Use
DO WHILE NOT EOF       'EOF = End of file

'ur code goes here
LOOP


Best of luck  

[Edited by misterxed on 04-02-2007 at 01:03 AM GMT]

____________________________
lOsT...

03-02-2007 at 08:03 PM
View Profile Send Email to User Show All Posts | Quote Reply
humberto
Level: VB Lord

Registered: 13-01-2005
Posts: 246
icon Re: Searching a text file for information



Private Sub Command1_Click()


  Dim sSearch As String
  Dim sLineBuff As String
  Dim liLineCounter As Long
  Dim iTextPosition As Integer


  sSearch = "FindFirst"
  sLineBuff = ""
  liLineCounter = 1
  iTextPosition = 0


'Open the file as text:

   Open "c:\LOGFILE.txt" For Input As #1


'Scan through the file looking for the text:
  Do Until EOF(1)
    Line Input #1, sLineBuff
    iTextPosition = InStr(sLineBuff, sSearch)
    If iTextPosition > 0 Then
Print "Text found at position "; iTextPosition; " in line"; liLineCounter
      Exit Do
    End If
  Loop


  End


End Sub

05-02-2007 at 12:23 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB General : Searching a text file for information
Previous Topic (real time mschart with scrollbar)Next Topic (How to do change automatically windows?) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder