Skip to content

Instantly share code, notes, and snippets.

@SteGriff
Last active May 3, 2017 13:52
Show Gist options
  • Select an option

  • Save SteGriff/423ae03279b27c74a13baeb33e5f24e3 to your computer and use it in GitHub Desktop.

Select an option

Save SteGriff/423ae03279b27c74a13baeb33e5f24e3 to your computer and use it in GitHub Desktop.
Test which values are truthy and falsy in VBA
'VBA
' Results:
' 1 is truthy but not equal to True
' -1 is truthy and == True
' 0 is falsy and == False
' "True" is truthy and == True
' "False" is falsy and == False
Public Sub Test()
If "True" Then
MsgBox "'True' is truthy"
Else
MsgBox "'True' is falsy"
End If
If "True" = True Then
MsgBox "'True' = True"
Else
MsgBox "'True' != True"
End If
If "False" Then
MsgBox "'False' is truthy"
Else
MsgBox "'False' is falsy"
End If
If "False" = False Then
MsgBox "'False' = False"
Else
MsgBox "'False' != False"
End If
If 1 Then
MsgBox "1 is truthy"
Else
MsgBox "1 is falsy"
End If
If 1 = True Then
MsgBox "1 = True"
Else
MsgBox "1 != True"
End If
If -1 Then
MsgBox "-1 is truthy"
Else
MsgBox "-1 is falsy"
End If
If -1 = True Then
MsgBox "-1 = True"
Else
MsgBox "-1 != True"
End If
If 0 Then
MsgBox "0 is truthy"
Else
MsgBox "0 is falsy"
End If
If 0 = False Then
MsgBox "0 = False"
Else
MsgBox "0 != False"
End If
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment