Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 VB freezes!
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
tupac




PostPosted: Fri Feb 17, 2006 5:51 pm   Post subject: VB freezes!

i got this problem when i try running my pong game i just started. This is the code: <the form includes a cirlce between 2 lines>
Private Sub Form_Load()
Dim dx As Integer
Dim dy As Integer
dx = 5
dy = 5
do
Shape1.Top = Shape1.Top + dx
Shape1.Left = Shape1.Left + dy
loop
end sub

thats the code... i duno wats wrong, cuz if i dont use "do" to loop the program, the circle wont keep traveling the path I gave it... Confused
PLZ help!
Sponsor
Sponsor
Sponsor
sponsor
cool dude




PostPosted: Sat Feb 18, 2006 12:52 pm   Post subject: (No subject)

its called a timer. take away the do loop and put this

code:

Shape1.Top = Shape1.Top + dx
Shape1.Left = Shape1.Left + dy


in your timer. don't forget to put an interval in the properties section for your timer
HazySmoke)345




PostPosted: Tue Feb 21, 2006 8:17 pm   Post subject: (No subject)

The problem is that there is no condition after "do" or "loop", which means, you're asking the computer to do what's between "do" and "loop" forever. There are two ways to solve that problem. One, is like what the person before me said... make a timer... the other one is something like this.
code:
Do
Shape1.Top = Shape1.Top + dx
Shape1.Left = Shape1.Left + dy
DoEvents
Loop


What "DoEvents" does is that it makes the form refresh, in another word, unfreeze itself, but it's not as realiable as a timer, the speed will vary depends on how busy your computer is, but try it out.
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: