Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Visual Basic Programming(Animation moving) Shoot the arrow. Given the form below

ID: 3823755 • Letter: V

Question

Visual Basic Programming(Animation moving)

Shoot the arrow. Given the form below write code which will animate the movement of the arrow from lower left horizontally toward the right until it hits the target at bottom right when the “Shoot Arrow” button is clicked. The arrow will move horizontally only. It will not change its height. It will stop and stay in place when it hits the target. The reset button will reset the arrow back to its starting location at far left.

Off the table: Given the form below write the code necessary to animate the ball (lblBall) such that it moves to the right until it reaches the right edge of the table where it falls to the floor in a diagonal direction. When the ball reaches the floor all motion stops and the ball will come to rest on the floor at bottom right. The reset button resets the ball to its original location on the table. The Go button starts the animation.

Shoot Arrow Reset Quit tmrMove Arrow Archery

Explanation / Answer

'Shoot the Arrow

'first save the starting position of the arrow and the position of the target into global variables on form load

Global StartPosLeft 'the 'left' value of the arrow image will be saved here

Global TargetPos 'position of the target will be saved here

Type this inside the form load subroutine:-

StartPosLeft=imgArrow.Left 'imgArrow is the image of the arrow

'next calculate the position of the target. We need the middle of the target, obtained by subtracting its left from right

TargetPos=imgTarget.Right-imgTarget.Left 'imgTarget is the target image

Type this in the Click() Sub of the Shoot Arrow button

While imgArrow.Left>=TargetPos 'keep moving the arrow image to the left 1 twip at a time until it reaches the 'middle of the target

imgArrow.Left=imgArrow.Left+1

Wend

Type this in the Click() Sub of the Rest button

imgArrow.Left=StartPosLeft 'move the arrow back to its starting position

Off the Table:-

Note:- Assuming that imgTable is the image of the table and iFrame is the container containing the images.

First save the starting position of the ball into a global variable on form load.

Global StartPosLeft 'Left property of lblBall will be stored here on form load

Global StartPosTop 'Top property of lblBall will be stored here on form load

Type this in the form load Sub:-

StartPosLeft=lblBall.Left

StartPosTop=lblBall.Top

Type this in the Click() of the Go button:-

While lblBall.Left<=imgTable.Right 'move the ball to the table's right edge

lblBall.Left=lblBall.Left+1

Wend

'now move the ball diagonally down to the floor

While lblBall.Bottom>iFrame.Bottom

lblBall.Right=lblBall.Right+1

lblBall.Top=lblBall.Top+1

Wend

'then move the ball to the right edge of the container

While lblBall.Right>iFrame.Right

lblBall.Right=lblBall.Right+1

Wend

Type this in the Click() of the Reset button:-

'move the ball back to its starting position

lblBall.Left=StartPosLeft

lblBall.Top=StartPosTop

Hope this helps!