Sunday, October 16, 2022

Data type - Byte

Data type Byte store as single 8-bit (1-byte) numbers from 0-255. The default value is 0 and no negative value and more than 255. It will generate error when we try to assigned out of range "Run-Time Error '6' over flow.

VBA Vode:

Option Explicit
Sub Examples_Byte()
    
    Dim iNumA As Integer, iNumB As Integer
    Dim BytNum As Byte
    
    iNumA = 10: iNumB = 15
    If Not Abs(iNumA - iNumB) > 255 Then
        BytNum = Abs(iNumA - iNumB) 'Remove negative sign
    Else
        MsgBox "Sorry! Data overflow.TQ"
    End If
    
    Debug.Print BytNum

End Sub

Note: 

Above example we use ABS function to remove negative sign and get absolute value and test the value over 255 or not then only assigned Byte data type.

Microsoft Reference-Byte-data-type
Other Reference-Byte-data-type.htm

Practice makes perfect. Thank You.

excelmacros
macro excel
excel programming
excel vba

No comments:

Post a Comment