is there any is integer function ?

Discussion in 'ASP .Net' started by Tee, Feb 27, 2004.

  1. Tee

    Tee Guest

    Hi,

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

    thanks,
    Tee
    Tee, Feb 27, 2004
    #1
    1. Advertising

  2. Tee

    TJS Guest

    if myValue > 0 then ...


    "Tee" <thy[NO@SPAM]streamyx.com> wrote in message
    news:%23eHvYdO$...
    > Hi,
    >
    > how do we detect if a value is a positive integer ?
    >
    > thanks,
    > Tee
    >
    >
    TJS, Feb 27, 2004
    #2
    1. Advertising

  3. > 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

    http://www.4GuysFromRolla.com
    http://www.ASPFAQs.com
    http://www.ASPMessageboard.com

    * When you think ASP, think 4GuysFromRolla.com!
    Scott Mitchell [MVP], Feb 27, 2004
    #3
  4. Tee

    Scott M. Guest

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

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


    "TJS" <> wrote in message
    news:%23M7RetO$...
    > if myValue > 0 then ...
    >
    >
    > "Tee" <thy[NO@SPAM]streamyx.com> wrote in message
    > news:%23eHvYdO$...
    > > Hi,
    > >
    > > how do we detect if a value is a positive integer ?
    > >
    > > thanks,
    > > Tee
    > >
    > >

    >
    >
    Scott M., Feb 27, 2004
    #4
  5. Tee

    Tee Guest

    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]" <> wrote in message
    news:pSz%b.30990$...
    >> 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
    >
    > http://www.4GuysFromRolla.com
    > http://www.ASPFAQs.com
    > http://www.ASPMessageboard.com
    >
    > * When you think ASP, think 4GuysFromRolla.com!
    Tee, Feb 27, 2004
    #5
  6. Tee

    Tee Guest

    Great idea,

    Thanks.


    "Scott M." <> wrote in message
    news:uidueTP$...
    > And how would this know the difference between 1 and 1.1?
    >
    > if x > 0 AND x = CTYPE(x, Integer) then
    >
    >
    > "TJS" <> wrote in message
    > news:%23M7RetO$...
    >> if myValue > 0 then ...
    >>
    >>
    >> "Tee" <thy[NO@SPAM]streamyx.com> wrote in message
    >> news:%23eHvYdO$...
    >> > Hi,
    >> >
    >> > how do we detect if a value is a positive integer ?
    >> >
    >> > thanks,
    >> > Tee
    >> >
    >> >

    >>
    >>

    >
    >
    Tee, Feb 27, 2004
    #6
  7. Tee

    Harsh Thakur Guest

    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
    >
    >
    >.
    >
    Harsh Thakur, Feb 27, 2004
    #7
  8. > 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:uTcdEYP$...
    > 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]" <> wrote in message
    > news:pSz%b.30990$...
    > >> 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
    > >
    > > http://www.4GuysFromRolla.com
    > > http://www.ASPFAQs.com
    > > http://www.ASPMessageboard.com
    > >
    > > * When you think ASP, think 4GuysFromRolla.com!

    >
    >
    Kevin Spencer, Feb 27, 2004
    #8
  9. Tee

    JesseChallis

    Joined:
    Jul 1, 2010
    Messages:
    1
    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
    JesseChallis, Jul 1, 2010
    #9
  10. Tee

    rutgers

    Joined:
    Feb 28, 2011
    Messages:
    1
    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: Feb 28, 2011
    rutgers, Feb 28, 2011
    #10
  11. Tee

    kmoloney

    Joined:
    Jan 27, 2012
    Messages:
    1
    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: Jan 27, 2012
    kmoloney, Jan 27, 2012
    #11
  12. Tee

    AJBiagioli

    Joined:
    Jan 30, 2012
    Messages:
    1
    ' inputString is the string we want to test.
    Dim number As Integer
    If TryParse(inputString, number) AndAlso number > 0
    '''' Continue here ....
    End If
    AJBiagioli, Jan 30, 2012
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ashu
    Replies:
    7
    Views:
    318
    David Resnick
    Jan 26, 2006
  2. aaragon
    Replies:
    15
    Views:
    512
    Daniel T.
    Dec 30, 2007
  3. tenxian
    Replies:
    3
    Views:
    293
    RedGrittyBrick
    Apr 29, 2008
  4. Weng Tianxiang
    Replies:
    7
    Views:
    1,279
    Paul Uiterlinden
    Sep 11, 2009
  5. Eric Danstron

    Are there ANY good forums out there anymore???

    Eric Danstron, Sep 21, 2005, in forum: ASP General
    Replies:
    1
    Views:
    146
    Immediacy
    Sep 22, 2005
Loading...

Share This Page