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.

picTax.Cls<br />

picTax.Print “Your FICA taxes for the current”<br />

picTax.Print “pay period are “; FormatCurrency(FicaTaxes)<br />

End Sub<br />

Private Function FICA(ytdEarnings As Single, curEarnings As Single) As Single<br />

Dim socialSecurityBenTax As Single, medicare As Single<br />

‘Calculate Social Security benefits tax <strong>and</strong> Medicare tax<br />

‘for a single pay period in 1999<br />

socialSecurityBenTax = 0<br />

If (ytdEarnings + curEarnings) Val(txtSecondNum.Text) Then<br />

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

Else<br />

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

End If<br />

However, because indenting improves the readability of the block, it is regarded<br />

as good programming style. As soon as you see the word If, your eyes can<br />

easily scan down the program to find the matching End If <strong>and</strong> the enclosed Else<br />

<strong>and</strong> ElseIf clauses. You then immediately have a good idea of the size <strong>and</strong> complexity<br />

of the block.<br />

2. Constructs in which an If block is contained inside another If block are referred<br />

to as nested If blocks.<br />

3. Care should be taken to make If blocks easy to underst<strong>and</strong>. For instance, in Figure<br />

4.2, the block on the left is difficult to follow <strong>and</strong> should be replaced by the<br />

clearer block on the right.<br />

If Blocks 111

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

Saved successfully!

Ooh no, something went wrong!