Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Please Help -- Data logger on text (.txt) file

Hi :SICK:

\/ VB 6 \/

i have a textbox(txtlog) and a bottun(cmdsave):

i need a code that when i pressed bottun(cmdsave) save text from
textbox(txtlog) to a text file(log.txt) and every time when i pressed
bottun make a new line and save the new entry and when the text
file(log.txt) reached to 50kb then start loging in other file like (log1.txt)

i am begginer and this writing something like this is so hard :SICK: for me
please help me with a code on VB6.

thanks so much :WAVE:
[546 byte] By [x-pc] at [2007-11-11 10:30:57]
# 1 Re: Please Help -- Data logger on text (.txt) file
First the general formula for writing in a file is :

open file for output as #1 'open the "file" for outputing in it
print #1, txtlog 'writing in it the txtlog container
close #1 'closing the file -important-

each calling for it will print in a new line the txtlog , for checking the size of the file, you may use the function "filelen()" and make an "if" check after each "print" and to know if it must change the "file" or nop .
Amahdy at 2007-11-11 17:22:40 >
# 2 Re: Please Help -- Data logger on text (.txt) file
i use this code but a problem is that this code are deleting previous logs
for example:
when i write [Hello] in text box and hit the bottun it saves in log.txt
but for second time when i write [How Are U] in text box and hit the bottun
[How Are U] replaced with [Hello]
but i want a code that every time i enter a diffrent things in text box
it make a new line under previous records and add new text

and when the log reaches to for example 50kb it automaticlly make new
.txt file (example: old log = log.txt new generated log = log1.txt )
and automaticlly fix the log file path to new log.
x-pc at 2007-11-11 17:23:40 >
# 3 Re: Please Help -- Data logger on text (.txt) file
open file for append as #1

about the new log, as told u before, use the filelen() function to check if the file size is 50 or not yet, for example
if filelen(file) = 51200 then Write_In_New_File() else Write_In(file) ...
Amahdy at 2007-11-11 17:24:38 >
# 4 Re: Please Help -- Data logger on text (.txt) file
thanks

but what about log file writing problem?
x-pc at 2007-11-11 17:25:35 >
# 5 Re: Please Help -- Data logger on text (.txt) file
yea I told you, open it for appending data like this :

"open file for append as #1"

instead of this:

"open file for output as #1"
Amahdy at 2007-11-11 17:26:34 >