FaheemAhmadGul
asked on
A more efficient way of writing an if then Structure
I have an integer variable named MyVariable in a Visual Basic Project. I also have three Boolean Variables named Bool1, Bool2 and Bool3 in my project. I have an If Then statement structure like the following:
If MyVariable = 1 Then
MsgBox("Hello")
Bool1 = True
ElseIf MyVariable = 2 Then
MsgBox("Hello")
Bool2 = True
ElseIf MyVariable = 3 Then
MsgBox("Hello")
Bool3 = True
End If
I am wondering if there is a more efficient way of writing this if then structure. Thank you for your help in anticipation.
If MyVariable = 1 Then
MsgBox("Hello")
Bool1 = True
ElseIf MyVariable = 2 Then
MsgBox("Hello")
Bool2 = True
ElseIf MyVariable = 3 Then
MsgBox("Hello")
Bool3 = True
End If
I am wondering if there is a more efficient way of writing this if then structure. Thank you for your help in anticipation.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just to add that your example can be written quite neatly using Select Case
Select Case MyVariable
Case 1, 2, 3
MsgBox ("Hello")
Bool1 = True
End If
ASKER