I’m making a very simple game application. The main form (Form1) has a single button on it labeled Button1. (very creative naming, eh?) The point of the application is to move the button in random directions across the form. My problem is that when I start debugging (I’m using Visual Studio 2010) the form never shows up, and when I open Windows Task Manager the name of my .exe never shows up in the process list. I was wondering if the code I’m using would have something to do with that. Here’s my code:
Class Form1
Private Sub Form1_Load(...)
InitializeComponent()
While True
MoveIt()
End While
End Sub
Sub MoveIt()
Dim rand As Short
Randomize()
rand = (Rnd() * 5)
Select Case rand
Case 0
'move button up 5px
Button1.Top -= 5
Case 1
'move button up 5px
Button1.Top -= 5
Case 2
'move button left 5px
Button1.Left -= 5
Case 3
'move button right 5px
Button1.Left += 5
Case 4
'move button down 5px
Button1.Top += 5
Case 5
'move button down 5px
Button1.Top += 5
End Select
End Sub
End Class
Yes, your code has something to do with this. You have an endless
Whileloop in your form’sLoadevent, which means theLoadevent never returns, which means your form basically never finishes loading.Instead of calling this from your
Loadevent, trigger the start of the random-button-movement process by usingBeginInvokefrom yourLoadevent:http://msdn.microsoft.com/en-us/library/a06c0dc2.aspx