I have been teaching myself vb: I have defined a Type and want to pass that to other modules/subroutines. It works if all the code is within one module but am struggling to get it to pass the values to another module. Here is my test code that works in one module.
Type myNetwork1
myOne As String
myTwo As String
End Type
Dim theData As myNetwork1
Sub my123() 'Calls the public sub myTest1 to define my variables
MsgBox (theData.myOne) 'returns blank
MsgBox (theData.myTwo) 'returns blank
myTest1 myNetwork1 = myNetwork
MsgBox (theData.myOne) '123
MsgBox (theData.myTwo) '456
End Sub
Public Sub myTest1(ByRef myNetwork1)
theData.myOne = "123"
theData.myTwo = "456"
End Sub
The routine works in this instance. However, when I try pass the object between modules it returns an object error. Can you help me spot my ommision?
Note: I have been able to manage to return arguments on an individual basis but can't do it with a Type.
Module1
Sub my123() 'Want to call the public funtion in a different module
MsgBox (theData.myOne)
MsgBox (theData.myTwo)
myTest1 myNetwork1 = myNetwork
MsgBox (theData.myOne)
MsgBox (theData.myTwo)
End Sub
Module2
Type myNetwork1
myOne As String
myTwo As String
End Type
Dim theData As myNetwork1
Public Sub myTest1(ByRef myNetwork1)
theData.myOne = "123"
theData.myTwo = "456"
End Sub
Type myNetwork1
myOne As String
myTwo As String
End Type
Dim theData As myNetwork1
Sub my123() 'Calls the public sub myTest1 to define my variables
MsgBox (theData.myOne) 'returns blank
MsgBox (theData.myTwo) 'returns blank
myTest1 myNetwork1 = myNetwork
MsgBox (theData.myOne) '123
MsgBox (theData.myTwo) '456
End Sub
Public Sub myTest1(ByRef myNetwork1)
theData.myOne = "123"
theData.myTwo = "456"
End Sub
The routine works in this instance. However, when I try pass the object between modules it returns an object error. Can you help me spot my ommision?
Note: I have been able to manage to return arguments on an individual basis but can't do it with a Type.
Module1
Sub my123() 'Want to call the public funtion in a different module
MsgBox (theData.myOne)
MsgBox (theData.myTwo)
myTest1 myNetwork1 = myNetwork
MsgBox (theData.myOne)
MsgBox (theData.myTwo)
End Sub
Module2
Type myNetwork1
myOne As String
myTwo As String
End Type
Dim theData As myNetwork1
Public Sub myTest1(ByRef myNetwork1)
theData.myOne = "123"
theData.myTwo = "456"
End Sub
Comment