
Blackstone H. answered 05/17/19
Senior Database Developer using SQL, Visual Basic (VB)
There are two forms of IF THEN / ELSE. One that uses the END IF, and one that doesn't. The statement without the END IF is for the simplest of tests and actions.
With the simple version, everything happens in one line of code.
======================
Private Sub SimpleIfThen()
Dim Someone As String
Someone = "Michael"
If Someone = "Michael" Then MsgBox "Michael called." Else MsgBox "Someone else called."
End Sub
The complex version allows for more logical tests and more lines of code after each condition
======================
Private Sub AddToCallLog(ByVal TimeStamp As Date)
'Add to database code goes in this routine
End Sub
Private Sub DeleteFromCallLog(ByVal AngryCaller As String)
'Remove from database code goes in this routine
End Sub
Private Sub ComplexIfThen(ByVal Someone As String)
If Someone = "Michael" Then
MsgBox "Michael called."
Call AddToCallLog(Now())
ElseIf Somone = "Susan" Then
MsgBox "Susan called on behalf of Michael."
Call AddToCallLog(Now())
ElseIf Someone = "John" Then
MsgBox "John was upset he didn't get a call from Michael."
Call DeleteFromCallLog(Someone)
Else
MsgBox "Someone else called."
End If
End Sub