Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General / August 2004



Tip: Looking for answers? Try searching our database.

Text Box to read a text fille

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Les - 31 Aug 2004 17:34 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.

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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.