Actually Marty, you can pass a UDT to a sub however there are some rules to follow. If the type is private, which it must be if you declare it in a Form or in a private class module (a class module is private in a standard exe project and can optionally be so in other project types) then the Sub must be private. However if the UDT is public (declared in a regular module or in a public class) the sub can be either public or private.
It actually makes sense if you think about it. A Public Sub can be reach from any part of your project and if it requires a UDT, the UDT must also be publicly available or otherwise you will not be able to pass the correct values to it in some cases.VB Code:
'This works just fine Private Type MyType i As Integer s As String End Type Private Sub MySub(arg As MyType) Debug.Print arg.i, arg.s End Sub Private Sub Command1_Click() Dim t As MyType t.i = 1 t.s = "Hello world" MySub t End Sub




Reply With Quote