Visual Basic Code Source
Free and Unique code for Visual Basic
 Current page : Home      overloadsOperatorTutorial




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 closest thing to the 'As Any' type is 'Object'. The 'As Any' type is really not efficient. So, even though it is supported in VB 6.0, you should only use it in very limited cases. In my opinion, Visual Basic.NET has a possible more efficient alternative to the 'As Any' type by using the Overloads operator. Overloading your Methods, and such is quite simple. To overload a function, you only need to add the Overloads keyword and create the functions with whatever data types you feel that the method could 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
   
    While this feature may not completely do what the 'As Any' type can, it is more efficient.  Take care....
 
 
 
                Jason - Edit: 2007, May 20th
 
 
Visual Basic Code Source - Copyright 1999-2007