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.

SOLUTION:<br />

In the following program, the condition is Val(txtFirstNum.Text) > Val(txtSecond Num.Text), <strong>and</strong> each<br />

action consists of a single assignment statement. With the input 3 <strong>and</strong> 7, the condition is false, <strong>and</strong> so the<br />

second action is taken.<br />

Object Property Setting<br />

frmMaximum Caption Maximum<br />

lblFirstNum Caption First Number<br />

Alignment Right Justify<br />

txtFirstNum Text (blank)<br />

lblSecondNum Caption Second Number<br />

Alignment Right Justify<br />

txtSecondNum Text (blank)<br />

cmdFindLarger Caption Find Larger Number<br />

picResult<br />

Private Sub cmdFindLarger_Click()<br />

Dim largerNum As Single<br />

picResult.Cls<br />

If Val(txtFirstNum.Text) > Val(txtSecondNum.Text) Then<br />

largerNum = Val(txtFirstNum.Text)<br />

Else<br />

largerNum = Val(txtSecondNum.Text)<br />

End If<br />

picResult.Print “The larger number is”; largerNum<br />

End Sub<br />

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

EXAMPLE 2<br />

Write a program that requests the costs <strong>and</strong> revenue for a company <strong>and</strong> displays the message “Break even”<br />

if the costs <strong>and</strong> revenue are equal or otherwise displays the profit or loss.<br />

SOLUTION:<br />

In the following program, the action following Else is another If block.<br />

Object Property Setting<br />

frm5_2_2 Caption Profit/Loss<br />

lblCosts Caption Costs<br />

Alignment Right justify<br />

txtCosts Text (blank)<br />

lblRev Caption Revenue<br />

Alignment Right justify<br />

txtRev Text (blank)<br />

cmdShow Caption Show Financial Status<br />

picResult<br />

Private Sub cmdShow_Click()<br />

Dim costs As Single, revenue As Single, profit As Single, loss As Single<br />

If Blocks 107

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

Saved successfully!

Ooh no, something went wrong!