if x is less than zero go right one step
if x is greater than 500 go left one step therefore
if x is between 0 and 500 do nothing
... but it should continue to move in whatever its current direction is.
Think about keeping track of its current direction, moving that way while the ball is in range, and changing the direction when the ball reaches 0 or 500.
If in doubt, write it down in English and run through a few cases on a piece of paper to get the algorithm right before you try to code it in Java.
When people animate things moving around the screen they usually have variables to hold the h & v velocity of the object (that's the amount by which the x and y positions change in each time cycle). So every time cycle its just xPosition = xPosition + xVelocity; (ditto for y)
if xVelocity is (say) +1 the object will move slowly right. If it's -10 the object will move rapidly left.
Does that help?
What do you mean by "one event"? Your terms are unusual.
I guess (I really really hope) he is using a javax.swing.Timer to control this. Swing Timers generate an event every n mSec, which passes an ActionEvent object to your code. So "event" would be the appropriate term in this case.
For Each ctrl As Control In Me.Controls("pnlMainPanel").Controls
If ctrl.GetType Is GetType(System.Windows.Forms.Panel) Then
For Each subCtrl As Control In ctrl.Controls
If subCtrl.GetType Is GetType(System.Windows.Forms.TextBox) Then
If subCtrl.GetType Is ...