Results 1 to 10 of 10

Thread: Problems with CInt [RESOLVED]

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004

    Problems with CInt [RESOLVED]

    Code:
        Const bibble As String = "a"
        Dim number As Integer
        number = CInt(bibble)
    This code crashes the program. Is there a function that would do the same thing as CInt, but not make the program crash?
    Last edited by Darkwraith; Feb 27th, 2004 at 01:44 PM.
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Crashes? Do you mean an error occurs? The error makes sence since you can't get an integer from a letter. What are you trying to accomplice?


    Has someone helped you? Then you can Rate their helpful post.

  3. #3
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Are you looking for the ascii value? Asc(bibble) should give you 97. Otherwise "a" has no integer meaning.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    Crashes? Do you mean an error occurs? The error makes sence since you can't get an integer from a letter. What are you trying to accomplice?
    I am taking in user input. The user input should be an integer. The problem is that I cannot assume that the user input will be numerical.

    I need a function that could take in string input and convert to an integer without crashing the program if the input is invalid. If there is no such thing, is there a function that can tell me if the string that I have is numerical?
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  5. #5
    Junior Member Shattered's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    26
    Code:
    number = Val(bibble)
    will convert the value entered into a numeric - if its text it will return a zero value.
    "much to learn you still have"

  6. #6
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    I might be mixing up my versions of VB, working in 4 of them, but you could look up IsNumeric() or similar.

  7. #7
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Originally posted by salvelinus
    I might be mixing up my versions of VB, working in 4 of them, but you could look up IsNumeric() or similar.
    The IsNumeric() just tells you if it has only numbers or not. Val() gives you only the numbers


    Has someone helped you? Then you can Rate their helpful post.

  8. #8
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Originally posted by manavo11
    The IsNumeric() just tells you if it has only numbers or not. Val() gives you only the numbers
    True, but maybe 0 is a valid entry, so Val() wouldn't help him in the case:
    If there is no such thing, is there a function that can tell me if the string that I have is numerical?

  9. #9
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    But there is such a thing... Val() does that...


    Has someone helped you? Then you can Rate their helpful post.

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    Thanks. IsNumeric() worked!

    Thank for the help!
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width