is there any is integer function ?

S

Scott M.

And how would this know the difference between 1 and 1.1?

if x > 0 AND x = CTYPE(x, Integer) then
 
T

Tee

Hi,

Thanks for your reply,
I know about the isnumeric, but ... whatever number value will return true
with isnumeric, so I hope to get something like isInteger() ...

thanks.
Tee
 
H

Harsh Thakur

Hi,

As noted before, for a positive integer, you can just say:
if(x > 0)
To test whether x is in integer, you can say:
x = int.Parse(value.ToString())
where value is the number you want to check.

If value represents an integer, x will contain it after
the step given above. Else an FormatException will be
thrown.

For more details you can check out int.Parse in MSDN.

HTH
Regards
Harsh Thakur
 
K

Kevin Spencer

with isnumeric, so I hope to get something like isInteger() ...

You need to re-read Scott's reply. That was the first thing he tested for.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Joined
Jul 1, 2010
Messages
1
Reaction score
0
A different Approach

public bool IsNumber(string text)
{
bool result = true;
foreach (var c in text)
{
if (!Char.IsDigit(c))
{
result = false;
break;
}
}

return result;
}

Cheers
 
Joined
Feb 28, 2011
Messages
1
Reaction score
0
Try this:


If IsNumeric(UserInputTextBox.Text) And (System.Math.Abs(val(UserInputTextBox.Text) Mod 1) <> 0) Then
'______Do something
End if

************************
OR Atfer checking IsNumeric(UserInputTextBox.Text)
Do this following:

if (System.Math.Abs(val(UserInputTextBox.Text) Mod 1) <> 0)
 
Last edited:
Joined
Jan 27, 2012
Messages
1
Reaction score
0
Positive Integer Function in vb.net

In vb.net you get a cast error if you pass a string in some functions. This should take care of it:


Private Function IsPositiveInteger(ByVal objValue AsObject) As Boolean
Dim intX AsInteger
If Not (IsNumeric(objValue)) Then
Return False
Else
intX = CInt(objValue)
If objValue > 0 Then
Return True
Else
Return False
End If
End If
 
Last edited:
Joined
Jan 30, 2012
Messages
1
Reaction score
0
' inputString is the string we want to test.
Dim number As Integer
If TryParse(inputString, number) AndAlso number > 0
'''' Continue here ....
End If
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top