CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Oct 2001
    Posts
    11

    Timer control problem

    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



  2. #2
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    78

    Re: Timer control problem

    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


  3. #3
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Timer control problem

    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

  4. #4
    Join Date
    Oct 2001
    Posts
    11

    Re: Timer control problem

    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



  5. #5
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Timer control problem

    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

  6. #6
    Join Date
    Oct 2001
    Posts
    11

    Re: Timer control problem

    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


  7. #7
    Join Date
    Sep 2000
    Location
    Sweden
    Posts
    14

    Re: Timer control problem

    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


  8. #8
    tdeltax Guest

    Re: Timer control problem

    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


  9. #9
    Join Date
    Oct 2001
    Posts
    55

    Re: Timer control problem

    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


  10. #10
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Timer control problem

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured