Results 1 to 6 of 6

Thread: delay/timer function?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2011
    Posts
    15

    delay/timer function?

    Hi!

    i want to do this with the delay of in interval with the loop of 10 times.

    for n=0 to 10
    label.text="0"
    time delay of 1 second
    label1.text="1"
    end loop

    But when i m using executing the loop completes it iterations and timer just show work in last iteration.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: delay/timer function?

    Add a timer component to the form, set the interval to 1000. That will do the timing, but you will need to change the logic. Whenever the timer runs down it raises the tick event, so you won't have your loop in one place the way you currently do. Instead, have a counter variable (an integer) at form scope. In the timer tick event, increment that counter and check whether it is 10. If it is, disable the timer. As long as it is not 10, change your labels accordingly.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2011
    Posts
    15

    Re: delay/timer function?

    i want to run the timer again and again for 10 times.

  4. #4
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: delay/timer function?

    You already mentioned that, what you mean is that you want to run your code 10 times. As already explained a timer runs every second, you control how many times it runs by stopping and starting it. There is another method, but unless you want the side effects I would use SH suggestion first.

  5. #5
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: delay/timer function?

    1. Add a timer to your form. Set the interval to 1000, enabled to true.
    2. Double click on the timer you've just added to the form. This will create a Timer.Tick event handler for you in code. You then paste this inside that sub:
    Code:
    Static counter as integer = 0
    'Display the current value of counter
    Label1.Text = counter.ToString()
    'Increment counter by 1
    counter += 1
    'Reset counter back to 0 if it's > 10
    If counter > 10 then 
       counter = 0
    End If
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2011
    Posts
    15

    Re: delay/timer function?

    now got the concept. thanks. i was think to repeat the timer with the loop.

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