Results 1 to 10 of 10

Thread: Opening text files

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2000
    Location
    London, UK
    Posts
    145

    Post

    Could anyone please tell me what is the quickest way to open a text-file and get the contents into a textbox?
    I have tried to open it sequential and read it line by line, or character by character, but it takes so much memory and time, I can only open small files (<10 kB)
    Is there a way to open the whole file at once?


    ------------------
    Wilhelm Tunemyr,
    Sweden

    [email protected]

    "Dort, wo man Bücher verbrennt, verbrennt man am Ende auch Menchen"
    Heinrich Heine (1797-1856)

    Pravda zvítezi!

  2. #2
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670

    Post

    You could always use a Rich Text Box - you will need to add the MS RichTextBoxControl to your project via the components window.
    With the Rich Text Box you can do this;

    RichTextBox1.LoadFile "[filename]",1

    to load a plain text file into it.
    I don't know what the limitations are 'cos I never really use the RichText box.



    ------------------
    Mark "Buzby" Beeton
    VB Developer
    [email protected]



  3. #3
    Addicted Member Razzle's Avatar
    Join Date
    Jan 2000
    Location
    Berlin, Germany
    Posts
    161

    Post

    Open filename for Input as #1
    Text1.text = Input(Len(1),1)
    Close #1

    This uses the standard text box

    ------------------
    Razzle
    ICQ#: 31429438

  4. #4
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Post

    I'll admit I use the richtextbox method myself from time to time (as above) but you should try the filesystemobjects in VB6 using text streams and writeall or write line (for list boxes and arrays). documantation is a little scetchy so its best to open projects,references and tick a link to "Scripting" then open the functions in the object browser (F2). Adding a reference saves you having to use set object etc like

    Set fs = CreateObject("Scripting.FileSystemObject")
    Set a = fs.CreateTextFile("c:\testfile.txt", True)
    a.WriteLine("This is a test.")
    a.Close

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2000
    Location
    London, UK
    Posts
    145

    Post

    I tried using RichTextBox, and it works great.
    Thanks!

    ------------------
    Wilhelm Tunemyr,
    Sweden

    [email protected]

    "Dort, wo man Bücher verbrennt, verbrennt man am Ende auch Menchen"
    Heinrich Heine (1797-1856)

    Pravda zvítezi!

  6. #6
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    Post

    Can you save using code this short for a RichTextBox also???


    Steve

  7. #7
    Addicted Member Razzle's Avatar
    Join Date
    Jan 2000
    Location
    Berlin, Germany
    Posts
    161

    Post

    no problem at all.
    Open filename for Output as #1
    Print #1, Text1.text
    Close #1

    ------------------
    Razzle
    ICQ#: 31429438
    What is the difference between a raven?
    -The legs. The length is equal, especially the right one.

  8. #8
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

    Post

    Pentax, du schriebst Menchen anstatt Menschen

    ------------------
    [email protected]
    ...
    Every program can be reduced to one instruction which doesn't work.


  9. #9
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670

    Post

    Or, just use


    RichTextBox1.SaveFile [filename]



    ------------------
    Mark "Buzby" Beeton
    VB Developer
    [email protected]



  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Feb 2000
    Location
    London, UK
    Posts
    145

    Post

    Donnerwetter!
    You mean I have spelled it wrong in all my mails for the last two years, my posts here on vb-world and other places?
    Quite emberassing...
    Anyway, thanks for telling me. I shall get it changed right away.

    ------------------
    Wilhelm Tunemyr,
    Sweden

    [email protected]

    "Dort, wo man Bücher verbrennt, verbrennt man am Ende auch Menschen"
    Heinrich Heine (1797-1856)

    Pravda zvítezi!

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