|
-
June 30th, 2006, 06:39 PM
#1
[RESOLVED] textfile,...??
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
Last edited by tracer_god; June 30th, 2006 at 06:41 PM.
-
June 30th, 2006, 08:15 PM
#2
Re: textfile,...??
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.
-
June 30th, 2006, 09:32 PM
#3
Re: textfile,...??
 Originally Posted by RoyK
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?
-
June 30th, 2006, 11:59 PM
#4
Re: textfile,...??
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
-
July 1st, 2006, 01:41 AM
#5
Re: textfile,...??
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
-
July 1st, 2006, 03:19 AM
#6
Re: textfile,...??
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
-
July 1st, 2006, 07:21 AM
#7
Re: textfile,...??
 Originally Posted by dglienna
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
YES!!! Just what i needed! Works Perfect! Thanks!!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|