Visual Basic
   Visual Basic.Net
   Downloads
   Links
   Support This Site
   Contact

Google
Web VBCodesource.com






The Overloading Operator - A possible 'As Any' type workaround

In Visual Basic 6.0 you have available a type declaration 'As Any'. As you have already realized, Visual Basic.NET does not support this variable type. The 'As Any' type is definitely not very effecient anyways. So, even with it being supported in VB 6.0, you would still only want to use it in very limited cases. In my opinion, VB.Net has a must better alternative to a 'As Any' type by using the Overloads operator. Overloading your Methods, ect.. is quite simple. It is also much more effecient than the "As Any" type declaration. To overload a function, you only need to add the overloads keyword and create the functions with whatever datatype you want to use. Example Below:


Public Overloads Function hiAll(ByVal h As String)
	MessageBox.Show(h)
End Function
Public Overloads Function hiAll(ByVal h As Integer)
	MessageBox.Show(h.ToString)
End Function
Public Overloads Function hiAll(ByVal h As Long)
	MessageBox.Show(h.ToString)
End Function

If you add that overloaded function to your application, and use it, you will see that you can use any of the data types that you included in the function overload. I personally, really like this feature of VB.Net. You have no need for a 'As Any' type declaration. Having to use the Overloads operator is much more effecient than the 'As Any' type declaration. Well, I hope you got something beneficial from this small tutorial. Take care.... Jason