Option Explicit
Private Sub Form_Load()
Dim s As String
Dim iPort As Integer
Dim n As Single
Dim bModem As Boolean
For iPort = 1 To 4
With MSComm1
.CommPort = iPort
.Settings = "9600,N,8,1"
.InputLen = 0
On Error Resume Next
.PortOpen = True
If Err = 0 Then
.Output = "ATV1Q0" & Chr$(13)
n = Timer
While Timer - n < 1
DoEvents
Wend
s = s & .Input
.PortOpen = False
If InStr(s, "OK" & vbCrLf) <> 0 Then
MsgBox "Modem detected on COM" & iPort
bModem = True
Exit For
End If
End If
End With
Next
If Not bModem Then MsgBox "No modem detected"
End
End Sub