VB School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB Expert!

Join 300,574 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,197 people online right now. Registration is fast and FREE... Join Now!




Save Text Box Data at Timed Intervals

 

Save Text Box Data at Timed Intervals

callumogrady

26 Jun, 2009 - 04:52 AM
Post #1

New D.I.C Head
*

Joined: 26 Jun, 2009
Posts: 2

Hey guys. I kind of need some help with a code. I want the data in my text box to save to a file at intervals of say 30000 ( 30 secs ). I don't want it to overwrite the other data on the file ( That was saved the previous 30 secs ), but add onto it to create one big log. How can I make this code do that?

Any help is much appreciated (:

CODE
Private Sub Form_Load()
On Error Resume Next
Dim TextValue
Open "C:\Values.ini" For Input As #1
Input #1, TextValue: Text1.Text = TextValue
Close #1
End Sub

Private Sub Form_Unload(Cancel As Integer)
Open "C:\Values.ini" For Output As #1
Print #1, Text1.Text
Close #1
End Sub


User is offlineProfile CardPM
+Quote Post


Fib

RE: Save Text Box Data At Timed Intervals

26 Jun, 2009 - 09:47 AM
Post #2

D.I.C Head
**

Joined: 12 Mar, 2009
Posts: 71



Thanked: 6 times
My Contributions
Hi callumogrady

First off you will need to place a timer control somewhere on your form(it doesn't matter because it won't be visible on runtime).

Then set the interval property of the timer to 30000. Then in your timer's Timer event, place this code:

CODE

    Dim fileNum As Integer
    fileNum = FreeFile

    Open "C:\Values.ini" For Append As #fileNum
    Print #fileNum, Text1.Text
    Close #fileNum


Text1 is your textbox. If you have it named differently, you will need to change that in the code.

I hope this helps!!

User is offlineProfile CardPM
+Quote Post

zippp

RE: Save Text Box Data At Timed Intervals

26 Jun, 2009 - 09:57 PM
Post #3

New D.I.C Head
*

Joined: 22 Jun, 2009
Posts: 39



Thanked: 4 times
My Contributions
yeah Fib, he can do like this, but he will overwrite the previous file. And i have an idea on how to saved it without overwrite.

Ok, you really need a timer and what Fib said before me.
You need to read from the file you want to saved to, and to write to it. why? cuz like that you won't overwrite it.

exemple: your file is fish.txt
your important textbox is textbox1

in the timer section, if the timer is 29 secounds, then you check for file existing and open it in a HIDDED textbox2.

then, when the timer is 30 secounds, you saved the textbox2+textbox1 (this is the order) , then clear the textbox2, and clear the textbox1.


what are you actualy going to do? you open the previous saved text, add some text to it and save it again. i think it's very easy to do it.

ps: this method isn't tested. it's just from my imagination.smile.gif
User is offlineProfile CardPM
+Quote Post

callumogrady

RE: Save Text Box Data At Timed Intervals

26 Jun, 2009 - 11:04 PM
Post #4

New D.I.C Head
*

Joined: 26 Jun, 2009
Posts: 2

Here is what i used for my project. It works fantastically. And it dosen't overwrite the previous file. It just keeps adding on to it.

Timer2 is set to an interval of 30000
Timer3 is set to an interval of 30001

That means it saves the data in the text box every 30 seconds and just after that it wipes the text box and you start again. It saves the data line by line (:


CODE
Private Sub Timer2_Timer()
Dim mytext As String
mytext = Text1.Text
Open "\myfile.txt" For Append As #1
Write #1, mytext
Close #1
End Sub

Private Sub Timer3_Timer()
Text1.Text = " "
End Sub

User is offlineProfile CardPM
+Quote Post

zippp

RE: Save Text Box Data At Timed Intervals

26 Jun, 2009 - 11:58 PM
Post #5

New D.I.C Head
*

Joined: 22 Jun, 2009
Posts: 39



Thanked: 4 times
My Contributions
good work smile.gif

my idea is way more difficult. i didn't thought at this one smile.gif
the String makes all the job:)

This post has been edited by zippp: 27 Jun, 2009 - 12:00 AM
User is offlineProfile CardPM
+Quote Post

vb5prgrmr

RE: Save Text Box Data At Timed Intervals

27 Jun, 2009 - 06:40 PM
Post #6

D.I.C Regular
***

Joined: 21 Mar, 2009
Posts: 459



Thanked: 30 times
My Contributions
QUOTE(callumogrady @ 26 Jun, 2009 - 11:04 PM) *

Here is what i used for my project. It works fantastically. And it dosen't overwrite the previous file. It just keeps adding on to it.

Timer2 is set to an interval of 30000
Timer3 is set to an interval of 30001

That means it saves the data in the text box every 30 seconds and just after that it wipes the text box and you start again. It saves the data line by line (:


CODE
Private Sub Timer2_Timer()
Dim mytext As String
mytext = Text1.Text
Open "\myfile.txt" For Append As #1
Write #1, mytext
Close #1
End Sub

Private Sub Timer3_Timer()
Text1.Text = " "
End Sub


Why???
CODE
Private Sub Timer2_Timer()
Open "\myfile.txt" For Append As #1
Write #1, Text1.Text
Close #1
End Sub
Text1.Text = ""
End Sub


This post has been edited by vb5prgrmr: 27 Jun, 2009 - 06:41 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 08:12AM

Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month