This code crashes the program. Is there a function that would do the same thing as CInt, but not make the program crash?Code:Const bibble As String = "a"
Dim number As Integer
number = CInt(bibble)
Printable View
This code crashes the program. Is there a function that would do the same thing as CInt, but not make the program crash?Code:Const bibble As String = "a"
Dim number As Integer
number = CInt(bibble)
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?
Are you looking for the ascii value? Asc(bibble) should give you 97. Otherwise "a" has no integer meaning.
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.Quote:
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 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?
will convert the value entered into a numeric - if its text it will return a zero value.Code:number = Val(bibble)
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 ;)Quote:
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.
True, but maybe 0 is a valid entry, so Val() wouldn't help him in the case:Quote:
Originally posted by manavo11
The IsNumeric() just tells you if it has only numbers or not. Val() gives you only the numbers ;)
Quote:
If there is no such thing, is there a function that can tell me if the string that I have is numerical?
But there is such a thing... Val() does that... :confused:
Thanks. IsNumeric() worked!
Thank for the help! :)