How do I determine data type?

  • Thread starter Thread starter Leanne
  • Start date Start date
L

Leanne

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

Thank you
 
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
 
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
 
Back
Top