Results 1 to 9 of 9

Thread: Text file.

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 1999
    Posts
    8

    Question

    Hi all,

    Sometime ago I asked here how to present a text file that I read on a form. I got an answer that suggested me simply to use a text box control.
    Problem is that I read that file in a loop. something like:
    While (NOT EOF)

    read....
    Textbox1.text = read_str

    Wend

    now each line erase the other and I can not display the whole file.

    How to avoid it?
    Should I use a different control? which one?

    Thanks.

  2. #2
    Lively Member
    Join Date
    Oct 2000
    Location
    Singapore
    Posts
    98
    Try enabling multiline for the textbox.

    btw, isn't there a limit for the number of characters u can place in a string?


  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    A string character limit is s^31 that's 2 gigabyte so that's not the problem but a textbox character limit is 65536 byte + that nullchars will cut off the rest of the text.

    Use & operater to add up strings instead of overwriting it again and again.

    Don't read a file line by line, open in binary and get the whole file in one chunk:

    Code:
    Dim buffer as string
    Open file for binary as #1
        buffer=space(lof(1))
        Get#1,,buffer
    close #1
    'now if that text file is smaller than 65536 bytes then you could put it in a textbox else put it in a richtextbox or leave it in the string.
    TExt1=buffer
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 1999
    Posts
    8
    I did try the multiline property, but it did not help.
    And as for the limit, I limit the string that I read for 200 chars and it works OK.

  5. #5
    New Member
    Join Date
    Mar 2000
    Posts
    13
    You have to add the string to the textbox, like this:

    Text1.text = Text1.text + read_str

    if you want to do it line by line.
    /Tote
    VB6 SP4

  6. #6
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    If you decide to use Line Input, use this

    Code:
    Text1.text = Text1.text & read_str 
    
    'Because if:
    'text.text = 4
    'readstr = 4 
    'it will result in
    'Text1.Text = 44
    instead of this
    Code:
    Text1.text = Text1.text + read_str 
    
    'Because if:
    'text.text = 4
    'readstr = 4 
    'it will result in
    'Text1.Text = 8 < not what we want huh?
    Get why?
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  7. #7
    New Member
    Join Date
    Mar 2000
    Posts
    13
    Sorry, I meant & and not +.
    But + will work if it's only text...


    [Edited by Tote on 10-15-2000 at 10:14 AM]
    /Tote
    VB6 SP4

  8. #8
    Guest
    Use the following method instead of Line Input.
    Code:
    Open "MyTextFile.txt" For Input As #1
    Text1 = Input(LOF(1), 1)
    Close #1

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Should have known this, if you post something then everyone comes with their own suggestion, well hope you don't choose one of the "adding upp strings"-solutions
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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