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!

Open a txt file into a text box? 1

Status
Not open for further replies.

gadget3302

Programmer
Apr 24, 2003
79
0
0
US
Can you load a .txt file into a text box, or something like that? If so how would I go about doing that?
 
gadget3302

Set reference to Microsoft Scripting Runtime Library in your project and run this code making sure you have some C:\MyFile.txt:

Option Explicit

Public myFSO As New Scripting.FileSystemObject

Private Sub Command1_Click()
Dim f As TextStream
Set f = myFSO.OpenTextFile("c:\MyFile.txt", 1)
Text1.Text = f.ReadAll
Set f = Nothing
End Sub


Vladk
 
Not the most elagant, but will work!

Private Sub Form_Load()
Dim fso, finput, strFileAsString
Set fso = CreateObject("Scripting.FileSystemObject")
Set finput = fso_OpenTextFile("C:\...\abc.txt")

Do While (finput.AtEndOfStream <> True)
strFileAsString = finput.ReadLine()
List1.AddItem (strFileAsString)
Loop
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top