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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

costs = Val(txtCosts.Text) revenue = Val(txtRev.Text)<br />

picResult.Cls If costs = revenue Then picResult.Print “Break even”<br />

Else<br />

If costs < revenue Then<br />

profit = revenue - costs<br />

picResult.Print “Profit is “; FormatCurrency(profit)<br />

Else<br />

loss = costs - revenue<br />

picResult.Print “Loss is “; FormatCurrency(loss)<br />

End If<br />

End If<br />

End Sub<br />

[Run, type 9500 <strong>and</strong> 8000 into the text boxes, <strong>and</strong> press the comm<strong>and</strong> button.]<br />

EXAMPLE 3<br />

The If block in the following program has a logical operator in its condition<br />

Object Property Setting<br />

frmQuiz Caption A Quiz<br />

lblQuestion Caption How many gallons does<br />

a ten-gallon hat hold?<br />

txtAnswer Text (blank)<br />

cmdEvaluate Caption Evaluate Answer<br />

picSolution<br />

Private Sub cmdEvaluate_Click()<br />

Dim answer As Single ‘Evaluate answer picSolution.Cls<br />

answer = Val(txtAnswer.Text)<br />

If (answer >= .5) And (answer

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

Saved successfully!

Ooh no, something went wrong!