View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_1819_] Rick Rothstein \(MVP - VB\)[_1819_] is offline
external usenet poster
 
Posts: 1
Default IsNumber (in Rick Rothstein's example)

You are going to explain in some detail exactly how you are using this
function. The reason is because the function already returns False for
numbers like $123 and 1E2... that is what it was designed to do.

Rick


"Sam Kuo" wrote in message
...
Hi Rick

Thanks for your explaination.
Sorry you were right that I was really after IsNumber, not IsDigits of
your
example.

I want to only allow positive whole number (without decimal point) and
real
number (with decimal point) to return TRUE. For example, the acceptable
input
might be 0.25 or 100 say.

Your IsNumber here works great for this purpose. But I also need input
with
signs (e.g. $123) or exponential (1E2) to return FALSE. Is this doable?

Function IsNumber(ByVal Value As String) As Boolean
IsNumber = Not Value Like "*[!0-9.]*" And _
Not Value Like "*.*.*" And _
Len(Value) 0 And Value < "." And _
Value < vbNullString
End Function

Many thanks
Sam




"Rick Rothstein (MVP - VB)" wrote:

Below is one of Rick Rothstein's examples that he recommands
for use in replacement of IsNumeric.

Function IsNumber(ByVal Value As String) As Boolean
IsNumber = Len(Value) 0 And Not Value Like "*[!0-9.]*"
End Function

Rightfully, the function you posted should have been called IsDigits,
not
IsNumber.


I just noticed... you added a decimal point inside the square-brackets
that
I had not included in my original posting. Doing that invalidates the
function... for that modification you did, things like the following will
now pass the test...

Debug.Print IsNumber(".")
Debug.Print IsNumber("...")
Debug.Print IsNumber("1.2.3")

See my other posts in this thread for the function you want.

Rick