(I'm using Vis Studio 2008 and a textbook written for VB2008)
Okay, so this problem from my textbook requires me to "animate" (read: move a picture box) a picture of a "robot" finding it's way to a wall and returning to it's original position. I have the logic of the program itself mostly figured out, but the moving of the picture box is alluding me at the moment. My code is as follows:
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
Dim totalCount As Integer = 0
Dim isTouchingWall As Boolean = False
Dim armsRaised As Boolean = False
Dim isSitting As Boolean = True
'always "stands up" and "raises arms" as first action.
picRobot.Image = My.Resources.robotstand
picRobot.Image = My.Resources.robotstandarmsraised
'moves torwards the "wall", need to check wall touch after every move
While isTouchingWall = False
totalCount = totalCount + 1
makeMove()
isTouchingWall = checkWallTouch(totalCount)
End While
'returns to original position, no need to check for walls, as distance is known
makeReturnTrip()
'always "sits" as last action. "arms are implied to lower"
picRobot.Image = My.Resources.robotsit
End Sub
Sub makeMove()
Static XCor As Integer = picRobot.Left
Static YCor As Integer = picRobot.Top
Static width As Integer = picRobot.Width
Static height As Integer = picRobot.Height
XCor = XCor - 100
If XCor <= -picRobot.Width Then
XCor = Me.Width
End If
picRobot.SetBounds(XCor, YCor, width, height)
Threading.Thread.Sleep(1000)
End Sub
I omitted some of the subs, makeReturnTrip() is empty at the moment, checkWallTouch returns true if the "totalCounter" variable equals a constant called wall (set to 10), false otherwise.
The btnStart sub is the main chunk of programming, and makeMove() is....a mess, more or less it's a result of me cannibalizing examples from my textbook and trying to make them work, as it stands, they do not work, but simply makes the picture box do something like a "shudder dissolve" you would see in some cheaper video editors.
I'm quite out of ideas and the documentation for picturebox (and picturebox.setbounds()) hasn't been helpful.
Any help would be appreciated (oh, and I don't NEED to use picturebox.setbounds, but it would be the preferred method, if my textbook is to be believed)
Edit: Another note, a button with a similar setbound method works, so I'm really not sure why a loop wouldn't.