Results 1 to 11 of 11

Thread: [RESOLVED] vb6: save big data from textbox to txt file

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2021
    Posts
    54

    Resolved [RESOLVED] vb6: save big data from textbox to txt file

    i have this code and it saves data from textbox to a text file
    problem is it first open txt file and then write data
    however when text file reaches +1mb, it slows down terribly
    plz help me fix code
    maybe there is a way to save data to text file without opening it

    Code:
    Dim strLine As String
    Dim strAllDogs As String
     
    Open App.Path & "\result.txt" For Input As #1
         While Not EOF(1)
              Line Input #1, strLine
              strAllDogs = strAllDogs & strLine & vbCrLf
         Wend
    Close #1
     
    Open App.Path & "\result.txt" For Output As #1
         Print #1, strAllDogs & Text1.Text
    Close #1

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    3,349

    Re: vb6: save big data from textbox to txt file

    It's probably your loop
    Untested
    Code:
    Dim iFile As Integer
    Dim strAllDogs As String
    iFile = FreeFile
    Open App.Path & "\result.txt" For Input As #iFile
    strAllDogs = Input(LOF(iFile), iFile) 
    Close #iFile
    iFile = FreeFile
    Open App.Path & "\result.txt" For Output As #iFile
    Print #iFile, strAllDogs & vbCrLf & Text1.Text
    Close #iFile
    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2021
    Posts
    54

    Re: vb6: save big data from textbox to txt file

    Quote Originally Posted by Zvoni View Post
    It's probably your loop
    Untested
    Code:
    Dim iFile As Integer
    Dim strAllDogs As String
    iFile = FreeFile
    Open App.Path & "\result.txt" For Input As #iFile
    strAllDogs = Input(LOF(iFile), iFile) 
    Close #iFile
    iFile = FreeFile
    Open App.Path & "\result.txt" For Output As #iFile
    Print #iFile, strAllDogs & vbCrLf & Text1.Text
    Close #iFile
    u were right problem was bcoz of loop
    i tested ur code, it works
    but i counted how long it takes to save. 3 seconds
    wish if could be faster...

  4. #4
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    3,349

    Re: vb6: save big data from textbox to txt file

    Quote Originally Posted by vb6s View Post
    u were right problem was bcoz of loop
    i tested ur code, it works
    but i counted how long it takes to save. 3 seconds
    wish if could be faster...
    Well, not counting algorithm (Loops etc.) , IMO 95% of IO-File-Performance is due to Hardware, as in the "pure" read/write-operation.
    Like: SATA-HDD vs. SSD vs. NVMe
    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  5. #5
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    33,925

    Re: vb6: save big data from textbox to txt file

    If all you're doing is adding text to the end it ... why not just open it For Append and then just write out what is in the text box, close the file... and that should be that.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    3,349

    Re: vb6: save big data from textbox to txt file

    Quote Originally Posted by techgnome View Post
    If all you're doing is adding text to the end it ... why not just open it For Append and then just write out what is in the text box, close the file... and that should be that.


    -tg
    There is that, nevermind opening an existing (!) file for Output implies overwriting it, and maybe this is your time-penalty
    Maybe as a test: Open for Output to a different filename
    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  7. #7

    Thread Starter
    Member
    Join Date
    Dec 2021
    Posts
    54

    Re: vb6: save big data from textbox to txt file

    Quote Originally Posted by techgnome View Post
    If all you're doing is adding text to the end it ... why not just open it For Append and then just write out what is in the text box, close the file... and that should be that.


    -tg
    can u plz help me with code ?
    bcoz i dont know how to do it

  8. #8
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    33,925

    Re: vb6: save big data from textbox to txt file

    All you need to do is google "vb6 open file for append" ... it's not that different from opening a file for output... it just changes where it startsd writing from for output = start from the beginning and overwrite. for append = start from where the end of hte file is and start writing.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9

    Thread Starter
    Member
    Join Date
    Dec 2021
    Posts
    54

    Re: vb6: save big data from textbox to txt file

    Quote Originally Posted by techgnome View Post
    All you need to do is google "vb6 open file for append" ... it's not that different from opening a file for output... it just changes where it startsd writing from for output = start from the beginning and overwrite. for append = start from where the end of hte file is and start writing.

    -tg
    thx so much i found this code and it works instantly without any delay

    'Start append text to file
    Code:
        FileNum = FreeFile
        Open App.Path & "\result.txt" For Append As FileNum
        Print #FileNum, Text1.Text
        Close FileNum
    'End

  10. #10
    PowerPoster
    Join Date
    Feb 2006
    Posts
    23,694

    Re: [RESOLVED] vb6: save big data from textbox to txt file

    How the heck did a TextBox get "big data" in the first place? Did it go to Menards?

  11. #11
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    33,925

    Re: [RESOLVED] vb6: save big data from textbox to txt file

    Quote Originally Posted by dilettante View Post
    How the heck did a TextBox get "big data" in the first place? Did it go to Menards?
    Hahaha... I imagine the "Big Data" was actually the file... not the text box.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

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