How do I determine data type?

L

Leanne

Is there any function in VB to determine if the number is
positive integer or not? Need help.

Thank you
 
D

Dan Artuso

Hi,
How about:
Dim i as Integer

i = 23

If i >= 0 Then
MsgBox "yep, it's positive"
End If

or if you mean you want to find out if it's an integer AND whether it's positive
or not:

If IsNumeric(i) Then

If i >= 0 Then
MsgBox "yep, it's a number and it's positive"
End If
Else
MsgBox "sorry, it's not a number
End If
 
J

John Nurick

Hi Leanne,

Something like this should do:

Public Function IsPosInteger(X As Double) As Boolean
Const PRECISION = 0.000000000001
'Adjust PRECISIONS as desired to avoid
'false negatives caused by rounding errors

IsPosInteger = (X > 0) _
And (Abs(X - CLng(X)) <= PRECISION)
'Use X <=0 if you count zero as a +ve integer

End Function
 

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