Showing posts with label Project-SMS. Show all posts
Showing posts with label Project-SMS. Show all posts

Thursday, August 15, 2013

Contoh VB6 Kode Cek Stok SEV Indosat (STK)

Di bawah ini merupakan contoh kode yang digunakan untuk mengecek stok SEV Indosat.

Peralatan yang dibutuhkan:

  1. Modem GSM
  2. Kartu chip Indosat

Adapun kodenya adalah sebagai berikut:

Option Explicit 

'-----------------------------------------------------------------------------
'http://khoiriyyah.blogspot.com
'-----------------------------------------------------------------------------

Dim strBuffer As String

Private Sub cmdSend_Click()
txtResult.Text = ""
txtProcess.Text = ""
strBuffer = ""
If UCase$(Left$(txtATCommand.Text, 2)) <> "AT" Then
MSComm1.Output = txtATCommand.Text & Chr(26)
Else
MSComm1.Output = txtATCommand.Text & vbCrLf
End If
End Sub

Private Sub Form_Load()
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
With MSComm1
.CommPort = 3 'Port disesuaikan
.Settings = "115200,N,8,1"
.Handshaking = comRTS
.RTSEnable = True
.DTREnable = True
.RThreshold = 1
.SThreshold = 1
.InputMode = comInputModeText
.InputLen = 0
.PortOpen = True
End With
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
txtProcess.Text = strBuffer
txtProcess.SelStart = Len(txtProcess.Text)
Do
strBuffer = strBuffer & MSComm1.Input
Loop While MSComm1.InBufferCount

If InStr(1, strBuffer, "+STIN: 99" & vbCrLf) Then
MSComm1.Output = "AT+STGI=99" & vbCrLf
strBuffer = ""
ElseIf InStr(1, strBuffer, "+STIN: 9" & vbCrLf) Then
MSComm1.Output = "AT+STGI=9" & vbCrLf
strBuffer = ""
ElseIf InStr(1, strBuffer, "+STIN: 6" & vbCrLf) Then
MSComm1.Output = "AT+STGI=6" & vbCrLf
strBuffer = ""
ElseIf InStr(1, strBuffer, "+STIN: 3" & vbCrLf) Then
MSComm1.Output = "AT+STGI=3" & vbCrLf
strBuffer = ""
ElseIf InStr(1, strBuffer, "+STIN: 1" & vbCrLf) Then
MSComm1.Output = "AT+STGI=1" & vbCrLf
strBuffer = ""
End If

If InStr(1, strBuffer, "+STGI") Then
If InStr(1, strBuffer, "SEV Menu") Then
MSComm1.Output = "AT+STGR=0,1,3" & vbCrLf
strBuffer = ""
End If

If InStr(1, strBuffer, "Inventory") Then
MSComm1.Output = "AT+STGR=6,1,1" & vbCr
strBuffer = ""
End If
If InStr(1, strBuffer, "Optional") Then
MSComm1.Output = "AT+STGR=6,1,1" & vbCr
strBuffer = ""
End If
If InStr(1, strBuffer, "Enter MPIN") Then
MSComm1.Output = "AT+STGR=3,1" & vbCr
MSComm1.Output = "313131" & Chr(26) 'PIN disesuaikan, hati-hati 3x salah PIN kartu akan diblokir
strBuffer = ""
End If
End If

End Sub

Catatan penting:

  1. Sebelumnya kita harus mengaktifkan terlebih dahulu menu STK-nya seperti yang telah dijelaskan dalam posting disini.
  2. Setelah seluruhnya selesai, yang harus kita lakukan adalah mengetikan AT+STGI=0 dan klik tombol Send seperti yang terlihat pada gambar di bawah:

Cek STOK SEV Indosat
Gambar - Cek STOK SEV Indosat

Download: Contoh kode VB6 cek stok SEV Indosat

Keywords: contoh, cek, gambar, vb6, code, visual, basic, 6.0, contok, chek, kode, html, contohcek, stk, output, instr, indosat, contoh-contoh, coding, source, mscomm1.output

READ MORE - Contoh VB6 Kode Cek Stok SEV Indosat (STK)

Wednesday, December 12, 2012

Mengirim SMS Menggunakan Modem Wavecom - VB6 Code

