Guaranteed Hits to your web site!












Learn Visual Basic 6.0


2. The Visual Basic Language


Visual Basic Branching - If Statements

  1. Branching statements are used to cause certain actions within a program if a certain condition is met.

  2. The simplest is the If/Then statement:
    Here, if and only if Balance - Check is less than zero, the statement "You are overdrawn" is printed.

  3. You can also have If/Then/End If blocks to allow multiple statements:
    In this case, if Balance - Check is less than zero, two lines of information are printed.

  4. Or, If/Then/Else/End If blocks:
    Here, the same two lines are printed if you are overdrawn (Balance - Check < 0), but, if you are not overdrawn (Else), your new Balance is computed.

  5. Or, we can add the ElseIf statement:
    Now, one more condition is added. If your Balance equals the Check amount (ElseIf Balance - Check = 0), a different message appears.

  6. In using branching statements, make sure you consider all viable possibilities in the If/Else/End If structure. Also, be aware that each If and ElseIf in a block is tested sequentially. The first time an If test is met, the code associated with that condition is executed and the If block is exited. If a later condition is also True, it will never be considered.


Pen Line


Counter Hit Counter Hit


This Homepage is special brought to you by CK Tan
Hosted by www.Geocities.ws

1