Nuevo código completo que aún tiene errores.
MSComm1.CommPort = ComboBoxCOM.ListIndex = 0
Private Sub Command_CONECTAR_Click()
If Not MSComm1.PortOpen Then
MSComm1.PortOpen = True ' Abrir puerto serie.
Command_CONECTAR.Caption = "DESCONECTAR"
Else
MSComm1.PortOpen = False ' Cerrar puerto serie.
Command_CONECTAR.Caption = "CONECTAR"
End If
End Sub
Private Sub Command_Led_8_OFF_Click()
MSComm1.Output = "Led_8_OFF"
End Sub
Private Sub Command_Led_8_ON_Click()
MSComm1.Output = "Led_8_ON"
End Sub
Private Sub Form_Load()
'Form1.ComboBoxCOM.Clear ' Limpiar comboBox.
MSComm1.CommPort = ComboBoxCOM.ListIndex = 0
Timer1.Interval = 1 ' Correr el timer a 1 mls.
Set WMIObjectSet = GetObject("winmgmts:\\.\root\CIMV2").ExecQuery("SELECT * FROM Win32_PnPEntity") 'Win32_SerialPort")
For Each wmiobject In WMIObjectSet
If InStr(wmiobject.Name, "COM") Then '
Form1.ComboBoxCOM.AddItem wmiobject.Name
End If
Next
Set WMIObjectSet = Nothing
End Sub
Saludos.
http://electronica-pic.blogspot.com