Mengenai cara mengirim SMS menggunakan aplikasi yang dibuat dengan VB6 menggunakan modem GSM Wavecom - Adapun cara mengirim SMS menggunakan aplikasi VB6 secara sederhana kodenya adalah sebagai berikut:
Option Explicit

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Command1_Click()
With MSComm1
.CommPort = 7 'Port disesuaikan terhadap modem Wavecom yang terdeteksi
.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
Sleep 1000
MSComm1.Output = TxtMessage.Text & Chr(26)
End Sub

Caranya:

  1. Buatlah 2 TextBox masing-masing diberi nama TxtNumber dan TxtMessage
  2. Tambahkan OCX Microsoft Comm Control 6.0 (MSComm)
  3. Tambahkan satu CommandButton dengan nama default.
READ MORE - Mengirim SMS Menggunakan Modem Wavecom - VB6 Code

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.
READ MORE - Mengirim SMS Disertai Verifikasi Terkirim - VB Source Code

Fungsi Wait Sleep Tanpa Windows API - VB6 Code

Mengenai fungsi wait atau sleep tanpa menggunakan fungsi API - Melanjutkan posting sebelumnya klik disini, sekarang kita akan membuat fungsi sleep atau wait tanpa bantuan API hanya menggunakan kode VB6 murni. Perbedaan fungsi sleep kali ini dengan fungsi sleep sebelumnya adalah:

Fungsi sleep menggunakan Sleep Kernel32.dll:

  • Mem-freeze GUI (membekukan tampilan)
  • Hitungan dalam millisecond

Fungsi sleep kali ini (lebih tepatnya delay time):

  • Tidak mem-freeze GUI
  • Hitungan dalam second

Adapun fungsi sleep atau wait tanpa fungsi API adalah sebagai berikut:

Private Sub Sleep(ByVal HowLong As Date)
Dim endDate As Date
endDate = DateAdd("s", HowLong, Now)
While endDate > Now
DoEvents
Wend
End Sub
Jika Anda mau bereksperimen maka buatlah kodenya seperti di bawah ini kemudian bandingkan antara fungsi sleep Kernel32.dll dengan fungsi sleep tanpa API.
Option Explicit

'Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Command1_Click()
Label1.Caption = "Mulai menjalankan fungsi sleep atau wait"
Label1.Refresh
Sleep 5 'sleep/wait/hentikan eksekusi kode ke baris berikutnya selama 5 detik
Label1.Caption = "Terhenti selama 5 detik"
End Sub

Private Sub Command2_Click()
Dim frm As New Form1
frm.Show
End Sub

Private Sub Timer1_Timer()
Static i As Integer
Caption = i
i = i + 1
End Sub

Private Sub Sleep(ByVal HowLong As Date)
Dim endDate As Date
endDate = DateAdd("s", HowLong, Now)
While endDate > Now
DoEvents
Wend
End Sub
Demikianlah seputar fungsi sleep atau wait, menggunakan API dan tanpa menggunakan API.
Option Explicit

Private Function Sleep(mSecs As Long) As Double
Dim Duration!
Duration! = Timer + mSecs
Do Until Timer > Duration!
DoEvents
Loop
End Function

Private Sub Command1_Click()
Sleep 0.9
MsgBox "Test"
End Sub
READ MORE - Fungsi Wait Sleep Tanpa Windows API - VB6 Code

VB6 Code - Fungsi Sleep Atau Wait Yang Diperbaiki

Mengenai fungsi sleep atau wait dalam VB6 yang telah diperbaiki - Fungsi sleep disini berbeda dengan fungsi sleep sebelumnya yang menggunakaan salah satu API kernel32 klik disini atau tanpa API klik disini. Keunggulan dari fungsi sleep kali ini adalah:

  • Tidak memfreeze GUI (jadi jika ada objek visual, maka ia akan terefresh dengan baik)
  • Hitungan dalam millisecond.

Adapun fungsi sleep yang telah diperbaiki dengan menggunakan VB6 adalah sebagai berikut:

Option Explicit

Private mCancel As Boolean

Type MSG
hwnd As Long
message As Long
wParam As Long
lParam As Long
time As Long
ptX As Long
ptY As Long
End Type

Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function GetMessage Lib "user32" Alias "GetMessageA" (lpMsg As MSG, ByVal hwnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long) As Long
Private Declare Function TranslateMessage Lib "user32" (lpMsg As MSG) As Long
Private Declare Function DispatchMessage Lib "user32" Alias "DispatchMessageA" (lpMsg As MSG) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long

