cond.gif (1345 bytes)

Exclamtiub.gif (188 bytes) Conditional statements are used to test a certain condition, and if the value u select is true, or is equal to, or whatever your program intents it to do, will perform the selected functions.

cond_format.gif (1042 bytes)

If Condition = Value then
stuff to do
End If

Break down
(all break downs are numbered by lines of code!)

1. We add the if statement, If our condition is met then...
2. We tell VB what to do if your condition is met.
3. Now we close up the if statement with the End If command. This tells VB that were done telling it what to do and to end the IF statement.

Multiple Conditions

If Label1.Caption < 10 Then
     Call Msgbox("Its Less than 10",vbOkOnly,"nauts-crib")
End If
    If Label1.Caption > 10 Then
         
Call Msgbox("Its Greater than 10",vbOkOnly,"nauts-crib")
     End If
          If label1.Caption = 10 Then
             
Call Msgbox("Its 10!",vbOkOnly,"nauts-crib")
          End If

!.gif (145 bytes) You can have as many if statements that you want, just remember to keep them indented for debugging.

1. We ask vb if the caption of label1 is less then 10.
2. If the caption is less then 10, then a msgbox pops up.
3.
We End the statement.

           

4. If the caption wasn't less then 10, then VB reads this statement, now we ask VB if the caption is greater then 10.
5. If the caption is greater then 10, we send a MSG box up.
6. We End the statement.

 

7. Now, if the caption wasn't less then 10, and wasn't greater then 10, VB reads this statement.
8.
If the caption is 10 then we send a MSG box up.
9.
We End the statement.

 


else.gif (1768 bytes)

 Exclamtiub.gif (188 bytes) Else - as in if the if condition isn't met then.. well, do something ELSE.

If Label1.Caption = 10 Then
       Call MsgBox("Its 10", vbOKOnly, "nauts-crib")
Else
       Call MsgBox("It might be less, or it might be greater", vbOKOnly, "nauts-crib.com")
End If

 

1. See if Label1.caption equals 10
2. If the first condition is met (if label1.caption = 10) we send a message box up.
3. If the condition was not met, we go to the else statement.
4. Now if the first condition wasn't met, it went to the else, and our statement is to send a msgbox saying it might be less, or it might be greater.

 


- Else is good, but.. I wantelseif.gif (982 bytes) more conditionals -

sometimes we call for the else statements, as in if the if condition isn't met then.. well,
do something ELSE, but sometimes we want to break down what happens in the else statement,
as in if its not 10, then. well is it less or greater?

If label1.Caption = 10 Then
      Call MsgBox("Its 10", vbOKOnly, "nauts-crib")
Else:
    If label1.Caption > 10 Then Call MsgBox("its greater", vbOKOnly, "nauts-crib.com")
    If label1.Caption < 10 Then Call MsgBox("its lower", vbOKOnly, "nauts-crib.com")
End If

 

1. we see if the caption is 10
2. If it is 10, then we call a msgbox saying it is.
3. If its not 10, then do whatever is in Else
4. now lets say the label wasn't 10, the else is called, and now we say, well if its not 10, then is it less then 10? if it is then call a MSG telling us its less then 10.
5. well if it wasn't 10, and it wasn't less then 10... is it greater then 10? if it is then call a MSG telling us it is.

VB_back.gif (1347 bytes)

1999-2000 © Erik Helgesen All Rights Reserved.
Only permitted Images and Material may be downloaded from this web site. 
PhotoShop, Flash, and Microsoft Visual Basic are registered trademarks!