Function DecimalOnly
’NOTE: Please download code samples. _
Guidespot uses characters that are incompatable _
with your compiler.
Public Function DecimalOnly(ByVal Text) _
As String
Dim AllowedChr _
As String
AllowedChr = _
“48|49|50|51|52|53|54|55|56|57”
’0 1 2 3 4 5 6 7 8 9
Dim IllegalChr _
As Boolean
IllegalChr = True
If Text = "" Then
’No need to parse
Exit Function
End If
For ct = 0 To _
UBound(Split(AllowedChr, “|”))
If Not Len(Text) = 1 Then
‘If the character code equals something _
in the list it’s ok
If Asc(Mid(Text, Len(Text), 1)) = _
Split(AllowedChr, “|”)(ct) Then
IllegalChr = False
Exit For
End If
Else
If Asc(Text) = _
Split(AllowedChr, “|”)(ct) Then
IllegalChr = False
Exit For
End If
End If
Next
’Ignoring when len is 1 forbids _
a period as the first character
If Not Len(Text) = 1 Then
If Not Len(Replace(Text, “.”, "")) = _
Len(Text) – 2 Then
If Mid(Text, Len(Text), 1) = _
“.” Then
IllegalChr = _
False
End If
End If
End If
If IllegalChr Then
Text = Mid(Text, 1, Len(Text) – 1)
End If
DecimalOnly = Text
End Function
Discussions