Hi,
I cant seem to remember how to load a text file into a text box. Any help?
I prefer not to have to load the text file into a string with vbCrLf and
etc, just hoping there is a setting that points to the file containing the
text and send it to the text box.
Thanks
Jim Edgar - 31 Aug 2004 17:45 GMT
> Hi,
>
[quoted text clipped - 4 lines]
>
> Thanks
A standard textbox doesn't accept a file name but a rich textbox will accept
.txt and .rtf filenames. A standard textbox needs multiline = true, wordwrap = true and
vertical scrollbars. Then you must open the file and set the text = file contents.
HTH,
Jim Edgar
Bob Butler - 31 Aug 2004 17:50 GMT
> Hi,
>
> I cant seem to remember how to load a text file into a text box. Any
> help? I prefer not to have to load the text file into a string with
> vbCrLf and etc, just hoping there is a setting that points to the
> file containing the text and send it to the text box.
The RichTextBox has a method to load contents from a file; a regular textbox
does not. You have to read the file into a string and then assign that to
the control.

Signature
Reply to the group so all can participate
VB.Net... just say "No"
Ken Halter - 31 Aug 2004 17:56 GMT
> Hi,
>
[quoted text clipped - 4 lines]
>
> Thanks
No need for a string...
'================
Option Explicit
Private Sub Command1_Click()
Call FillBox(Text1, "C:\Temp\Test.txt")
End Sub
Private Sub FillBox(TBox As TextBox, FileName As String)
On Error GoTo ErrorTrap
Dim iFile As Integer
iFile = FreeFile
Open FileName For Input As iFile
TBox.Text = Input$(LOF(iFile), iFile)
Close iFile
Terminate:
Exit Sub
ErrorTrap:
MsgBox "Error " & Err.Number _
& vbCrLf & Err.Description, vbCritical
Debug.Assert False
Resume Terminate
End Sub
'================

Signature
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep all discussions in the groups..
Les - 31 Aug 2004 17:56 GMT
Thank you all I got so wrapped up with the text box I forgot about the
infamous rich text box. I do however find Kens suggestion using a text box
interesting! Does anyone know which method is faster typically?
Thanks
> Hi,
>
[quoted text clipped - 4 lines]
>
> Thanks