|
-
Nov 19th, 2014, 04:05 AM
#10
Re: Val Function and overload notice
 Originally Posted by Mehdi Jazini
it seems you don't know about val benefits... when the entered value is not a number then the val function returns 0 instead of error but in cint and clng it returns error... cint(val(value)) is so better than cint(value) so val has place in vb.net as it had in vb6 
That's bad advice. It's not true that Val returns zero when the input is not a number. I would say that "1x2" is not a number and yet Val would return 1.0 when fed that input. If you actually want to use zero when the input is not numeric then you should be using the TryParse method of the appropriate numeric type. The only thing Val is actually good for is when you want to pick the number off the front of a String that is, or may not be, completely numeric. That's rare but you might perhaps want to take the house number off the front of an address. Again though, if you do that and the address doesn't begin with a number then you get zero, which might not be what you want.
Tags for this Thread
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
|