Article ID: 141691
Article Last Modified on 10/11/2006
Sub Using_IF()
' Dimension the variable.
Dim x As Integer
' Place a value in x.
x = Int(Rnd * 100)
' Test to see if x less than or equal to 10.
If x <= 10 Then
' Display a message box.
MsgBox "X is <=10"
' Test to see if x less than or equal to 40 and greater than 10.
ElseIf x <= 40 And x > 10 Then
MsgBox "X is <=40 and > 10"
' Test to see if x less than or equal to 70 and greater than 40.
ElseIf x <= 70 And x > 40 Then
MsgBox "X is <=70 and > 40"
' Test to see if x less than or equal to 100 and greater than 70.
ElseIf x <= 100 And x > 70 Then
MsgBox "X is <= 100 and > 70"
' If none of the above tests returned true.
Else
MsgBox "X does not fall within the range"
End If
End Sub
Sub Using_Case()
' Dimension the variable.
Dim x As Integer
' Place a value in x.
x = Int(Rnd * 100)
' Start the Select Case structure.
Select Case x
' Test to see if x less than or equal to 10.
Case Is <= 10
' Display a message box.
MsgBox "X is <=10"
' Test to see if x less than or equal to 40 and greater than 10.
Case 11 To 40
MsgBox "X is <=40 and > 10"
' Test to see if x less than or equal to 70 and greater than 40.
Case 41 To 70
MsgBox "X is <=70 and > 40"
' Test to see if x less than or equal to 100 and greater than 70.
Case 71 To 100
MsgBox "X is <= 100 and > 70"
' If none of the above tests returned true.
Case Else
MsgBox "X does not fall within the range"
End Select
End Sub
tell me about conditional programming
if
-or-
case
163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: 5.00a 5.00c logic
Keywords: kbdtacode kbhowto kbprogramming KB141691