Counter and Timer
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2

Thread: Counter and Timer

  1. #1
    Join Date
    Feb 2009

    Post Counter and Timer

    I want to specify the counter for the for next loop to control the animation time

    So far i have:

    Public Class MainForm
      Dim Counter As Integer
     Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
             Counter = 1000
            xCounterTextBox.Text = Counter
            xSpeed = 2
            ySpeed = 2
     X = 216
     Y = 135 
    xButtonLabel.Text = "Button(" & X & "," & Y & ")" 
     Private Sub ForNextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xForNextButton.Click
    For Counter = 0 To 1000
                xTimer.Enabled = True
                xTimer.Interval = 1
    I want the button "Enjoy Button" to move when i click the "For Next button" will this loop...for about 3 seconds...and at a fast speed

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008

    Re: Counter and Timer

    You do not want the interval of your timer set to 1.
    You also do not want to enable it in a loop such as you have.
    What would happen here is the loop would likely run its course before the timer fires the first time.

    Instead what you want to do is set the interval to say 100 for starters. You can always change it if you do not like the speed.
    Enable the timer in your button click.
    Set either a form level variable or a static variable in the timer event. Increment that variable each time the timer cycles and disable the timer when the target number of cycles is reached.

    Kinda like

    Sub Timer1_Tick .....
        Static CycleCounter as long
        'Code to do Animation cycle here
        If CycleCounter>30 then
        End if
    End Sub
    With a interval of 100 the timer will fire 10 times in one second and a total of 30 in 3 seconds. The number should be adjusted based on the timer interval and the lenght of the animation desired.
    Last edited by DataMiser; March 19th, 2009 at 10:12 PM.

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a survey!

HTML5 Development Center