Is there a way for me to get specific information from a text file and insert them into specific textboxes? i just need a very simple way since am a newbie at this. Any help would be greatly appreciated. Thanks in advanced
Printable View
Is there a way for me to get specific information from a text file and insert them into specific textboxes? i just need a very simple way since am a newbie at this. Any help would be greatly appreciated. Thanks in advanced
You will have to read it. After you read it, you can parse the string. One easy way to do it is use the Instr function.
How do i read it?Quote:
Originally Posted by RoyK
You can use the built in file manupulation function of VB.
Example:
Dim TextLine
Open "TESTFILE" For Input As #1 ' Open file.
Do While Not EOF(1) ' Loop until end of file.
Line Input #1, TextLine ' Read line into variable.
Debug.Print TextLine ' Print to the Immediate window.
Loop
Close #1 ' Close file
Hope you will be able to find your way.
Regards
Amarjit
Or, check this out. It splits on lines, but you coulld just as easily split on spaces to get words.
Code:Option Explicit
Private Sub Form_Load()
Dim x As Integer, st As String
Dim ff As Integer
Dim strBuff As String
Dim str() As String
ff = FreeFile
Open App.Path & "\to do.txt" For Input As #ff
strBuff = Input(LOF(ff), ff)
Close #ff
' ----------------- two ways to skin a cat --------------
' MsgBox "Lines = " & Len(strBuff) - Len(Replace(strBuff, vbCrLf, "x")) + 1
' -------------------------------------------------------
str() = Split(strBuff, vbCrLf)
MsgBox "There are " & UBound(str) + 1 & " lines in the file"
For x = 0 To UBound(str)
st = st & str(x) & vbCrLf & vbCrLf
Next x
MsgBox st
End Sub
hi
this code will read the text file and disply it in a text box (txtLoadedText)
FilePath = "c:\123.txt"
Open FilePath For Binary As #1
txtLoadedText = Input(LOF(1), 1)
Close #1
YES!!! Just what i needed! Works Perfect! Thanks!!!!Quote:
Originally Posted by dglienna