Click to See Complete Forum and Search --> : Displaying Text inside a txtBox
MitzEclipse
July 5th, 2001, 12:42 PM
Displaying Text inside a txtBox
Does anyone know how to do this? I have already declared a variable, and I just want to dump the contents of the variable (a txt file) into a text box -- and later parse this information.
I've played around with debug.print, but is there a way to dump that data into a text box?
Thanks
dfwade
July 5th, 2001, 01:13 PM
text1.text = YourVariable
MitzEclipse
July 5th, 2001, 01:45 PM
I did that, however, it doesn't work.
The way I have it setup is that there is a cmdButton -- when you click on it it brings up a file open dialog. right now when you double click on the file the text box displays the LOCATION of the file (ie: c:\temp\file.txt)
I would like to figure out how to display the CONTENTS of the text file within that text box.
Thanks
John G Duffy
July 5th, 2001, 02:18 PM
In order to dump the contents of the file into the textbox, you will need to read the records in the file and add them yourself. The CommonDIalog does not read the file it only passes you the path and filename of the user selected file.
Here is code to do this. It's very simple and assumes no errors will take place.
private Sub Command1_Click()
' set your TextBox for ScrollBars = Both
' set your TextBox for Multiline = true
Dim Temp as string
CommonDialog1.ShowOpen
Open CommonDialog1.FileName for input as #1
Text1.Text = "" ' clear out textBox
Do Until EOF(1)
Line input #1, Temp
Text1.Text = Text1.Text & Temp & vbCrLf
Loop
End Sub
John G
dfwade
July 5th, 2001, 02:22 PM
oh, start a new project, add a common dialog box and and a text box then paste this code in. Then add a reference to the microsoft scripting runtime to your project from the project refereneces selection.
public Function DisplayFile(fileName as string) as string
Dim fso as FileSystemObject
Dim ts as TextStream
set fso = new FileSystemObject
If fso.FileExists(fileName) then
set ts = fso.OpenTextFile(fileName, ForReading)
DisplayFile = ts.ReadAll
End If
End Function
private Sub Form_Load()
With CommonDialog1
.ShowOpen
If len(.fileName) > 0 then
Text1 = DisplayFile(.fileName)
End If
End With
End Sub
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.