Results 1 to 2 of 2

Thread: Searching for value in a text file

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Location
    TX
    Posts
    1

    Question

    I am creating a program to save data to a sequential access file and I am able to write data to the file using multiple textboxes. When I save the data to the file, one line of
    text constitutes one record.

    How can I open that file and perform a search for a value, then when it is found, populate the corresponding textboxes?

    Any help is much appreciated!



  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'search for a particular line and do something with it
    'read the file into an array and then back into your file
    'and save it
    
    Option Explicit
    Option Compare Text
    
    Private Sub Form_Load()
    
        Dim myLine As String
        Dim myComp As String
        Dim intNum As Integer
        
        myComp = "The line I am Looking for"
        intNum = FreeFile
    '
    'open file
        Open "C:\myfile.txt" For Input As intNum
        
       Do While Not EOF(intNum)
                 
            Line Input #intNum, myLine
            If Trim(myLine) = Trim(myComp) Then
              ' a match is found
              'do whatever your want to do here
              text1.Text = myLine  'send the line to a textbox
            End If
            
        Loop
            Close #intNum
    
     End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width