Passing type array event args

Basicfarmer used Ask the Experts™
Experts, I have an activeX.exe that is to keep tabs on the network status of several industrial inkjet printers on a network in a manufacturing environment. I have created a type and array of that type and I need to pass it to the client program in the arguments of an event. I keep getting an error stating "Type Mismatch: array of user defined type expected." Can you please show me what i am missing here. I am sure I have not delared something properly.

Below is some of my code. The error happens in the startComm procedure.

Private Type netComm

    ipAddress As String
    printerReady As Boolean
End Type

Private commStatus() As netComm

Public Sub startComm()

    Dim SQL As String, rs As DAO.Recordset, varLoop As Long
    printerCount = DCount("IPAddress", "Printers")

    'ReDim Preserve ipAddress(printerCount) As String
    'ReDim Preserve printerReady(printerCount) As Boolean
    ReDim tcp(printerCount) As tcp
    'ReDim Preserve printer(2, printerCount) As String
    ReDim commStatus(printerCount) As netComm
    SQL = "SELECT IPAddress FROM Printers"
    Set rs = currentDb.OpenRecordset(SQL)
    varLoop = 0
    Do While Not rs.EOF

        'printerReady(varLoop) = False
        'ipAddress(varLoop) = rs.Fields("IPAddress")
        'printer(0, varLoop) = rs.Fields("IPAddress")
        'printer(1, varLoop) = "Not Ready"
        commStatus(varLoop).ipAddress = rs.Fields("IPAddress")
        commStatus(varLoop).printerReady = False
        Set tcp(varLoop) = New tcp
        RaiseEvent onDisconnect(rs.Fields("IPAddress"))
        varLoop = varLoop + 1


    Set rs = Nothing
    RaiseEvent updateNet(commStatus())
    'commTimer.Enabled = True

End Sub
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I would start with trying this:

Public commStatus() As netComm 'make var public just to see if this is it

RaiseEvent updateNet(commStatus) 'remove the ()



I get the error that user defined types cannot be part of public scope.

I think this is my problem.
Top Expert 2010
Try something like this....
' YourClass.cls

Option Explicit

Event updateNet(ByRef arr() As netCom)

Private commStatus() As netCom

Public Sub startComm()

  Dim i                 As Long
  ReDim commStatus(10) As netCom
  For i = LBound(commStatus) To UBound(commStatus)
    Set commStatus(i) = New netCom
    commStatus(i).ipAddress = "" & i
  Next i
  RaiseEvent updateNet(commStatus())
End Sub

Private Sub cleanUp()
  Dim i As Long
  For i = LBound(commStatus) To UBound(commStatus)
  Set commStatus(i) = Nothing
  Next i
  Erase commStatus
End Sub

' netCom.cls

Option Explicit

Private m_ipAddress          As String
Private m_printerReady       As Boolean

Friend Property Let ipAddress(ByVal szipAddress As String)
  m_ipAddress = szipAddress
End Property

Public Property Get ipAddress() As String
  ipAddress = m_ipAddress
End Property

Friend Property Let printerReady(ByVal bReady As Boolean)
  m_printerReady = bReady
End Property

Public Property Get printerReady() As Boolean
  printerReady = m_printerReady
End Property

Open in new window

I think you may have a scoping problem.  First off, when I have strange problems like this that I know should work, I go back to plain vanilla: create a separate app that has only the simple concept you are trying to create.  

Where is your event "updateNet" defined (should be in the same module as the code above) and how is it defined.  Can you show it?

Just checking, is this a form module?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial