in the MSDN, this is the description of VAL() function:
What's overload property? why part of functions or methods in .NET have this property?Quote:
This member is overloaded
Printable View
in the MSDN, this is the description of VAL() function:
What's overload property? why part of functions or methods in .NET have this property?Quote:
This member is overloaded
You really should have been able to look this up for yourself but here goes. Overloading simply means that you have multiple methods or properties that have the same name but different numbers and/or types of parameters. Here are two examples of overloaded methods:Note that the `Overloads` keyword is optional but, if you use it on one overload, you must use it on all.vb.net Code:
Public Sub DoSomething(arg As String) '... End Sub Public Sub DoSomething(arg As Integer) '... End Sub Public Overloads Sub DoSomethingElse(arg1 As String) '... End Sub Public Overloads Sub DoSomethingElse(arg1 As String, arg2 As String) '... End Sub
Because it is... it can accept a string, or an object, or.... it can accept parameter of different types... result, it needs to be overloaded.
-tg
exactly...
now i have received a good example on the stackoverflow.com about it:
thank youCode:Public Overloads Function Val(ByVal InputStr As String) As Double
' -or-
Public Overloads Function Val(ByVal Expression As Object) As Double
' -or-
Public Overloads Function Val(ByVal Expression As Char) As Integer
So what was it about jmc's post that wasn't sufficient?
-tg
It doesn't matter what method it is. An overloaded method is an overloaded method. What's the difference between your Val example and my DoSomething example? There really isn't any. It really seems like the word "example" has stopped meaning something that illustrates a principle that can then be applied elsewhere and now means the exact bit of code that you want to write.
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 :D
As has been said, Val should be avoided. If you want to cast a value to an integer then you can check if it is a number or not before casting it.
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.
The only reason Val exists is because it is something that has been part of the BASIC language lexicon since... well since the days of BASIC.
-tg