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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autorefresh with Timer 2

Status
Not open for further replies.

mikeisvfp

Programmer
Mar 5, 2011
91
CA
Im trying to give the user the ability to type in the amount of seconds for the grid to Autorefresh.

what am i doing wrong?

In the Timer Event of the Timer

thisform.timer1.interval = 1000

if !empty(thisform.txtrefresh.value)
thisform.txtrefresh.value = thisform.timer1.interval * thisform.txtrefresh.value
endif
thisform.grdappointment.refresh()


 
Since you don't say what isn't working, and what you show doesn't match your subject, I'm not sure what sort of answer you expect?
 
What is an "autorefresh" and where do you set it?

Note:

* Grids do not have an autorefresh property
* Forms do not have an autorefresh property
* You're not setting any autorefresh property in the code you've posted
* The Class Browser has an autorefresh property, but it doesn't have anything to do with grids or forms

I *think* you're looking for the SET REFRESH command, but it's hard to reach that from what you've posted so far.
 
I totally understand that, but all i am looking for is to refresh my grid every 30 seconds lets say..
And i can do that by simply by using the Timer control,
if i set the interval to 30000, and in the timer event of the timer i place thisfrom.mygrid.refresh() it will refresh my grid every 30 seconds. What I want is to have the user enter there own value as to how many in seconds they want the grid to refresh.

is this possible? if not i will go along with what works
 
You can do that. Put a textbox on the form and in its valid method set the Timer.Interval to Textbox.Value * 1000. This certainly shouldn't involve code inside the timer. The timer's only job is the refresh.

Of course, all that does is cause the grid to repaint with data that may or may not have changed.

If the data hasn't changed/updated calling refresh every second won't update what the grid is displaying. You need SET REFRESH for that (or possibly a Requery() on the data source).

There's far more involved than simply setting a property of a timer.
 
Mike,

You've already got a textbox in which the user enters the number of seconds. You need code in the textbox's LostFocus. The code will set the timer's Interval property to the number that the user enters, multiplied by one thousand.

Then, in the timer's Timer event, you call the grid's Refresh. That's all there is to it.

Your original code is almost there. The problem is that you are multiplying the interval by the value in the textbox, and storing the result back into the textbox, which is not what you want.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
thisform.txtrefresh.value = thisform.timer1.interval * thisform.txtrefresh.value

Why do you change the txtrefresh.value, when you want to change the timer.interval value?

Bye, Olaf.
 
type in the amount of seconds

Are you remembering that the Timer object's interval is in Milliseconds - not Seconds

Code:
* --- Since txtrefresh is supposed to be Seconds units ---
nMillisecs = (ThisForm.TxtRefresh.Value * 1000)  && Get MSecs
ThisForm.Timer1.Interval = nMillisecs

Good Luck,
JRB-Bldr




 
its actually not working, im getting a datatype mismatch
and when i debug it seems txtrefresh.value is not muliplying by 1000

pls help
 
If the data type is coming up as a mismatch, then you should know to test and/or intentionally change the data type.

Code:
* --- Since txtrefresh is supposed to be Seconds units ---
nMillisecs = (VAL(ThisForm.TxtRefresh.Text) * 1000)  && Get MSecs
ThisForm.Timer1.Interval = nMillisecs

Good Luck,
JRB-Bldr
 
nMillisecs = (VAL(ThisForm.TxtRefresh.Text * 1000) && Get MSecs
ThisForm.Timer1.Interval = nMillisecs

I was close, I know that Val() returns numbers in character expressions.

Thank You JRB-Bldr

Mike
 
If you initially set ThisForm.TxtRefresh.Value to 0 or 1, it will be numeric. ThisForm.TxtRefresh.Text of course always is text. Your exression is still wrong, as you can't multiply a text, but that may be a typo, missing a closing paranthesis before the multiplication operator.

Bye, Olaf.
 
Hi Olaf

I was actually just showing what i had tried after reading about VAL() the missing paranthesis is what i was missing.

Thank You once again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top