Saturday, October 15, 2022

Data type - Boolean

Data type Boolean is only True ( -1 ) Or False ( 0 ) and basically stored as 16-bit (2-byte) numbers. The default is False or 0 (zero) but if the statement result other than 0 then it consider True. For example we have numbers A=5 and B=5 then A-B=0 then boolean consider False and vice versa.

VBA Vode:

Option Explicit
Sub Examples_Boolean()

    Dim iNumA As Integer, iNumB As Integer
    Dim BlResult As Boolean
    
    iNumA = 10: iNumB = 5
    BlResult = Not (iNumA < iNumB)
    
    Debug.Print BlResult

End Sub

Note: 

The result for the above code is True? Don't get confuse when we use Not operator, because inside bracket statement is False (10<5) then operator Not reverse the statement become True.

Microsoft Reference-Boolean-data-type
Other Reference-Boolean-data-type

Practice makes perfect. Thank You.

macro enabled excel
excel macro
vba coding
vba code

No comments:

Post a Comment