Dear John, How Do I... Pass Any Type of Data in a Parameter?

Remember that Variant variables can contain just about any kind of data imaginable. This opens the door to passing any type of data you want to a parameter as long as the parameter has been declared as Variant. For example, in this code sample I've passed an integer, a string, and an array to a small procedure:

Option Explicit

Private Sub VariantTest(vntV)
    Print TypeName(vntV)
End Sub

Private Sub Form_Click()
    Dim dblA(3, 4, 5, 6, 7) As Double
    VariantTest 123
    VariantTest "This is a test string."
    VariantTest dblA
End Sub

The Variant parameter vntV, defined as the only parameter in the VariantTest procedure, accepts whatever you want to pass it. The TypeName function is then used to display the type of data that was passed.

Figure 4-2 shows the results of running this sample code.

Figure 4-2. Results of a procedure that uses a Variant parameter.