A project I'm working on needs to control communications on multiple comm ports on the PC. This must be done inside an ActiveX EXE. My problem is I do not know how many ports and therefore how many mscomm objects will be needed at design time. I use some code to create a control listed below:

Public WithEvents commObj As MSComm

Private Sub Form_Load()
Set commObj = Controls.Add("MSCommLib.MSComm", "commObj")
With commObj
.CommPort = 1
.Settings = "9600,e,7,1"
.RThreshold = 1
.PortOpen = True
End With
End Sub


How do I make Public Declarations such as above once my code determines how many serial ports I will need? (Need the component accessible from anywhere in the program)