Enjoy
Function HexPad(Value As Long, Width As Integer) As String
Select Case Width
Case Is = 8
HexPad = IIf(Value < 16, "0", "") & Hex$(Value)
Case Is = 16
HexPad = IIf((Value < 16), "000", _
IIf((Value < 256), "00", _
IIf((Value < 4096), "0", ""))) & Hex$(Value)
Case Is = 32 'no larger than +2147483647
HexPad = IIf((Value < 16), "0000000", _
IIf((Value < 256), "000000", _
IIf((Value < 4096), "00000", _
IIf((Value < 65535), "0000", _
IIf((Value < 1048575), "000", _
IIf((Value < 16777215), "00", _
IIf((Value < 268435455), "0", _
""))))))) & Hex$(Value)
End Select
End Function
Function HexPad(Value As Long, Width As Integer) As String
Select Case Width
Case Is = 8
HexPad = IIf(Value < 16, "0", "") & Hex$(Value)
Case Is = 16
HexPad = IIf((Value < 16), "000", _
IIf((Value < 256), "00", _
IIf((Value < 4096), "0", ""))) & Hex$(Value)
Case Is = 32 'no larger than +2147483647
HexPad = IIf((Value < 16), "0000000", _
IIf((Value < 256), "000000", _
IIf((Value < 4096), "00000", _
IIf((Value < 65535), "0000", _
IIf((Value < 1048575), "000", _
IIf((Value < 16777215), "00", _
IIf((Value < 268435455), "0", _
""))))))) & Hex$(Value)
End Select
End Function