|
-
Feb 25th, 2004, 10:33 AM
#1
Thread Starter
Fanatic Member
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.
-
Feb 25th, 2004, 03:26 PM
#2
-
Feb 25th, 2004, 03:50 PM
#3
Frenzied Member
Are you looking for the ascii value? Asc(bibble) should give you 97. Otherwise "a" has no integer meaning.
-
Feb 25th, 2004, 09:48 PM
#4
Thread Starter
Fanatic Member
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.
-
Feb 26th, 2004, 02:30 AM
#5
Junior Member
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"
-
Feb 26th, 2004, 07:56 AM
#6
Frenzied Member
I might be mixing up my versions of VB, working in 4 of them, but you could look up IsNumeric() or similar.
-
Feb 26th, 2004, 09:02 AM
#7
-
Feb 26th, 2004, 11:55 AM
#8
Frenzied Member
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?
-
Feb 26th, 2004, 04:04 PM
#9
-
Feb 27th, 2004, 01:44 PM
#10
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|