Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
Call Send_SMS(CPNumber.Text, SMSText.Text)
End Sub
Private Sub Form_Load()
On Error GoTo commErr
With MSComm1
.CommPort = 3
.Handshaking = comNone
.Settings = "9600,n,8,1"
If .PortOpen = False Then
.PortOpen = True
.DTREnable = True
.RTSEnable = True
.RThreshold = 1
.InputLen = 1
.Output = "AT" & vbCrLf
Sleep 500
.Output = "ATE0" & vbCrLf
Sleep 500
Else
MsgBox "Port Already Open"
End If
MsgBox "Connected"
Exit Sub
commErr:
If Err.Number = 8005 Then
MsgBox "Port is busy"
ElseIf Err.Number = 8002 Then
MsgBox "Invalid Port"
Exit Sub
End If
End With
End Sub
Private Function Send_SMS(ByVal Number As String, ByVal Text As String)
With MSComm1
.Output = "AT+CMGS=" & Chr(34) & Trim(Number) & Chr(34) & vbCrLf
Sleep 1000
.Output = Trim(Text) & Chr(26) & vbCrLf
Sleep 2000
If InStr(.Input, "OK") Then
MsgBox "Message Send"
Else
MsgBox "Message Not Send"
End If
End With
End Function
Private Sub Form_Unload(Cancel As Integer)
With MSComm1
If .PortOpen = True Then
.PortOpen = False
Sleep 500
End If
End
End With
End Sub
luv u full
BalasHapus