-
March 19th, 2009, 06:48 PM
#1
Counter and Timer
Hi,
I want to specify the counter for the for next loop to control the animation time
So far i have:
Code:
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
Next
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
-
March 19th, 2009, 10:09 PM
#2
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
Code:
Sub Timer1_Tick .....
Static CycleCounter as long
'Code to do Animation cycle here
CycleCounter=CycleCounter+1
If CycleCounter>30 then
Timer1.Enabled=false
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|