Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 08-26-2006, 01:45 PM   #1 (permalink)
 
Junior Techie

Join Date: May 2005

Posts: 66

dingdong-man

Default VB.nET Timer control

again , in my assignment, i'm required to move objects within 5 seconds in a certain places. so everysecond during the 5 second they are movin' in an exact places. is it correct to do this by making the 'select case' conditional for timer1.interval ??

Select Case Timer1.Interval
Case 1000
object.Left = 60
object.Top = 100
Case 2000
object.Left = 80
object.Top = 120
Case 3000
object.Left = 100
object.Top = 140
.
.
.
.
and so on....

or is there any other better idea? because this actually make the program too long to look at.

thanks...
dingdong-man is offline  
Old 08-26-2006, 05:51 PM   #2 (permalink)
 
Newb Techie

Join Date: Jul 2006

Posts: 34

The Future

Send a message via AIM to The Future
Default

If I understand what you're doing, you want to move an object gradually every second over a 5 second period in the same linear direction. If so, using a Select Case on the Interval property of the Timer object is not the going to work. The interval is constant and doesn't change.

I would suggesting setting the interval to 1000 (which is in milliseconds, equalling 1 second), and then every time the timer executes, add code to increase the Object's Left property by 20 and Top property by 25 or whatever you would like to do.

If I misunderstood your question, could you please rephrase it?
The Future is offline  
Old 08-26-2006, 10:53 PM   #3 (permalink)
 
Junior Techie

Join Date: May 2005

Posts: 66

dingdong-man

Default

thnx for your comment, but actually it doesn't need to be in linear direction, so adding the "left" properties to the object might not be used permanently.

i made some changes in the method, but it seems to be more complicated than before.

look... i declare another variable, called 'object counter'
and i've set the timer interval to 1000, and i have it like this:

Timer1_Tick
Dim object_counter As Integer
Timer1.Interval = 1000
object_counter += 1

Select Case object_counter
Case 1
object.Left = 60
object.Top = 100
Case 2
object.Left = 80
object.Top = 120
Case 3
object.Left = 100
object.Top = 140

but do you guys think it's more complicated than before.... bcoz it's just added another variable and then did the same thing..
if i set the interval to be 5000, why isn't it going to happen? because interval move from 0 to 5000 within 5 seconds right?

please recorrect my understanding if i'm wrong

i can't think any other better....
thnx..
dingdong-man is offline  
Old 08-28-2006, 10:24 AM   #4 (permalink)
 
Newb Techie

Join Date: Jul 2006

Posts: 34

The Future

Send a message via AIM to The Future
Default

I believe your confusion arises with the Interval property. When you set the property to any number, say 5000 milliseconds, that means that the code in the Timer_tick() method will execute every 5 seconds. That's all. To the best of my knowledge, the interval is not stored in a variable that counts up to 5000 to back from 0 to 5000 again.
The Future is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On