Difference between revisions of "Passing UDTs to Classes"

From HashVB
Jump to: navigation, search
 
Line 17: Line 17:
 
   Debug.Print myClassInstance.myFunction(foo) '-- Prints 1000 to Immediate window
 
   Debug.Print myClassInstance.myFunction(foo) '-- Prints 1000 to Immediate window
  
Simple :)
+
Simple :-)

Revision as of 20:44, 1 September 2005

This is actually extremely simple to do - all you need to do is declare the method (be it a property, function or sub) to which you are passing the UDT as Friend - like this:

 '-- In some module
 Public Type myType
     x As Integer
     y As Integer
 End Type
 
 '-- In the class
 Friend Function myFunction(foo As myType) As Integer
     myFunction = foo.x + foo.y
 End Function
 
 '-- Passing to the function
 Dim foo As myType
 foo.x = 10: foo.y = 100
 Debug.Print myClassInstance.myFunction(foo) '-- Prints 1000 to Immediate window

Simple :-)