By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,361 Members | 1,677 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,361 IT Pros & Developers. It's quick & easy.

is there any is integer function ?

P: n/a
Tee
Hi,

how do we detect if a value is a positive integer ?

thanks,
Tee
Nov 18 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
TJS
if myValue > 0 then ...
"Tee" <thy[NO@SPAM]streamyx.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

how do we detect if a value is a positive integer ?

thanks,
Tee

Nov 18 '05 #2

P: n/a
> how do we detect if a value is a positive integer ?

Are you using VB.NET or C#? In C# I'd do:

if (x is int)
{
if ((int) x) > 0)
// x is a positive integer
else
// x is a negative integer
}
else
// x is NOT an integer at all!
In VB.NET you can use IsNumeric().

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!
Nov 18 '05 #3

P: n/a
And how would this know the difference between 1 and 1.1?

if x > 0 AND x = CTYPE(x, Integer) then
"TJS" <no****@here.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
if myValue > 0 then ...
"Tee" <thy[NO@SPAM]streamyx.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

how do we detect if a value is a positive integer ?

thanks,
Tee


Nov 18 '05 #4

P: n/a
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

"Scott Mitchell [MVP]" <mi******@4guysfromrolla.com> wrote in message
news:PS*******************@newssvr25.news.prodigy. com...
how do we detect if a value is a positive integer ?


Are you using VB.NET or C#? In C# I'd do:

if (x is int)
{
if ((int) x) > 0)
// x is a positive integer
else
// x is a negative integer
}
else
// x is NOT an integer at all!
In VB.NET you can use IsNumeric().

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!

Nov 18 '05 #5

P: n/a
Tee
Great idea,

Thanks.
"Scott M." <s-***@BADSPAMsnet.net> wrote in message
news:ui*************@TK2MSFTNGP12.phx.gbl...
And how would this know the difference between 1 and 1.1?

if x > 0 AND x = CTYPE(x, Integer) then
"TJS" <no****@here.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
if myValue > 0 then ...
"Tee" <thy[NO@SPAM]streamyx.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
> Hi,
>
> how do we detect if a value is a positive integer ?
>
> thanks,
> Tee
>
>



Nov 18 '05 #6

P: n/a
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
-----Original Message-----
Hi,

how do we detect if a value is a positive integer ?

thanks,
Tee
.

Nov 18 '05 #7

P: n/a
> 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.

"Tee" <thy[NO@SPAM]streamyx.com> wrote in message
news:uT**************@tk2msftngp13.phx.gbl...
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

"Scott Mitchell [MVP]" <mi******@4guysfromrolla.com> wrote in message
news:PS*******************@newssvr25.news.prodigy. com...
how do we detect if a value is a positive integer ?


Are you using VB.NET or C#? In C# I'd do:

if (x is int)
{
if ((int) x) > 0)
// x is a positive integer
else
// x is a negative integer
}
else
// x is NOT an integer at all!
In VB.NET you can use IsNumeric().

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!


Nov 18 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.