I Think it is best solution
- From: "Programmer" <Programmer@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 14 Aug 2005 14:04:02 -0700
This code can understand the value is numeric or not?
and it can change delimeter if you want.
Thanks for help, Michael and Sinna
Function MyNumeric(NumberValue As String, DelimiterSensitive As String,
Optional ConvertTheNumberDelimeterFormat As Integer)
'This function is slackwx's function
'I want to share this with you If you need it, you can use it.
'If you have any comment, you can send an e-mail
'My e-mail address : Slackwx at gmail.com
'Thanks for help ,Michael and Sinna
IsOnlyNumericExpression = Not (NumberValue Like "*[!0-9.,]*")
If IsOnlyNumericExpression Then ' doesnt allow Hex Decimal Value and others
' ### Delimeter Sensitive Section Starts ###
If Len(DelimiterSensitive) <> 1 Or Len(DelimiterSensitive) = 0 Then ' it
must be
MyNumeric = False
Exit Function
ElseIf Len(DelimiterSensitive) = 1 Then ' that's good it will work
CheckOption = InStr(1, ",.", DelimiterSensitive, vbTextCompare)'if option
is my own option?
If CheckOption = 0 Then ' there is no option my own
MyNumeric = False
Exit Function
End If
If CheckOption = 1 Then ' Delimiter is comma
CommaCountArray = Split(NumberValue, ",")
CommaCount = UBound(CommaCountArray)
If CommaCount > 1 Then 'if it contains a lot of comma, array
dimension must be greater than 1
MyNumeric = False
Exit Function
End If
'if it contains one comma ,it is ok but I wonder does it contain any
dot (one or more...)
DotCountArray = Split(NumberValue, ".")
DotCount = UBound(DotCountArray)
If DotCount = 1 And ConvertTheNumberDelimeterFormat = 1 Then ' if
user wants to convert valid format numeric according to delimetersensivite
MyNumeric = Replace(NumberValue, ".", ",")
Exit Function
ElseIf DotCount >= 1 Then 'if it contains one or more dot, array
dimension must be 1 or greater than 1
MyNumeric = False
Exit Function
End If
End If
If CheckOption = 2 Then ' Delimiter is dot
DotCountArray = Split(NumberValue, ".")
DotCount = UBound(DotCountArray)
If DotCount > 1 Then 'if it contains a lot of dot, array dimension
must be greater than 1
MyNumeric = False
Exit Function
End If
'if it contains one dot ,it is ok but I wonder does it contain any
comma (one or more...)
CommaCountArray = Split(NumberValue, ",")
CommaCount = UBound(CommaCountArray)
If CommaCount = 1 And ConvertTheNumberDelimeterFormat = 1 Then ' if
user wants to convert valid format numeric according to delimetersensivite
MyNumeric = Replace(NumberValue, ",", ".")
Exit Function
ElseIf CommaCount >= 1 Then 'if it contains one or more comma, array
dimension must be 1 or greater than 1
MyNumeric = False
Exit Function
End If
End If
End If
' ### Delimeter Sensitive Section Ends ###
' value is still here , it is so cool
MyNumeric = True
Else
MyNumeric = False
End If
End Function
.
- References:
- IsNumeric Does not Work!
- From: Programmer
- IsNumeric Does not Work!
- Prev by Date: Re: IsNumeric Does not Work!
- Next by Date: RE: Problem restoring VB6 app from the taskbar
- Previous by thread: Re: IsNumeric Does not Work!
- Next by thread: RE: Problem restoring VB6 app from the taskbar
- Index(es):