You are on page 1of 7

VERSION 5.00 Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX" Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx" Begin VB.

Form Form1 BorderStyle = 1 'Fixed Single Caption = "AT Command Console" ClientHeight = 7245 ClientLeft = 45 ClientTop = 735 ClientWidth = 7410 LinkTopic = "Form1" MaxButton = 0 'False ScaleHeight = 7245 ScaleWidth = 7410 StartUpPosition = 2 'CenterScreen Begin MSComctlLib.StatusBar StatusBar1 Align = 2 'Align Bottom Height = 375 Left = 0 TabIndex = 8 Top = 6870 Width = 7410 _ExtentX = 13070 _ExtentY = 661 _Version = 393216 BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} NumPanels = 2 BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} Style = 6 Alignment = 1 TextSave = "01/07/2012" EndProperty BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628} Style = 5 Alignment = 1 TextSave = "12:45 AM" EndProperty EndProperty End Begin MSCommLib.MSComm MSComm1 Left = 1140 Top = 1920 _ExtentX = 1005 _ExtentY = 1005 _Version = 393216 DTREnable = -1 'True End Begin VB.Frame Frame1 Caption = "&Kirim Pesan" Height = 1275 Left = 60 TabIndex = 4 Top = 180 Width = 7155 Begin VB.CommandButton Command1 Caption = "Kirim" Enabled = 0 'False Height = 375 Left = 5520 TabIndex = 7

Top Width

= =

360 1395

End Begin VB.TextBox TxtMessage Height = 795 Left = 120 TabIndex = 6 Top = 300 Width = 5295 End Begin VB.TextBox TxtNumber Height = 315 Left = 5520 TabIndex = 5 Top = 780 Width = 1395 End End Begin VB.TextBox Text3 Height = 1395 Left = 60 MultiLine = -1 'True ScrollBars = 2 'Vertical TabIndex = 2 Top = 5400 Width = 7215 End Begin MSComctlLib.ListView ListView1 Height = 2055 Left = 60 TabIndex = 1 Top = 3000 Width = 7215 _ExtentX = 12726 _ExtentY = 3625 View = 3 LabelEdit = 1 LabelWrap = -1 'True HideSelection = -1 'True FullRowSelect = -1 'True GridLines = -1 'True _Version = 393217 ForeColor = -2147483640 BackColor = -2147483643 BorderStyle = 1 Appearance = 0 NumItems = 5 BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} Text = "No." Object.Width = 882 EndProperty BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628} SubItemIndex = 1 Text = "No. Tel/HP" Object.Width = 2540 EndProperty BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628} Alignment = 1 SubItemIndex = 2 Text = "Tanggal"

Object.Width = 2540 EndProperty BeginProperty ColumnHeader(4) {BDD1F052-858B-11D1-B16A-00C0F0283628} Alignment = 1 SubItemIndex = 3 Text = "Jam" Object.Width = 3175 EndProperty BeginProperty ColumnHeader(5) {BDD1F052-858B-11D1-B16A-00C0F0283628} SubItemIndex = 4 Text = "Pesan" Object.Width = 4410 EndProperty End Begin VB.TextBox Text1 Height = 1335 Left = 60 MultiLine = -1 'True ScrollBars = 2 'Vertical TabIndex = 0 Top = 1560 Width = 7215 End Begin VB.Label Label1 Caption = "Pesan:" Height = 255 Left = 120 TabIndex = 3 Top = 5160 Width = 1455 End Begin VB.Menu mnuActions Caption = "&Actions" Visible = 0 'False Begin VB.Menu mnuReply Caption = "&Reply" End Begin VB.Menu mnuDeleteCurrent Caption = "&Delete This" End End Begin VB.Menu mnuSMS Caption = "&SMS" Begin VB.Menu mnuReadAll Caption = "&Read All" End Begin VB.Menu mnuReadByIndex Caption = "&Read By Index" End End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Dim strBuffer As String Dim blnFirstLoad As Boolean

