Results 1 to 4 of 4

Thread: The Last Word.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 1999
    Location
    London, England
    Posts
    213

    Post

    How can I search a file and extract the last word from this file and read it into a variable.


  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Use Get and Open the File for Binary Access, then you can Skip right to the end of the File, eg..
    Code:
    Private Sub Command1_Click()
        Dim iFile As Integer
        Dim sBuff As String
        Dim iPos As Integer
        
        iFile = FreeFile
        sBuff = Space(255)
        Open "C:\File.txt" For Binary Access Read As iFile
            Get #iFile, LOF(iFile) - 255, sBuff
        Close iFile
        sBuff = Trim(sBuff)
        While InStr(iPos + 1, sBuff, " ")
            iPos = InStr(iPos + 1, sBuff, " ")
        Wend
        'Display Last Word In the Caption
        Caption = Mid$(sBuff, iPos)
    End Sub
    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  3. #3
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Oops, I deleted the last post 'cause you already got the response from Aaron.
    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]
    ICQ#: 51055819



    [This message has been edited by Serge (edited 12-08-1999).]

  4. #4
    Lively Member
    Join Date
    May 1999
    Location
    Vancouver, BC, Canada
    Posts
    84

    Post

    Dim myString As String
    'load myString with the file...for this 'example, I just used some text:
    myString = "Basically Visually Impaired. "
    'remove extra spaces:
    myString = Trim(myString)
    'remove final period:
    myString = IIf(Right$(myString, 1) = ".", Left$(myString, Len(myString) - 1),_ myString)
    'get last word:
    Label1 = Right$(myString, Len(myString)_
    - InStrRev(myString, " "))

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