Results 1 to 8 of 8

Thread: Reading a text file into a TextBox

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458
    Hi,
    I need to read-in contents of a text file (Readme file) into a text box on my Help.frm. What would be the right approach? Can anyone help?

    Thanks.
    Thanks

    Tomexx.

  2. #2
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Maybe this code helps you.
    Code:
    Dim oneLine As String 'one line of the file
    'open the file
    Open "c:\myfile.txt" For Input As #1
        'read each line and add it to the textbox
        Do
            'read a line
            Line Input #1,oneLine
            'add it to the textbox
            Text1.Text = Text1.Text & oneLine & VBCRLF
        Loop Until Eof(1)
    'close the file
    Close #1
    Oetje
    [email protected]
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

  3. #3
    Hyperactive Member Asaf_99's Avatar
    Join Date
    Jul 2000
    Location
    Israel
    Posts
    335
    Maybe you should cosider using a RichTextBox control. It does whatever a regular Textbox would do but even better. If your help text file is very long you should use a RichTextBox.
    Code:
    RichTextBox1.LoadFile "C:\MyTxtFile.txt", 1
    Asaf Sagi

    ICQ: 61917199
    E-Mail: [email protected]

  4. #4
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    The size limit of a textbox is 64 KB, so I don't think you need a richtextbox. But a richtextbox also supports formatting.
    Oetje
    [email protected]
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

  5. #5
    Guest
    The RTF Box uses up a lot more resources than a standard Textbox.

    Here is a faster way of loading the file. (using a standard TextBox)
    Code:
    Open "MyFile.txt" For Input As #1
    Text1 = Input(LOF(1), 1)
    Close #1

  6. #6
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604
    well, what is the limit in size for a rtb?


    Wengang
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    The limit for a RTF box is the virtual memory that Windows has assigned your program.
    That is it doesn't have a limit other than the RAM.

  8. #8
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604
    thanks
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width