Is digit


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'**********************************************************************************************************
' Name:                 isDigit
' Author:               mielk | 2012-02-19
'
' Comment:              Function checks if the given character is a digit.
'
' Parameters:
'   char                The character to be checked.
'                       The given text should contain only one character. If longer string is passed to
'                       this function, only first character is analyzed and the other ones are ignored.
'
' Returns:
'   Boolean             True - if the given character is a digit.
'                       False - if the given character is not a digit.
'
'
' --- Changes log -----------------------------------------------------------------------------------------
' 2012-02-19    mielk       Method created.
'**********************************************************************************************************
Public Function isDigit(ByVal char As String) As Boolean
    Const METHOD_NAME As String = "isDigit"
    '------------------------------------------------------------------------------------------------------
    Dim iAsciiCode As Integer
    '------------------------------------------------------------------------------------------------------


    'Uses [Asc] function to get an ASCII code of a character.
    iAsciiCode = VBA.Asc(char)


    'The ASCII codes for the digits range from 48 to 57. If an ASCII code of the character is
    'within this range, the character is a digit and will be appended to the result string.
    If iAsciiCode >= 48 And iAsciiCode <= 57 Then
        isDigit = True
    End If


End Function