在VB中使用MSComm控件发短信但不能触发OnComm下的comEvReceive事件
dim strReceive as String
Private Sub Form_Load()
With Me.MSComm1
.CommPort = 1
.Settings = "9600,n,8,1"
.OutBufferCount = 0
.InBufferCount = 0
.RThreshold = 1
.PortOpen = True
End With
End Sub
Private Sub Command1_Click()
Me.MSComm1.Output = "AT+CMGS = +8613912121212" & Chr(13) & "Please don't reply this SMS." & Chr(26)
End Sub
Private Sub MSComm1_OnComm()
Select Case Me.MSComm1.CommEvent
Case comEvReceive
Me.MSComm1.RThreshold = 0
Me.MSComm1.InputLen = 0
Me.MSComm1.InputMode = comInputModeText
strReceive = strReceive & Me.comSMS.Input
If InStr(strReceive, "OK" & vbCrLf) <> 0 Or InStr(strReceive, "ERROR" & vbCrLf) <> 0 Then
MsgBox strReceive
strReceive = ""
End If
Me.MSComm1.RThreshold = 1
Case comEvRing
MsgBox "Ring"
Me.MSComm1.Output = "ATH" & Chr(13)
End Select
End Sub
Private Sub Form_Unload(Cancel As Integer)
Me.MSComm1.PortOpen = False
End Sub