19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

90 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

Object Property Setting<br />

frm4_3_3 Caption Right Triangle<br />

lblSideOne Caption Length of one side<br />

txtSideOne Text (blank)<br />

lblSideTwo Caption Length of other side<br />

txtSideTwo Text (blank)<br />

cmdCalculate Caption Calculate Hypotenuse<br />

lblHyp Caption Length of hypotenuse<br />

picHyp<br />

Private Sub cmdCalculate_Click()<br />

Dim a As Single, b As Single<br />

‘Calculate length of the hypotenuse of a right triangle<br />

a = Val(txtSideOne.Text)<br />

b = Val(txtSideTwo.Text)<br />

picHyp.Cls<br />

picHyp.Print Hypotenuse(a, b)<br />

End Sub<br />

Private Function Hypotenuse(a As Single, b As Single) As Single<br />

‘Calculate the hypotenuse of a right triangle<br />

‘having sides of lengths a <strong>and</strong> b<br />

Hypotenuse = Sqr(a ^ 2 + b ^ 2)<br />

End Function<br />

[Run, type 3 <strong>and</strong> 4 into the text boxes, <strong>and</strong> then click the comm<strong>and</strong> button.]<br />

EXAMPLE 4<br />

The following program uses the future value function. With the responses shown, the program computes<br />

the balance in a savings account when $100 is deposited for 5 years at 4% interest compounded quarterly.<br />

Interest is earned 4 times per year at the rate of 1% per interest period. There will be 4 * 5 or interest<br />

periods.<br />

Object Property Setting<br />

frm4_3_4 Caption Bank Deposit<br />

lblAmount Caption Amount of bank deposit<br />

txtAmount Text (blank)<br />

lblRate Caption Annual rate of interest<br />

txtRate Text (blank)<br />

lblNumComp Caption Number of times interest is<br />

compounded per year<br />

txtNumComp Text (blank)<br />

lblNumYrs Caption Number of years<br />

txtNumYrs Text (blank)<br />

cmdCompute Caption Compute Balance<br />

lblBalance Caption Balance<br />

picBalance

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!