Private Sub TimerProc()
mCancel = True
End Sub

Public Sub Wait(frm As Form, mSecs As Long)
Dim MyMsg As MSG
Dim TimerID As Long

TimerID = SetTimer(frm.hwnd, ObjPtr(frm), mSecs, AddressOf TimerProc)
mCancel = False

Do While Not mCancel
GetMessage MyMsg, 0, 0, 0
TranslateMessage MyMsg
DispatchMessage MyMsg
Loop

KillTimer frm.hwnd, TimerID
End Sub
Demikian fungsi sleep dalam VB6 dengan menggunakan timer API. Semoga bermanfaat.
READ MORE - VB6 Code - Fungsi Sleep Atau Wait Yang Diperbaiki

VB6 SMS Gateway: Mendeteksi Port Modem Secara Otomatis

Mengenai cara mendeteksi port modem secara otomatis menggunakan VB6 - Pada project sebelumnya klik disini dan disini. Kita telah berhasil mengirimkan SMS menggunakan modem GSM secara sederhana. Akan tetapi karena sederhana kedua project tersebut tidak diperlengkapi dengan deteksi port modem secara otomatis, sehingga untuk mengetahui port modem Anda lakukan langkah di bawah ini:

  1. Klik tombol start (sebelah kiri bawah)
  2. Selanjutnya klik Settings >> Control Panel >> System
  3. Klik tab Hardware Klik tombol Device Manager
  4. Klik Node Ports (COM & LPT)
  5. Carilah di sana akan ada port modem Wavecom Anda.

Sungguh merepotkan sekali, setiap kali port modemnya berubah kita harus selalu mengulangi dan mengulangi langkah-langkah di atas. Mulai saat ini, tinggalkan cara di atas, dan beralihlah pada deteksi port modem secara otomatis. Adapun kode untuk mendeteksi port modem secara otomatis menggunakan VB6 adalah sebagai berikut:

Option Explicit

Dim strBuffer As String
Dim intPortNumber As String

Private Sub Command2_Click()
On Error Resume Next
Dim i As Integer
For i = 1 To 20
If MSComm1.PortOpen Then MSComm1.PortOpen = False
intPortNumber = i
MSComm1.CommPort = i
MSComm1.PortOpen = True
MSComm1.Output = "AT" & vbCrLf
Wait Me, 50
Next
End Sub

Private Sub Form_Load()
With MSComm1
.Settings = "115200,n,8,1"
.Handshaking = comRTS
.RTSEnable = True
.DTREnable = True
.RThreshold = 1
.SThreshold = 1
.InputMode = comInputModeText
.InputLen = 0
End With
End Sub

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

Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive
strBuffer = strBuffer & MSComm1.Input
End Select
Do
strBuffer = strBuffer & MSComm1.Input
Loop While MSComm1.InBufferCount
If InStr(1, strBuffer, "OK") > 0 Then
Caption = "COM" & intPortNumber
Text1.Text = intPortNumber
End If
End Sub
Demikian cara mendeteksi port modem secara otomatis menggunakan VB6, jika modemnya lebih dari 1, misalnya 2, 3, 8, 15 sampai tak terhingga, Anda hanya perlu sedikit memodifikasi kodenya. Semoga bermanfaat.
READ MORE - VB6 SMS Gateway: Mendeteksi Port Modem Secara Otomatis

VB6 SMS Gateway: Menambahkan Fitur Auto Reply

Mengenai cara membalas SMS secara otomatis melalui aplikasi VB6 - Sebelumnya kita telah membahas mengenai cara menerima SMS baru klik disini, nah sekarang kita akan menambahkan fitur auto reply melalui AT Commands dengan aplikasi VB6 yang kita buat sendiri. Adapun contoh kode VB6 membalas SMS otomatis adalah seperti di bawah ini:
Option Explicit

Dim strBuffer As String
Dim blnFirstLoad As Boolean

Private Sub Command1_Click()
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
With MSComm1
.PortOpen = True
.Output = "AT+CMGS=" & Chr(34) & TxtNumber.Text & Chr(34) & vbCrLf
.Output = TxtMessage.Text & Chr(26)
End With
End Sub

