Wednesday, December 12, 2012

Mengirim SMS Disertai Verifikasi Terkirim - VB Source Code

Mengenai mengirim SMS menggunakan modem wavecom melalui aplikasi yang dibuat menggunakan VB6 - Ini merupakan kelanjutan dari project sebelumnya, pada kesempatan kali, kita akan menambahkan fitur verifikasi, apakah SMS telah terkirim atau gagal terkirim. Nah, bagaimanakah kode untuk mengirim SMS menggunakan modem wavecom melalui aplikasi VB6 yang disertai pesan verifikasi? berikut adalah kodenya:
Option Explicit

Dim strBuffer As String

Private Sub Command1_Click()
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
With MSComm1
.CommPort = 7
.Settings = "115200,N,8,1"
.Handshaking = comRTS
.RTSEnable = True
.DTREnable = True
.RThreshold = 1
.SThreshold = 1
.InputMode = comInputModeText
.InputLen = 0
.PortOpen = True
End With
MSComm1.Output = "AT+CMGS=" & Chr(34) & TxtNumber.Text & Chr(34) & vbCrLf
Delay 1
MSComm1.Output = TxtMessage.Text & Chr(26)
If WaitForSuccess Then
MsgBox "SMS telah terkirim", vbInformation + vbOKOnly
Else
MsgBox "SMS gagal terkirim", vbCritical, "SMS Gagal"
End If

End Sub

Private Sub Form_Unload(Cancel As Integer)
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
End Sub

Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive
strBuffer = strBuffer & MSComm1.Input
End Select
Debug.Print strBuffer
End Sub

Private Function WaitForSuccess() As Boolean
Dim i As Integer
Dim strInput As String
Dim strPart As String
Dim c As String, b As String
For i = 1 To 5
Do
Delay 1
c = strBuffer
strBuffer = ""
If c = "" Then Exit Do
b = strInput & c
Loop
strPart = b
strInput = strInput & strPart
If InStr(1, strInput, vbCrLf & "OK" & vbCrLf) > 0 Then Exit For
If strPart = "" Then
Delay 1
End If
Next
WaitForSuccess = InStr(1, strInput, vbCrLf & "OK" & vbCrLf) > 0
End Function

Private Sub Delay(ByVal HowLong As Date)
Dim endDate As Date
endDate = DateAdd("s", HowLong, Now)
While endDate > Now
DoEvents
Wend
End Sub
Demikian mengenai cara mengirim SMS menggunakan modem wavecom melalui aplikasi VB6 yang ditambahkan fitur verifikasi, semoga bermanfaat.