-
Aug 9th, 2022, 05:31 AM
#1
Thread Starter
Member
[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
-
Aug 9th, 2022, 05:41 AM
#2
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
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
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
-
Aug 9th, 2022, 06:15 AM
#3
Thread Starter
Member
Re: vb6: save big data from textbox to txt file
Originally Posted by Zvoni
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...
-
Aug 9th, 2022, 06:35 AM
#4
Re: vb6: save big data from textbox to txt file
Originally Posted by vb6s
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
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
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
-
Aug 9th, 2022, 08:51 AM
#5
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
-
Aug 9th, 2022, 09:06 AM
#6
Re: vb6: save big data from textbox to txt file
Originally Posted by techgnome
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
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
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
-
Aug 9th, 2022, 09:12 AM
#7
Thread Starter
Member
Re: vb6: save big data from textbox to txt file
Originally Posted by techgnome
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
-
Aug 9th, 2022, 09:15 AM
#8
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
-
Aug 9th, 2022, 10:02 AM
#9
Thread Starter
Member
Re: vb6: save big data from textbox to txt file
Originally Posted by techgnome
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
-
Aug 9th, 2022, 10:26 AM
#10
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?
-
Aug 9th, 2022, 10:31 AM
#11
Re: [RESOLVED] vb6: save big data from textbox to txt file
Originally Posted by dilettante
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|