Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to insert into table using timer.... 1

Status
Not open for further replies.

Mandy_crw

Programmer
Jul 23, 2020
578
PH
Hi expert... if i may ask help please.... my app is already working fine... i just want to add a little feature... I have a database in my server, then i have to client computers... What i what to do is from the two client will insert data into the database in the server, then from time to time the server checks whether there are data input from the two client... like every minute checks new records added, or after two minutes or five minutes... the insertion of record is already done, but i dont know to check automatically if there are records inserted... thanks in advance...
 
If you USE a table, and users add to it, the new records will also be available to other users. Without any timer.

If you query the data, then you want to update, that's true. I rarely do something to synchronize data for a user, because they use several forms in the work process and when starting a specific form it gets the latest data as it does a new query anyway.

But if you want to give it a try, you could have picked up already how to use a timer from the examples on detecting the idle state of your application.

Before I post any code, what is your situation about that data? Do you have the DBFs in your forms dataenvironments, do you use views, queries, in short it matters what you display with how to refresh it. It could be as simple as doing a form.refresh(), it could need requeries, literally of the views or just in the sense of redoing the queries you did to get your data for display.

Chriss
 
Yes Chriss i tried actually looking and doing some codes on the examples in detecting idle state... but so sorry i cannot come up with my intended function...

I have maindatabase that accepts data from two computers... a form uses that maindatabase to display thru grid the data appended by the two computer... i have no problem with these Chris... i have done it... my problem now is, i want to check how many data were appended everyminute, and automatically, so that i can show thru a messagebox how many records were added by client cmputer #1 and added by client computer #2, though i think i can do how to display thru messagebox, i dont know how to write the code to autmatically show it every minute... thnks...
 
Hi Mandy,

Unless I'm not understanding, I think the Timer control's Timer Event & Interval Property are all you need (see Help).

In the Timer event (as a procedure in your app), you can analyze the data how you want and send the appropriate message(s) to your user(s). It will fire every xxx milliseconds as you set in Interval.

Steve
 
Mandy,

to do something repeatedly with the timer is how it works, just don't disable it. A timer repeats its Timer() event every Interval milliseconds.

A Messagebox is not the best idea, as it just disturbs users, just display the information you want to display somewhere. Like in a label in the corner of your form, or use SET MESSAGE to display it in the status bar. Depends on how important that information is for you or your users. It doesn't change that a timer simply repeats what it does.

So again, you just need a timer for it, a timer that stays active. Here's a little example of a timer displaying the time, for simplicity:

Code:
Thisform.AddObject('TimeTimer1','TimeTimer')

With this class definition:
Code:
Define Class TimeTimer as Timer
    Interval=1000 && every second
    oLabel = .null.

    Procedure Init()
        _screen.ActiveForm.AddObject('lblTime','Label')
        This.oLabel = _screen.ActiveForm.lblTime
        This.oLabel.Visible = .t.
    Endproc

    Procedure Timer()   
       This.oLabel.Caption = Transform(DateTime())
    Endproc
Enddefine

Using this as is, you get a label with default font and size that will be at top,left=0 in the top left corner of the form and display the time.

You can also, instead of defining a class, just use the Timer control, it's simply in the toolbar of VFP controls. Add one to the form design and then program it's Timer event. The only difference is that this isn't a reusable class, it's just the native basis timer VFP has programmed directly on the form.

Regarding your need, I misunderstood your goal was to just refresh the displayed data of the form to show what was inserted in the past minute or so.

If you want to display how many records were appended, well, you store how large the dbf or its reccount is and then subtract that from the next size or reccount and you can display that.

If you'd like to observe any changes to any dbf of a database DBC, then you'll need to store a lot of values to compare with each time. I don't know how detailed you want this. If you just want to observe the reccount of one DBF, well, then just set the caption or message to that.

Chriss
 
Just by the way: Your thread title is misleading, as if you're asking how to use a timer to insert data. That's surely not what you ask. You said - and I understood it the first time - the inserting of data is already done.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top