CInt in

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

  1. Guest

    Guest Guest


    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?

    Guest, Jan 17, 2005
    1. Advertisements

  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)
    Marc M, Jan 18, 2005
    1. Advertisements

  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)
    Marc M, Jan 18, 2005
  4. Guest

    Guest Guest

    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.


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

    ' lets say s = "7.1"
    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
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.