CInt in VB.net

Discussion in 'MCAD' started by Guest, Jan 17, 2005.

  1. Guest

    Guest Guest

    Hi,

    I have a question regarding the use of CInt and/or Char
    member functions.

    Let's say I have an input string,

    Dim input As String = "7.5"

    and I need to check if this string(number) is either 7 or
    8 (or so on....), I use the CInt function and compare the
    value using If-statement.

    "7.5" is supposed to return false to me but CInt now
    turns it into 8 (so it returns true now)

    Any ideas to fix that?

    thanks.
     
    Guest, Jan 17, 2005
    #1
    1. Advertising

  2. Guest

    Marc M Guest

    CInt will convert to Interger
    CDouble will help you.
    C???? are leftover of old VB 6, try to get away from it

    In .Net it is better to use CType like

    if CType(input, double) ....

    Good luck
    Marc M
    MCSD (6.0 & .NET)

    wrote:
    > Hi,
    >
    > I have a question regarding the use of CInt and/or Char
    > member functions.
    >
    > Let's say I have an input string,
    >
    > Dim input As String = "7.5"
    >
    > and I need to check if this string(number) is either 7 or
    > 8 (or so on....), I use the CInt function and compare the
    > value using If-statement.
    >
    > "7.5" is supposed to return false to me but CInt now
    > turns it into 8 (so it returns true now)
    >
    > Any ideas to fix that?
    >
    > thanks.
     
    Marc M, Jan 18, 2005
    #2
    1. Advertising

  3. Guest

    Marc M Guest

    CInt will convert to Integer
    Use CDouble.
    All C????? are old VB 6.0 syntax

    In .Net use CType to convert like

    If CType(input, Double) .......

    Hope this helps

    Marc M
    MCSD (6.0 & .NET)


    wrote:

    > Hi,
    >
    > I have a question regarding the use of CInt and/or Char
    > member functions.
    >
    > Let's say I have an input string,
    >
    > Dim input As String = "7.5"
    >
    > and I need to check if this string(number) is either 7 or
    > 8 (or so on....), I use the CInt function and compare the
    > value using If-statement.
    >
    > "7.5" is supposed to return false to me but CInt now
    > turns it into 8 (so it returns true now)
    >
    > Any ideas to fix that?
    >
    > thanks.
     
    Marc M, Jan 18, 2005
    #3
  4. Guest

    Guest Guest


    >-----Original Message-----
    >Hi,
    >
    >I have a question regarding the use of CInt and/or Char
    >member functions.
    >
    >Let's say I have an input string,
    >
    >Dim input As String = "7.5"
    >
    >and I need to check if this string(number) is either 7 or
    >8 (or so on....), I use the CInt function and compare the
    >value using If-statement.
    >
    >"7.5" is supposed to return false to me but CInt now
    >turns it into 8 (so it returns true now)
    >
    >Any ideas to fix that?
    >
    >thanks.
    >


    Best way (I think) use .Net System.Convert.ToDouble or
    System.Convert.ToDecimal with try & catch. If convert
    successful then it is number else it is not.

    Example

    Public Function SomeFunct(ByVal s As String) As Double
    Dim x As Double

    ' lets say s = "7.1"
    Try
    x = System.Convert.ToDouble(s)
    Return x;
    Catch ex As Exception
    Return -1 'set -1 to inform you that not number!
    End Try

    End Function

    Hope that helpful.
     
    Guest, Jan 21, 2005
    #4
    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. Brunswick Lowe

    vb.net vs. studio.net

    Brunswick Lowe, Jul 30, 2003, in forum: MCSD
    Replies:
    5
    Views:
    3,311
    John S
    Aug 3, 2003
  2. Alex
    Replies:
    0
    Views:
    506
  3. Cowboy \(Gregory A. Beamer\)

    Take MCSD.NET with VB.NET and C#.NET in the same time?

    Cowboy \(Gregory A. Beamer\), Jan 1, 2004, in forum: MCSD
    Replies:
    1
    Views:
    527
    The Fox
    Jan 1, 2004
  4. Ivor

    C#.Net or VisualBasic.Net

    Ivor, Aug 18, 2004, in forum: MCSD
    Replies:
    8
    Views:
    1,064
    The Poster Formerly Known as Kline Sphere
    Aug 22, 2004
  5. london1919
    Replies:
    1
    Views:
    2,966
    Lawrence Garvin \(MVP\)
    Dec 8, 2008
Loading...

Share This Page