29-06-2009, 01:11 PM
If then, what?
If .. Then statements are very important.
Examples:
An example of If .. Else
An example of If .. ElseIf ..
There are some short hand with VB6. If you are testing a boolean value you do not need to have "IF value = true Then". you just need to have "If value Then". For false values you use "If Not b Then" instead of "If b = false then".
Project
Use multiple versions of the If .. then statement to evaluate a number that the user inputs. Check if the number is above 0, above 100, and above 1000. Display the results.
Overview
Notes
If .. Then statements are very important.
Code:
If [Logic] Then
[Statements]
End If
Examples:
Code:
Dim i As Long
If i > 0 Then
Debug.Print "The answer is true"
End If
An example of If .. Else
Code:
Dim b As Boolean
b = False
If b = True Then
Debug.Print "The answer is true"
Else
Debug.Print "The answer is false"
End If
An example of If .. ElseIf ..
Code:
Dim i As Long
If i > 0 Then
Debug.Print "The answer is true"
ElseIf i < 0 Then
Debug.Print "The answer is false"
End If
There are some short hand with VB6. If you are testing a boolean value you do not need to have "IF value = true Then". you just need to have "If value Then". For false values you use "If Not b Then" instead of "If b = false then".
Code:
Dim b As Boolean
b = False
If b Then
Debug.Print "The answer is true"
ElseIf Not b Then
Debug.Print "The answer is false"
End If
Project
Use multiple versions of the If .. then statement to evaluate a number that the user inputs. Check if the number is above 0, above 100, and above 1000. Display the results.
Overview
- Declare variables.
- Use an If ... then statement to check the number the user inputs.
Notes
- Make sure to comment your code.