Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text file to TextBox

Status
Not open for further replies.

Helen1greece

Technical User
Jun 4, 2003
85
0
0
GR
How is it possible to take text form text file and put it in a TextBox. Can somebody give me an example code without using a RichTextBox?
 
Sure:
Code:
Private Sub Command1_Click()
Dim Buffer As String
Dim F As Integer
Dim FilePath As String
    FilePath = "C:\Some Folder\Another Folder\YourFile.txt"
    F = FreeFile
    Buffer = Space(FileLen(FilePath))
        Open FilePath For Binary As #F
            Get #F, , Buffer
        Close #F
    Text1.Text = Buffer
End Sub
 
or you could add a reference to the Microsocoft Scripting Runtime library, and then use the fractionally shorter:
[tt]
With New FileSystemObject
Text1.Text = .OpenTextFile("C:\test.txt").ReadAll
End With
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top