Private Sub Form_Load()
With MSComm1
.CommPort = 7 'port disesuaikan atau beri kode auto detect port modem
.Settings = "115200,N,8,1"
.Handshaking = comRTS
.RTSEnable = True
.DTREnable = True
.RThreshold = 1
.SThreshold = 1
.NullDiscard = True
.InputMode = comInputModeText
.InputLen = 0
.PortOpen = True
End With
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
Do
strBuffer = strBuffer & MSComm1.Input
Loop While MSComm1.InBufferCount
If InStr(1, strBuffer, "+CMGR") Then
If InStr(1, strBuffer, "OK") Then
Text1.Text = strBuffer
End If
End If
If InStr(1, strBuffer, "+CMTI") > 0 Then
If Right(strBuffer, 1) = vbLf Then
Dim s() As String
s = Split(strBuffer, ",")
Debug.Print s(UBound(s))
ReadSMSByIndex Trim$(s(UBound(s)))
Delay 1
Command1_Click 'Auto reply
strBuffer = ""
End If
End If
End Select
End Sub

Private Sub ReadSMSByIndex(Index As Integer)
strBuffer = ""
MSComm1.Output = "AT+CMGR=" & Index & vbCrLf 'baca SMS yang berada di index ke-1
End Sub

Private Sub Delay(ByVal HowLong As Date)
Dim endDate As Date
endDate = DateAdd("s", HowLong, Now)
While endDate > Now
DoEvents
Wend
End Sub
Demikian contoh kode VB6 untuk membalas SMS baru secara otomatis, Anda dapat memodifikasi kodenya untuk disesuaikan dengan kebutuhan.
READ MORE - VB6 SMS Gateway: Menambahkan Fitur Auto Reply

VB6 SMS Gateway: Contoh Mengekspor PhoneBook ke Excel

Private Sub ExportToExcel(PhoneBook As String)
Dim ExcelObj As New Excel.Application
Dim ExcelBook As Excel.Workbook
Dim ExcelSheet As Excel.Worksheet
Dim i As Integer

Set ExcelBook = ExcelObj.Workbooks.Add
Set ExcelSheet = ExcelBook.Worksheets(1)

Dim s() As String
Dim r As String

s = Split(PhoneBook, vbCrLf & "+CPBR:")

With ExcelSheet
.Columns("A:A").ColumnWidth = 7
.Columns("B:B").ColumnWidth = 16
.Columns("C:C").ColumnWidth = 16
.Columns("D:D").ColumnWidth = 16
For i = 1 To UBound(s)
If s(i - 1) <> "" Then
r = Split(s(i - 1), ",")(0)
If InStr(1, r, "+CPBR:") > 0 Then
r = Split(Split(s(i - 1), ",")(0), ":")(1)
Else
r = Split(Split(s(i - 1), ",")(0), ":")(0)
End If
.Cells(i, 1) = r
.Cells(i, 2) = Split(s(i - 1), ",")(1)
.Cells(i, 3) = Split(s(i - 1), ",")(2)
.Cells(i, 4) = Split(s(i - 1), ",")(3)
End If
Next
End With

ExcelObj.Visible = True
End Sub
READ MORE - VB6 SMS Gateway: Contoh Mengekspor PhoneBook ke Excel

VB6 SMS Gateway: AT Command Tester Sederhana

Option Explicit 

Dim strBuffer As String

Private Sub cmdSend_Click()
txtResult.Text = ""
txtProcess.Text = ""
strBuffer = ""
If UCase$(Left$(txtATCommand.Text, 2)) <> "AT" Then
MSComm1.Output = txtATCommand.Text & Chr(26)
Else
MSComm1.Output = txtATCommand.Text & vbCrLf
End If
End Sub

Private Sub Form_Load()
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
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
txtProcess.Text = strBuffer
txtProcess.SelStart = Len(txtProcess.Text)
Do
strBuffer = strBuffer & MSComm1.Input
Loop While MSComm1.InBufferCount
If InStr(1, strBuffer, "OK") > 0 Then
txtResult.Text = strBuffer
txtResult.SelStart = Len(txtResult.Text)
ElseIf InStr(1, strBuffer, "ERROR") Then
txtResult.Text = strBuffer
strBuffer = ""
End If
End Sub

Download: Source Code

READ MORE - VB6 SMS Gateway: AT Command Tester Sederhana