Click to See Complete Forum and Search --> : The Last Word.
nmretd
Dec 7th, 1999, 09:08 PM
How can I search a file and extract the last word from this file and read it into a variable.
Aaron Young
Dec 8th, 1999, 12:30 AM
Use Get and Open the File for Binary Access, then you can Skip right to the end of the File, eg..
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
aarony@redwingsoftware.com
adyoung@win.bright.net
Serge
Dec 8th, 1999, 12:32 AM
Oops, I deleted the last post 'cause you already got the response from Aaron.
------------------
Serge
Software Developer
Serge_Dymkov@vertexinc.com
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)
[This message has been edited by Serge (edited 12-08-1999).]
jkurpias
Dec 8th, 1999, 12:33 AM
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, " "))
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.