Check for Integer?

G

garyh

Does anyone know of a way to easily check numeric data to
determine if it is an integer? There are a number of IS*
functions (IS NULL, et al.), but I can't seem to find a
way to easily check.

Any help is welcome. Thanks.

Gary
 
M

Marshall Barton

Does anyone know of a way to easily check numeric data to
determine if it is an integer? There are a number of IS*
functions (IS NULL, et al.), but I can't seem to find a
way to easily check.

If you know the data is numeric, then all you need is to
check if it matches it integer part.

If x = Int(x) Then
' it's an integer
Else
' not an integer
End If

If you want, you can create your own function based on the
above logic:

Public Function IsInteger(x As Variant) As Variant
IsInteger = (x = Int(x))
End Function
 
M

Marshall Barton

R. Hicks said:
Use the IsNumeric() Function ...

You've said that twice now and I still don't see how
IsNumeric can be used to determine if a number is an
integer. It's not even clear if IsNumeric tells you when a
string is a number (e.g. IsNumeric("3D4-") is True) so I
would appreciate it if you would elaborate on how to apply
your suggestion to the question.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top