Click to See Complete Forum and Search --> : Timer control problem


muppaneni
October 18th, 2001, 02:19 PM
HI,
I am having the following problem in Visual Basic, Can any one please suggest a solution.
The problem is:
I am presenting a list of words one at a time, on the screen at a specific interval(say 1 sec) of time using the timer.
Now i need to make a little change to it,i need to introduce a 0.5 s interval between the successive words.

That is the whole process goes as follows...
present:
word1 ---presented for 1 sec, immediately followed by the next word after this word
word2---again presented for 1 sec and so on.

what i need:
word1 presented for 1 sec
0.5sec interval(no word appears during this interval)

word2 presented for 1 sec
0.5 sec interval(no word appears during this interval)
word3 presented and so on..

I would greatly appreciate your suggestions,
Thanks
Vasu

Raptors Fan
October 18th, 2001, 03:16 PM
Hi,

What about having the timer interval to .5 secs, then have your code do the following for each interval:

interval action
-------- ------
1 Display First Word
2 Display previous again or just do nothing
3 Display nothing
4 Display Next Word
5 etc.

Just an idea,

RF

John G Duffy
October 18th, 2001, 07:01 PM
Set your timer for .5 sec then use a boolean switch to show word or show nothing in the Timer Event.

private Sub Timer1_Timer()
static blSwitch as Boolean
If blSwitch then
Label1.Caption = "Hello There"
else
Label1.Caption = "nothing here"
End If
blSwitch = Not blSwitch
End Sub




John G

muppaneni
October 18th, 2001, 07:37 PM
HI,
Thanks for the suggestion.
I am not dealing with the exact timings of 1 sec and 0.5 sec,my problem is they will be varying.
Say for example the user of the program can choose the intervals to be 2 sec(for displaying the word) and 0.25 sec(as the interval between the words), and so on.
I would be greatful if you can suggest a solution.
Thanks
vasu

John G Duffy
October 18th, 2001, 08:19 PM
You can set the timer interval to whatever you want. It is specified in the Interval property and can ve altered at run time like so

Timer1.Interval = 200



Where the number is milliseconds. 1/2 second would be 500 milliseconds. One second would be 1000.

John G

muppaneni
October 18th, 2001, 08:35 PM
HI
Thanks for the reply,
But i guess i failed miserably in explaining my problem, sorry for my miserable english.
Let me try to explain the problem again,
I need to display a word and then a time interval during which no word will be presented.
say suppose the word is to appear for 1500 ms and
no word for 53ms,
followed by another word for 1500ms and no word for 53 ms and so on.

If understood correctly, the code you sent to me will be very useful if the 2 intervals are equal, or if the fraction is exactly a integer(which may not be the case for me)

I can set the timer interval at runtime but could not understand how to manage these 2 timers(incase if i use) with precision.

so the process should go like this
word presented for 1500 ms
no word for 53ms
word presented for 1500ms
no word for 53 ms
and so on.

Thanks for your patience and help,
Vasu

Xplorer
October 19th, 2001, 02:03 AM
Hi,

If you combine the previous answers you would get something like this I believe:

private blnShowText as Boolean

private Sub Form_Load()
Label1.Caption = "Insert word here"
Timer1.Interval = 1500
Timer1.Enabled = true
blnShowText = false
End Sub

private Sub Timer1_Timer()
If (blnShowText) then
Label1.Caption = "Insert next word here"
Timer1.Interval = 1500
else
Label1.Caption = ""
Timer1.Interval = 53
End If

blnShowText = Not blnShowText
End Sub



This will show text for 1500 ms and show nothing for 53 ms.

/Xplorer

tdeltax
October 19th, 2001, 06:13 AM
u can use two timer with which r enabled and disabled in the timer events of the each other. set the interval of one time to 1 s and the other to 0.5 s

tdeltax
October 19th, 2001, 06:13 AM
u can use two timer with which r enabled and disabled in the timer events of the each other. set the interval of one time to 1 s and the other to 0.5 s

John G Duffy
October 19th, 2001, 08:22 AM
Here is an example using two different intervals. The chosen intervals and displayed data are used only to show the effects. YOu can set the interval and data to whatever you chose

option Explicit

private Sub Form_Load()
Timer1.Interval = 3000
Timer1.Enabled = true
End Sub

private Sub Timer1_Timer()
static blTimer as Boolean
If blTimer then
Timer1.Interval = 10000
Label1.Caption = "Interval set at 10 seconds"
else
Timer1.Interval = 2000
Label1.Caption = "interval set at 2 seconds"

End If
blTimer = Not blTimer
End Sub



ps. Your english is quite good. I have heard a lot worse from Born and Bred in the USA

John G