Private Sub Command1_Click() ActionsATCommands "AT+CMGS=" & Chr(34) & TxtNumber.Text & Chr(34) & vbCrLf TxtMessage.Text = "" End Sub Private Sub ActionsATCommands(ATCommand As String, Optional Actions As String = "Send") If MSComm1.PortOpen = True Then MSComm1.PortOpen = False With MSComm1 .PortOpen = True .Output = ATCommand If Actions = "Send" Then .Output = TxtMessage.Text & Chr(26) End If 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 ButtonOKEnabled End Sub Private Sub Form_Unload(Cancel As Integer) Do While MSComm1.PortOpen = False MSComm1.PortOpen = False Loop End Sub Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem) Text3.Text = ListView1.SelectedItem.ListSubItems(4).Text End Sub Private Sub ListView1_MouseDown(Button As Integer, Shift As Integer, x As Single , y As Single) mnuReply.Enabled = Not ListView1.SelectedItem Is Nothing If Button = vbRightButton Then PopupMenu mnuActions End If End Sub Private Sub mnuDeleteCurrent_Click() If MsgBox("Are you sure want to delete this SMS", vbQuestion + vbYesNo, "Del ete Confirmation") = vbNo Then Exit Sub ActionsATCommands "AT+CMGD=" & Trim$(Mid$(ListView1.SelectedItem.Key, 2, Len (ListView1.SelectedItem.Key))) & vbCrLf, "DeleteByIndex" ListView1.ListItems.Remove ListView1.SelectedItem.Index End Sub

Private Sub mnuReadAll_Click() ListView1.ListItems.Clear Text1.Text = "" strBuffer = "" ActionsATCommands "AT+CMGL=" & Chr(34) & "ALL" & Chr(34) & vbCrLf, "ReadAll" End Sub Private Sub mnuReadByIndex_Click() ListView1.ListItems.Clear strBuffer = "" Dim i As String i = InputBox("Insert SMS index", "Read SMS by Index") If Not IsNumeric(i) Then Exit Sub ActionsATCommands "AT+CMGR=" & i & vbCrLf, "ReadByIndex" End Sub Private Sub mnuReply_Click() TxtMessage.Text = "" TxtMessage.SetFocus TxtNumber.Text = ListView1.SelectedItem.ListSubItems(1).Text 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, vbCrLf & vbCrLf & "OK") Then Text1.Text = strBuffer Call InsertToListView(strBuffer) strBuffer = "" End If End If If InStr(1, strBuffer, "+CMGL") Then Text3.Text = strBuffer Text3.SelStart = Len(Text3.Text) If InStr(1, strBuffer, vbCrLf & vbCrLf & "OK") Then Text1.Text = strBuffer Text1.SelStart = Len(Text1.Text) Call InsertToListViewCGML(strBuffer) 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))) PlaySound "NewMessage.wav" Delay 1 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 Private Function InsertToListView(sBuffer As String) Dim s As String Dim x() As String Dim g() As String Dim i As Integer s = sBuffer Dim n As MSComctlLib.ListItem Select Case True Case InStr(1, s, "+CMGR:") > 0 g = Split(s, vbCrLf) For i = 0 To UBound(g) If InStr(1, g(i), "+CMGR:") Then With ListView1.ListItems Set n = .Add(, , ListView1.ListItems.Count + 1) n.ListSubItems.Add , , Replace(Split(g(i), ",")(1), Chr( 34), "") n.ListSubItems.Add , , Replace(Split(g(i), ",")(3), Chr( 34), "") n.ListSubItems.Add , , Replace(Split(g(i), ",")(4), Chr( 34), "") n.ListSubItems.Add , , g(i + 1) End With End If Next ListView1.ListItems(ListView1.ListItems.Count).EnsureVisible Text3.Text = ListView1.ListItems(ListView1.ListItems.Count).ListSubI tems(4).Text ListView1.SetFocus ListView1.ListItems(ListView1.ListItems.Count).Selected = True End Select End Function Private Function InsertToListViewCGML(sBuffer As String) Dim s As String Dim x() As String Dim g() As String Dim i As Integer s = sBuffer Dim n As MSComctlLib.ListItem Select Case True Case InStr(1, s, "+CMGL:") > 0 g = Split(s, vbCrLf) For i = 0 To UBound(g) If InStr(1, g(i), "+CMGL:") Then With ListView1.ListItems

Set n = .Add(, , ListView1.ListItems.Count + 1) n.ListSubItems.Add , , Replace(Split(g(i), ",")(2), Chr( 34), "") n.ListSubItems.Add , , Replace(Split(g(i), ",")(4), Chr( 34), "") n.ListSubItems.Add , , Replace(Split(g(i), ",")(5), Chr( 34), "") n.ListSubItems.Add , , g(i + 1) n.Key = "a" & Trim$(Replace(Split(g(i), ",")(0), "+CMGL: ", "")) End With End If Next ListView1.ListItems(ListView1.ListItems.Count).EnsureVisible Text3.Text = ListView1.ListItems(ListView1.ListItems.Count).ListSubI tems(4).Text End Select End Function Private Sub TxtMessage_Change() ButtonOKEnabled End Sub Public Sub ButtonOKEnabled() Command1.Enabled = (TxtMessage.Text <> "" And TxtNumber.Text <> "") End Sub Private Sub TxtNumber_Change() ButtonOKEnabled End Sub

You might also like