home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / Sms_Sender2097221132008.psc / SmsSender / GSM.ctl < prev   
Text File  |  2008-01-13  |  54KB  |  1,361 lines

  1. VERSION 5.00
  2. Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
  3. Begin VB.UserControl GSM 
  4.    ClientHeight    =   510
  5.    ClientLeft      =   0
  6.    ClientTop       =   0
  7.    ClientWidth     =   495
  8.    ControlContainer=   -1  'True
  9.    DataBindingBehavior=   1  'vbSimpleBound
  10.    DataSourceBehavior=   1  'vbDataSource
  11.    EditAtDesignTime=   -1  'True
  12.    InvisibleAtRuntime=   -1  'True
  13.    Picture         =   "GSM.ctx":0000
  14.    ScaleHeight     =   510
  15.    ScaleWidth      =   495
  16.    ToolboxBitmap   =   "GSM.ctx":0442
  17.    Begin MSCommLib.MSComm MSComm 
  18.       Left            =   120
  19.       Top             =   600
  20.       _ExtentX        =   1005
  21.       _ExtentY        =   1005
  22.       _Version        =   393216
  23.       DTREnable       =   -1  'True
  24.    End
  25. End
  26. Attribute VB_Name = "GSM"
  27. Attribute VB_GlobalNameSpace = False
  28. Attribute VB_Creatable = True
  29. Attribute VB_PredeclaredId = False
  30. Attribute VB_Exposed = False
  31. Option Explicit
  32. Private mSpeed As String
  33. Event Response(ByVal Result As String)
  34. Private mCommPort As Integer
  35. Private mPortOpen As Boolean
  36. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  37. Private Const LVSCW_AUTOSIZE_USEHEADER As Long = -2
  38. Private Const LVM_FIRST As Long = &H1000
  39. Private Const LVM_SETCOLUMNWIDTH As Long = (LVM_FIRST + 30)
  40. Private m_Buffer As String
  41. Private mLogFile As String
  42. Private mReadDelete As String
  43. Private mWriteSend As String
  44. Private mReceived As String
  45. Private mReceivedUsed As Long
  46. Private mReceivedCapacity As Long
  47. Private mReadDeleteUsed As Long
  48. Private mReadDeleteCapacity As Long
  49. Private mWriteSendUsed As String
  50. Private mWriteSendCapacity As String
  51. Private mpbMemory As String
  52. Private mpbCapacity As Long
  53. Private mpbUsed As Long
  54. Private resultPos As Long
  55. '>>>>>>>>>>> obtained from planet source code to receive
  56. '>>>>>>>>>>> pdu messages
  57. Private mvarnoSCA As String
  58. Private mvarnoOA As String
  59. Private mvarFO As String
  60. Private mvarDCS As String
  61. Private mvarSCTS_Tgl As String
  62. Private mvarSCTS_Jam As String
  63. Private mvarSCTS_Tgl_A As String
  64. Private mvarSCTS_Jam_A As String
  65. Private mvarIndexSend As String
  66. Private mvarUDL As String
  67. '>>>>>>>>>>>>>
  68. Public Enum FindWhere
  69.     Search_Text = 0
  70.     Search_SubItem = 1
  71.     Search_Tag = 2
  72. End Enum
  73. Public Enum SearchType
  74.     Search_Partial = 1
  75.     Search_Whole = 0
  76. End Enum
  77. Public Enum SmsMemoryStorageEnum
  78.     SimMemory = 0
  79.     MobileEquipmentMemory = 1
  80.     BothMemories = 2
  81.     ReadMemorySetting = 3
  82.     BroadcastMessageStorage = 4
  83.     StatusReportStorage = 5
  84.     TerminalAdapterStorage = 6
  85. End Enum
  86. Public Enum MessageFormatEnum
  87.     TextFormat = 1
  88.     PDUFormat = 0
  89.     ReadFormat = 2
  90. End Enum
  91. Public Enum EchoEnum
  92.     EchoOff = 0
  93.     EchoOn = 1
  94. End Enum
  95. Public Enum PhoneBookMemoryStorageEnum
  96.     SimPhoneBook = 0
  97.     MobileEquipmentPhoneBook = 1
  98.     BothPhoneBooks = 2
  99.     ReadPhoneBookSetting = 3
  100.     SupportedMemory = 4
  101. End Enum
  102. Public Enum CentreNumberEnum
  103.     SetCentreNumber = 0
  104.     ReadCentreNumber = 1
  105. End Enum
  106. Public Enum SmsTypesEnum
  107.     RecRead = 0
  108.     RecUnread = 1
  109.     Rec = 2
  110.     StoSent = 3
  111.     StoUnsent = 4
  112.     All = 5
  113. End Enum
  114. Public Enum PDUFlashMessageTypeEnum
  115.     ' flash = 00, non flash = F0
  116.     NonFlash = 0
  117.     Flash = 1
  118. End Enum
  119. Public Enum PDUDisplayReportSMSEnum
  120.     ' yes = 31, no = 11
  121.     YesReport = 1
  122.     NoReport = 0
  123. End Enum
  124. Public Enum PDULimitPeriodOfDeliveryEnum
  125.     ' 1=1hour,2=12hour,3=1day(default),4=2day,5=1week
  126.     OneHour = 1
  127.     TwelveHours = 2
  128.     OneDay = 3
  129.     TwoDays = 4
  130.     OneWeek = 5
  131. End Enum
  132. Public Enum PhoneBookMemoryToFormatEnum
  133.     SimPhoneBookFormat = 0
  134.     MobileEquipmentPhoneBookFormat = 1
  135. End Enum
  136. Public Enum WriteLocationEnum
  137.     WriteRecRead = 0
  138.     WriteRecUnread = 1
  139.     WriteStoSent = 3
  140.     WriteStoUnsent = 4
  141. End Enum
  142. Public Enum ModemTypeEnum
  143.     DataCard = 0
  144.     Cellphone = 1
  145. End Enum
  146. Private nModemType As ModemTypeEnum
  147. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  148. Public Property Get CommPort() As Integer
  149.     On Error Resume Next
  150.     ' get the port used by the modem
  151.     CommPort = mCommPort
  152.     Err.Clear
  153. End Property
  154. Public Property Let CommPort(nCommPort As Integer)
  155.     On Error Resume Next
  156.     ' set the port to use for the modem connection
  157.     MSComm.CommPort = nCommPort
  158.     mCommPort = nCommPort
  159.     PropertyChanged "CommPort"
  160.     Err.Clear
  161. End Property
  162. Public Property Get ModemType() As ModemTypeEnum
  163.     On Error Resume Next
  164.     ' get the modem type
  165.     ModemType = nModemType
  166.     Err.Clear
  167. End Property
  168. Public Property Let ModemType(newModemType As ModemTypeEnum)
  169.     On Error Resume Next
  170.     ' set the modem type
  171.     nModemType = newModemType
  172.     If nModemType = Cellphone Then
  173.         resultPos = 3
  174.     ElseIf nModemType = DataCard Then
  175.         resultPos = 2
  176.     End If
  177.     PropertyChanged "ModemType"
  178.     Err.Clear
  179. End Property
  180. Private Function FixSmsDate(sDate As String) As String
  181.     On Error Resume Next
  182.     Dim syyyy As String
  183.     Dim smm As String
  184.     Dim sdd As String
  185.     syyyy = MvField(sDate, 1, "/")
  186.     smm = MvField(sDate, 2, "/")
  187.     sdd = MvField(sDate, 3, "/")
  188.     sdd = sdd & "/" & smm & "/" & syyyy
  189.     FixSmsDate = Format$(sdd, "dd/mm/yyyy")
  190.     Err.Clear
  191. End Function
  192. Public Property Get LogFile() As String
  193.     On Error Resume Next
  194.     ' get the path of the log file
  195.     LogFile = mLogFile
  196.     Err.Clear
  197. End Property
  198. Public Property Let LogFile(nLogFile As String)
  199.     On Error Resume Next
  200.     ' set the path of the log file
  201.     mLogFile = nLogFile
  202.     PropertyChanged "LogFile"
  203.     Err.Clear
  204. End Property
  205. Public Property Get Settings() As String
  206.     On Error Resume Next
  207.     ' get the settings of the modem
  208.     Settings = MSComm.Settings
  209.     Err.Clear
  210. End Property
  211. Public Property Get VM() As String
  212.     On Error Resume Next
  213.     ' value delimiter
  214.     VM = Chr$(253)
  215.     Err.Clear
  216. End Property
  217. Public Property Get FM() As String
  218.     On Error Resume Next
  219.     ' value delimiter
  220.     FM = Chr$(254)
  221.     Err.Clear
  222. End Property
  223. Public Property Get Quote() As String
  224.     On Error Resume Next
  225.     ' value double quote
  226.     Quote = Chr$(34)
  227.     Err.Clear
  228. End Property
  229. Public Property Get Speed() As String
  230.     On Error Resume Next
  231.     ' get the speed of the modem
  232.     Speed = mSpeed
  233.     Err.Clear
  234. End Property
  235. Public Property Let Speed(nSpeed As String)
  236.     On Error Resume Next
  237.     ' set the speed of the modem, this will change settings
  238.     mSpeed = nSpeed
  239.     MSComm.Settings = nSpeed & ",n,8,1"
  240.     PropertyChanged "Speed"
  241.     PropertyChanged "Settings"
  242.     Err.Clear
  243. End Property
  244. Public Property Get PortOpen() As Boolean
  245.     On Error Resume Next
  246.     ' get the status of the port
  247.     PortOpen = mPortOpen
  248.     Err.Clear
  249. End Property
  250. Public Property Let PortOpen(nPortOpen As Boolean)
  251.     On Error GoTo ErrMsg
  252.     ' set the status of the port
  253.     MSComm.PortOpen = nPortOpen
  254.     mPortOpen = nPortOpen
  255.     PropertyChanged "PortOpen"
  256.     Err.Clear
  257.     Exit Property
  258. ErrMsg:
  259.     RaiseEvent Response(Err.Description)
  260.     Err.Clear
  261. End Property
  262. Private Sub MSComm_OnComm()
  263.     On Error Resume Next
  264.     ' read contents of the data sent by modem
  265.     Select Case MSComm.CommEvent
  266.     Case comEvReceive
  267.         m_Buffer = MSComm.Input
  268.     End Select
  269.     Err.Clear
  270. End Sub
  271. Public Function Connect(MyPort As String, MySpeed As String) As String
  272.     On Error Resume Next
  273.     ' connect to the gsm modem by specifying the port number and speed of the modem
  274.     If MSComm.PortOpen = True Then MSComm.PortOpen = False
  275.     Me.CommPort = Val(MyPort)
  276.     Me.Speed = MySpeed
  277.     MSComm.DTREnable = True
  278.     MSComm.RTSEnable = True
  279.     MSComm.RThreshold = 1
  280.     MSComm.InBufferSize = 1024
  281.     Me.PortOpen = True
  282.     Me.Echo EchoOn
  283.     Connect = IIf(Me.PortOpen = True, "OK", "ERROR")
  284.     Err.Clear
  285. End Function
  286. Public Property Get ManufacturerIdentification() As String
  287.     On Error Resume Next
  288.     ' get the gadget manufacturer identification
  289.     ManufacturerIdentification = Request("AT+GMI", , resultPos, vbCrLf)
  290.     RaiseEvent Response(ManufacturerIdentification)
  291.     Err.Clear
  292. End Property
  293. Public Property Get ModemSerialNumber() As String
  294.     On Error Resume Next
  295.     ' get the gadget modem serial/imei number
  296.     ModemSerialNumber = Request("AT+GSN", , resultPos, vbCrLf)
  297.     RaiseEvent Response(ModemSerialNumber)
  298.     Err.Clear
  299. End Property
  300. Public Property Get RevisionIdentification() As String
  301.     On Error Resume Next
  302.     ' get the gadget revision identification
  303.     Dim mAnswer As String
  304.     mAnswer = Request("AT+GMR", , resultPos, vbCrLf)
  305.     RevisionIdentification = MvField(mAnswer, 2, ":")
  306.     RaiseEvent Response(RevisionIdentification)
  307.     Err.Clear
  308. End Property
  309. Public Property Get ModelIdentification() As String
  310.     On Error Resume Next
  311.     ' get the gadget model indentification number
  312.     ModelIdentification = Request("AT+GMM", , resultPos, vbCrLf)
  313.     RaiseEvent Response(ModelIdentification)
  314.     Err.Clear
  315. End Property
  316. Public Function SMS_NewMessageIndicate(bSet As Boolean) As String
  317.     On Error Resume Next
  318.     ' tell the gadget to notify computer of new sms received
  319.     If bSet = True Then
  320.         SMS_NewMessageIndicate = Request("AT+CNMI=1,1,0,0,0", , resultPos, vbCrLf)
  321.     Else
  322.         SMS_NewMessageIndicate = Request("AT+CNMI=0,0,0,0,0", , resultPos, vbCrLf)
  323.     End If
  324.     RaiseEvent Response(SMS_NewMessageIndicate)
  325.     Err.Clear
  326. End Function
  327. Public Property Get SignalQualityMeasure() As String
  328.     On Error Resume Next
  329.     ' read the signal of the phone and return it as a percentage
  330.     ' the maximum signal is 31
  331.     Dim mAnswer As String
  332.     mAnswer = Request("AT+CSQ", , resultPos, vbCrLf)
  333.     mAnswer = MvField(mAnswer, 2, ":")
  334.     mAnswer = MvField(mAnswer, 1, ",")
  335.     mAnswer = (Val(mAnswer) / 31) * 100
  336.     SignalQualityMeasure = Round(mAnswer, 0)
  337.     RaiseEvent Response(SignalQualityMeasure)
  338.     Err.Clear
  339. End Property
  340. Public Function PhoneBook_MemoryStorage(PhoneBookSelect As PhoneBookMemoryStorageEnum) As String
  341.     On Error Resume Next
  342.     ' select gadget phonebook memory
  343.     Dim mAnswer As String
  344.     Select Case PhoneBookSelect
  345.     Case SimPhoneBook
  346.         mAnswer = Request("AT+CPBS=" & Me.Quote & "SM" & Me.Quote, "", resultPos, vbCrLf)
  347.         mAnswer = Request("AT+CPBS?", , resultPos, vbCrLf)
  348.         mAnswer = MvField(mAnswer, 2, ":")
  349.         mAnswer = Replace$(mAnswer, Me.Quote, "")
  350.         mpbCapacity = MvField(mAnswer, 3, ",")
  351.         mpbUsed = MvField(mAnswer, 2, ",")
  352.         mpbMemory = MvField(mAnswer, 1, ",")
  353.     Case MobileEquipmentPhoneBook
  354.         mAnswer = Request("AT+CPBS=" & Me.Quote & "ME" & Me.Quote, "", resultPos, vbCrLf)
  355.         mAnswer = Request("AT+CPBS?", , resultPos, vbCrLf)
  356.         mAnswer = MvField(mAnswer, 2, ":")
  357.         mAnswer = Replace$(mAnswer, Me.Quote, "")
  358.         mpbCapacity = MvField(mAnswer, 3, ",")
  359.         mpbUsed = MvField(mAnswer, 2, ",")
  360.         mpbMemory = MvField(mAnswer, 1, ",")
  361.     Case BothPhoneBooks
  362.         mAnswer = Request("AT+CPBS=" & Me.Quote & "MT" & Me.Quote, "", resultPos, vbCrLf)
  363.         mAnswer = Request("AT+CPBS?", , resultPos, vbCrLf)
  364.         mAnswer = MvField(mAnswer, 2, ":")
  365.         mAnswer = Replace$(mAnswer, Me.Quote, "")
  366.         mpbCapacity = MvField(mAnswer, 3, ",")
  367.         mpbUsed = MvField(mAnswer, 2, ",")
  368.         mpbMemory = MvField(mAnswer, 1, ",")
  369.     Case ReadPhoneBookSetting
  370.         mAnswer = Request("AT+CPBS?", , resultPos, vbCrLf)
  371.         mAnswer = MvField(mAnswer, 2, ":")
  372.         mAnswer = Replace$(mAnswer, Me.Quote, "")
  373.         mpbCapacity = MvField(mAnswer, 3, ",")
  374.         mpbUsed = MvField(mAnswer, 2, ",")
  375.         mpbMemory = MvField(mAnswer, 1, ",")
  376.     Case SupportedMemory = 4
  377.         'mAnswer = Request("AT+CPBS=?", , resultPos, vbCrLf)
  378.         mAnswer = Request("AT+CPBS=?", , , vbCrLf)
  379.     End Select
  380.     PhoneBook_MemoryStorage = mAnswer
  381.     RaiseEvent Response(PhoneBook_MemoryStorage)
  382.     Err.Clear
  383. End Function
  384. Public Function PhoneBook_ReadEntry(Location As Long) As String
  385.     On Error Resume Next
  386.     ' read a specified phonebook entry using a location
  387.     ' an empty location returns blank
  388.     Dim mAnswer As String
  389.     Dim mLoc As String
  390.     Dim mNum As String
  391.     Dim mNam As String
  392.     mAnswer = Request("AT+CPBR=" & Location, , resultPos, vbCrLf)
  393.     mAnswer = Replace$(mAnswer, Me.Quote, "")
  394.     mAnswer = Trim$(Replace$(mAnswer, "+CPBR:", ""))
  395.     Select Case LCase$(mAnswer)
  396.     Case "not found", "+cme error: not found", ""
  397.         mAnswer = ""
  398.     Case Else
  399.         mLoc = MvField(mAnswer, 1, ",")
  400.         mNum = MvField(mAnswer, 2, ",")
  401.         mNam = MvField(mAnswer, 4, ",")
  402.         mAnswer = mLoc & "," & mNum & "," & mNam
  403.     End Select
  404.     PhoneBook_ReadEntry = mAnswer
  405.     RaiseEvent Response(PhoneBook_ReadEntry)
  406.     Err.Clear
  407. End Function
  408. Public Function PhoneBook_FindEntry(FullName As String) As String
  409.     On Error Resume Next
  410.     ' search for a phonebook entry and return result
  411.     Dim mAnswer As String
  412.     mAnswer = Request("AT+CPBF=" & Me.Quote & FullName & Me.Quote, , resultPos, vbCrLf)
  413.     mAnswer = Replace$(mAnswer, Me.Quote, "")
  414.     mAnswer = Trim$(Replace$(mAnswer, "+CPBF:", ""))
  415.     Select Case LCase$(mAnswer)
  416.     Case "not found", "", "+cme error: not found"
  417.         mAnswer = "0"
  418.     End Select
  419.     PhoneBook_FindEntry = mAnswer
  420.     RaiseEvent Response(PhoneBook_FindEntry)
  421.     Err.Clear
  422. End Function
  423. Public Function PhoneBook_EntryExists(ByVal FullName As String, ByVal CellNo As String) As String
  424.     On Error Resume Next
  425.     ' search for a phonebook entry for the name and cellphone and return the location
  426.     ' a zero location means not found
  427.     Dim mAnswer As String
  428.     Dim mPhone As String
  429.     Dim mIndex As String
  430.     mAnswer = Request("AT+CPBF=" & Me.Quote & FullName & Me.Quote, , resultPos, vbCrLf)
  431.     mAnswer = Replace$(mAnswer, Me.Quote, "")
  432.     mAnswer = Trim$(Replace$(mAnswer, "+CPBF:", ""))
  433.     Select Case LCase$(mAnswer)
  434.     Case "not found", "", "+cme error: not found"
  435.         PhoneBook_EntryExists = "0"
  436.     Case Else
  437.         mIndex = MvField(mAnswer, 1, ",")
  438.         mPhone = MvField(mAnswer, 2, ",")
  439.         If mPhone = CellNo Then
  440.             PhoneBook_EntryExists = mIndex
  441.         Else
  442.             PhoneBook_EntryExists = "0"
  443.         End If
  444.     End Select
  445.     RaiseEvent Response(PhoneBook_EntryExists)
  446.     Err.Clear
  447. End Function
  448. Public Function PhoneBook_WriteEntry(Location As Long, ByVal CellNo As String, ByVal FullName As String) As String
  449.     On Error Resume Next
  450.     ' write a phonebook entry at a particular location and refresh the count
  451.     Dim mAnswer As String
  452.     mAnswer = "AT+CPBW=" & Location & "," & Me.Quote & CellNo & Me.Quote & ",129," & Me.Quote & FullName & Me.Quote
  453.     mAnswer = Request(mAnswer, , resultPos, vbCrLf)
  454.     PhoneBook_WriteEntry = mAnswer
  455.     If mAnswer = "OK" Then Me.PhoneBook_MemoryStorage (ReadPhoneBookSetting)
  456.     RaiseEvent Response(PhoneBook_WriteEntry)
  457.     Err.Clear
  458. End Function
  459. Public Function PhoneBook_DeleteEntry(Location As Long) As String
  460.     On Error Resume Next
  461.     ' delete a phonebook entry using the location
  462.     Dim mAnswer As String
  463.     mAnswer = Request("AT+CPBW=" & Location, , resultPos, vbCrLf)
  464.     PhoneBook_DeleteEntry = mAnswer
  465.     RaiseEvent Response(PhoneBook_DeleteEntry)
  466.     Err.Clear
  467. End Function
  468. Public Property Get PhoneBook_AvailableIndexes() As String
  469.     On Error Resume Next
  470.     ' get the available phonebook indexes
  471.     Dim mAnswer As String
  472.     mAnswer = Request("AT+CPBR=?", , resultPos, vbCrLf)
  473.     mAnswer = MvField(mAnswer, 2, ":")
  474.     PhoneBook_AvailableIndexes = mAnswer
  475.     RaiseEvent Response(PhoneBook_AvailableIndexes)
  476.     Err.Clear
  477. End Property
  478. Public Function Echo(EchoStatus As EchoEnum) As Boolean
  479.     On Error Resume Next
  480.     ' turn echo off/on, off results in less traffic
  481.     ' echo off returns the command with the result
  482.     Dim mAnswer As String
  483.     Select Case EchoStatus
  484.     Case EchoOff
  485.         mAnswer = Request("ATE0", , resultPos, vbCrLf)
  486.     Case EchoOn
  487.         mAnswer = Request("ATE1", , resultPos, vbCrLf)
  488.     End Select
  489.     If mAnswer = "OK" Then
  490.         Echo = True
  491.     Else
  492.         Echo = False
  493.     End If
  494.     RaiseEvent Response(Echo)
  495.     Err.Clear
  496. End Function
  497. Public Function Request(ByVal strCommand As String, Optional ByVal ExpectedResult As String = "", Optional Position As Long = -1, Optional ControlChars As String = vbCrLf) As String
  498.     On Error GoTo ErrMsg
  499.     ' send a request to the comm port and wait for the result
  500.     ' the result will be delimited by chr(253)
  501.     Dim sResult As String
  502.     If Len(LogFile) > 0 Then
  503.         FileUpdate LogFile, Now() & ", request received " & strCommand, "a"
  504.     End If
  505.     MSComm.Output = strCommand & ControlChars
  506.     sResult = WaitReply(10, ExpectedResult)
  507.     sResult = Replace$(sResult, vbNewLine, VM)
  508.     If Len(LogFile) > 0 Then
  509.         FileUpdate LogFile, Now() & ", response received " & sResult, "a"
  510.     End If
  511.     If Position > 0 Then
  512.         sResult = MvField(sResult, Position, VM)
  513.     Else
  514.         sResult = sResult
  515.     End If
  516.     Request = DescriptiveError(sResult)
  517.     Err.Clear
  518.     Exit Function
  519. ErrMsg:
  520.     RaiseEvent Response(Err.Description)
  521.     Err.Clear
  522. End Function
  523. Private Function WaitReply(lDelay As Long, WaitString As String) As String
  524.     On Error Resume Next
  525.     ' wait process for a data request from the
  526.     ' ms comm port to be finalized
  527.     Dim x As Long
  528.     Dim bOK As Boolean
  529.     DoEvents
  530.     If WaitString = "" Then
  531.         bOK = True
  532.         For x = 1 To lDelay
  533.             Sleep 500
  534.             DoEvents
  535.         Next
  536.     Else
  537.         bOK = False
  538.         For x = 1 To lDelay
  539.             DoEvents
  540.             If InStr(m_Buffer, WaitString) Then
  541.                 bOK = True
  542.                 Exit For
  543.             Else
  544.                 DoEvents
  545.                 Sleep 500
  546.                 DoEvents
  547.             End If
  548.         Next
  549.     End If
  550.     If Len(m_Buffer) > 0 Then
  551.         DoEvents
  552.     End If
  553.     WaitReply = m_Buffer
  554.     Err.Clear
  555. End Function
  556. Private Function MvField(ByVal strValue As String, Optional ByVal PartPosition As Long = 1, Optional ByVal Delimiter As String = ",", Optional TrimValue As Boolean = True) As String
  557.     On Error Resume Next
  558.     ' return a substring of a string delimited by a string specified
  559.     Dim xResult As String
  560.     Dim xArray() As String
  561.     Dim xSize As Long
  562.     If Len(strValue) = 0 Then Exit Function
  563.     If InStr(1, strValue, Delimiter) = 0 Then
  564.         MvField = strValue
  565.         Err.Clear
  566.         Exit Function
  567.     End If
  568.     xArray = Split(strValue, Delimiter)
  569.     Select Case PartPosition
  570.     Case -1
  571.         PartPosition = UBound(xArray) + 1
  572.     Case 0
  573.         PartPosition = 1
  574.     End Select
  575.     xSize = UBound(xArray)
  576.     If xSize = 0 Then
  577.         MvField = ""
  578.     Else
  579.         xResult = xArray(PartPosition - 1)
  580.         If TrimValue = True Then
  581.             xResult = Trim$(xResult)
  582.         End If
  583.         MvField = xResult
  584.     End If
  585.     Err.Clear
  586. End Function
  587. Public Sub FileUpdate(ByVal filName As String, ByVal filLines As String, Optional ByVal Wora As String = "write")
  588.     On Error Resume Next
  589.     ' update contents of a file by either appending / creating a new entry
  590.     Dim iFileNum As Long
  591.     Dim cDir As String
  592.     cDir = FileToken(filName, "p")
  593.     CreateNestedDirectory cDir
  594.     iFileNum = FreeFile
  595.     Select Case LCase$(Left$(Wora, 1))
  596.     Case "w"
  597.         Open filName For Output As #iFileNum
  598.         Case "a"
  599.             Open filName For Append As #iFileNum
  600.             End Select
  601.             Print #iFileNum, filLines
  602.         Close #iFileNum
  603.         Err.Clear
  604. End Sub
  605. Private Function DescriptiveError(ByVal sResult As String) As String
  606.     On Error Resume Next
  607.     ' return descriptive phone error code
  608.     Select Case sResult
  609.     Case "+CME ERROR: 0":        DescriptiveError = "Phone failure"
  610.     Case "+CME ERROR: 1":        DescriptiveError = "No connection to phone"
  611.     Case "+CME ERROR: 2":        DescriptiveError = "Phone adapter link reserved"
  612.     Case "+CME ERROR: 3":        DescriptiveError = "Operation not allowed"
  613.     Case "+CME ERROR: 4":        DescriptiveError = "Operation not supported"
  614.     Case "+CME ERROR: 5":        DescriptiveError = "PH_SIM PIN required"
  615.     Case "+CME ERROR: 6":        DescriptiveError = "PH_FSIM PIN required"
  616.     Case "+CME ERROR: 7":        DescriptiveError = "PH_FSIM PUK required"
  617.     Case "+CME ERROR: 10":        DescriptiveError = "SIM not inserted"
  618.     Case "+CME ERROR: 11":        DescriptiveError = "SIM PIN required"
  619.     Case "+CME ERROR: 12":        DescriptiveError = "SIM PUK required"
  620.     Case "+CME ERROR: 13":        DescriptiveError = "SIM failure"
  621.     Case "+CME ERROR: 14":        DescriptiveError = "SIM busy"
  622.     Case "+CME ERROR: 15":        DescriptiveError = "SIM wrong"
  623.     Case "+CME ERROR: 16":        DescriptiveError = "Incorrect password"
  624.     Case "+CME ERROR: 17":        DescriptiveError = "SIM PIN2 required"
  625.     Case "+CME ERROR: 18":        DescriptiveError = "SIM PUK2 required"
  626.     Case "+CME ERROR: 20":        DescriptiveError = "Memory full"
  627.     Case "+CME ERROR: 21":        DescriptiveError = "Invalid index"
  628.     Case "+CME ERROR: 22":        DescriptiveError = "Not found"
  629.     Case "+CME ERROR: 23":        DescriptiveError = "Memory failure"
  630.     Case "+CME ERROR: 24":        DescriptiveError = "Text string too long"
  631.     Case "+CME ERROR: 25":        DescriptiveError = "Invalid characters in text string"
  632.     Case "+CME ERROR: 26":        DescriptiveError = "Dial string too long"
  633.     Case "+CME ERROR: 27":        DescriptiveError = "Invalid characters in dial string"
  634.     Case "+CME ERROR: 30":        DescriptiveError = "No network service"
  635.     Case "+CME ERROR: 31":        DescriptiveError = "Network timeout"
  636.     Case "+CME ERROR: 32":        DescriptiveError = "Network not allowed, emergency calls only"
  637.     Case "+CME ERROR: 40":        DescriptiveError = "Network personalization PIN required"
  638.     Case "+CME ERROR: 41":        DescriptiveError = "Network personalization PUK required"
  639.     Case "+CME ERROR: 42":        DescriptiveError = "Network subset personalization PIN required"
  640.     Case "+CME ERROR: 43":        DescriptiveError = "Network subset personalization PUK required"
  641.     Case "+CME ERROR: 44":        DescriptiveError = "Service provider personalization PIN required"
  642.     Case "+CME ERROR: 45":        DescriptiveError = "Service provider personalization PUK required"
  643.     Case "+CME ERROR: 46":        DescriptiveError = "Corporate personalization PIN required"
  644.     Case "+CME ERROR: 47":        DescriptiveError = "Corporate personalization PUK required"
  645.     Case "+CME ERROR: 48":        DescriptiveError = "PH-SIM PUK required"
  646.     Case "+CME ERROR: 100":        DescriptiveError = "Unknown error"
  647.     Case "+CME ERROR: 103":        DescriptiveError = "Illegal MS"
  648.     Case "+CME ERROR: 106":        DescriptiveError = "Illegal ME"
  649.     Case "+CME ERROR: 107":        DescriptiveError = "GPRS services not allowed"
  650.     Case "+CME ERROR: 111":        DescriptiveError = "PLMN not allowed"
  651.     Case "+CME ERROR: 112":        DescriptiveError = "Location area not allowed"
  652.     Case "+CME ERROR: 113":        DescriptiveError = "Roaming not allowed in this location area"
  653.     Case "+CME ERROR: 126":        DescriptiveError = "Operation temporary not allowed"
  654.     Case "+CME ERROR: 132":        DescriptiveError = "Service operation not supported"
  655.     Case "+CME ERROR: 133":        DescriptiveError = "Requested service option not subscribed"
  656.     Case "+CME ERROR: 134":        DescriptiveError = "Service option temporary out of order"
  657.     Case "+CME ERROR: 148":        DescriptiveError = "Unspecified GPRS error"
  658.     Case "+CME ERROR: 149":        DescriptiveError = "PDP authentication failure"
  659.     Case "+CME ERROR: 150":        DescriptiveError = "Invalid mobile class"
  660.     Case "+CME ERROR: 256":        DescriptiveError = "Operation temporarily not allowed"
  661.     Case "+CME ERROR: 257":        DescriptiveError = "Call barred"
  662.     Case "+CME ERROR: 258":        DescriptiveError = "Phone is busy"
  663.     Case "+CME ERROR: 259":        DescriptiveError = "User abort"
  664.     Case "+CME ERROR: 260":        DescriptiveError = "Invalid dial string"
  665.     Case "+CME ERROR: 261":        DescriptiveError = "SS not executed"
  666.     Case "+CME ERROR: 262":        DescriptiveError = "SIM Blocked"
  667.     Case "+CME ERROR: 263":        DescriptiveError = "Invalid block"
  668.     Case "+CME ERROR: 772":        DescriptiveError = "SIM powered down"
  669.     Case "+CMS ERROR: 1": DescriptiveError = "Unassigned (unallocated) number"
  670.     Case "+CMS ERROR: 8": DescriptiveError = "Operator determined barring"
  671.     Case "+CMS ERROR: 10": DescriptiveError = "Call barred"
  672.     Case "+CMS ERROR: 21": DescriptiveError = "Short message transfer rejected"
  673.     Case "+CMS ERROR: 27": DescriptiveError = "Destination out of service"
  674.     Case "+CMS ERROR: 28": DescriptiveError = "Unidentified subscriber"
  675.     Case "+CMS ERROR: 29": DescriptiveError = "Facility rejected"
  676.     Case "+CMS ERROR: 30": DescriptiveError = "Unknown subscriber"
  677.     Case "+CMS ERROR: 38": DescriptiveError = "Network out of order"
  678.     Case "+CMS ERROR: 41": DescriptiveError = "Temporary failure"
  679.     Case "+CMS ERROR: 42": DescriptiveError = "Congestion"
  680.     Case "+CMS ERROR: 47": DescriptiveError = "Resources unavailable, unspecified"
  681.     Case "+CMS ERROR: 50": DescriptiveError = "Requested facility not subscribed"
  682.     Case "+CMS ERROR: 69": DescriptiveError = "Requested facility not implemented"
  683.     Case "+CMS ERROR: 81": DescriptiveError = "Invalid short message transfer reference value"
  684.     Case "+CMS ERROR: 95": DescriptiveError = "Invalid message, unspecified"
  685.     Case "+CMS ERROR: 96": DescriptiveError = "Invalid mandatory information"
  686.     Case "+CMS ERROR: 97": DescriptiveError = "Message type non-existent or not implemented"
  687.     Case "+CMS ERROR: 98": DescriptiveError = "Message not compatible with short message protocol state"
  688.     Case "+CMS ERROR: 99": DescriptiveError = "Information element non-existent or not implemented"
  689.     Case "+CMS ERROR: 111": DescriptiveError = "Protocol error, unspecified"
  690.     Case "+CMS ERROR: 127": DescriptiveError = "Interworking, unspecified"
  691.     Case "+CMS ERROR: 128": DescriptiveError = "Telematic interworking not supported"
  692.     Case "+CMS ERROR: 129": DescriptiveError = "Short message Type 0 not supported"
  693.     Case "+CMS ERROR: 130": DescriptiveError = "Cannot replace short message"
  694.     Case "+CMS ERROR: 143": DescriptiveError = "Unspecified TP-PID error"
  695.     Case "+CMS ERROR: 144": DescriptiveError = "Data coding scheme (alphabet) not supported"
  696.     Case "+CMS ERROR: 145": DescriptiveError = "Message class not supported"
  697.     Case "+CMS ERROR: 159": DescriptiveError = "Unspecified TP-DCS error"
  698.     Case "+CMS ERROR: 160": DescriptiveError = "Command cannot be actioned"
  699.     Case "+CMS ERROR: 161": DescriptiveError = "Command unsupported"
  700.     Case "+CMS ERROR: 175": DescriptiveError = "Unspecified TP-Command error"
  701.     Case "+CMS ERROR: 176": DescriptiveError = "TPDU not supported"
  702.     Case "+CMS ERROR: 192": DescriptiveError = "SC busy"
  703.     Case "+CMS ERROR: 193": DescriptiveError = "No SC subscription"
  704.     Case "+CMS ERROR: 194": DescriptiveError = "SC system failure"
  705.     Case "+CMS ERROR: 195": DescriptiveError = "Invalid SME address"
  706.     Case "+CMS ERROR: 196": DescriptiveError = "Destination SME barred"
  707.     Case "+CMS ERROR: 197": DescriptiveError = "SM Rejected-Duplicate SM"
  708.     Case "+CMS ERROR: 198": DescriptiveError = "TP-VPF not supported"
  709.     Case "+CMS ERROR: 199": DescriptiveError = "TP-VP not supported"
  710.     Case "+CMS ERROR: 208": DescriptiveError = "SIM SMS storage full"
  711.     Case "+CMS ERROR: 209": DescriptiveError = "No SMS storage capability in SIM"
  712.     Case "+CMS ERROR: 210": DescriptiveError = "Error in MS"
  713.     Case "+CMS ERROR: 211": DescriptiveError = "Memory Capacity Exceeded"
  714.     Case "+CMS ERROR: 212": DescriptiveError = "SIM Application Toolkit Busy"
  715.     Case "+CMS ERROR: 255": DescriptiveError = "Unspecified error cause"
  716.     Case "+CMS ERROR: 300": DescriptiveError = "ME failure"
  717.     Case "+CMS ERROR: 301": DescriptiveError = "SMS service of ME reserved"
  718.     Case "+CMS ERROR: 302": DescriptiveError = "Operation not allowed"
  719.     Case "+CMS ERROR: 303": DescriptiveError = "Operation not supported"
  720.     Case "+CMS ERROR: 304": DescriptiveError = "Invalid PDU mode parameter"
  721.     Case "+CMS ERROR: 305": DescriptiveError = "Invalid text mode parameter"
  722.     Case "+CMS ERROR: 310": DescriptiveError = "SIM not inserted"
  723.     Case "+CMS ERROR: 311": DescriptiveError = "SIM PIN required"
  724.     Case "+CMS ERROR: 312": DescriptiveError = "PH-SIM PIN required"
  725.     Case "+CMS ERROR: 313": DescriptiveError = "SIM failure"
  726.     Case "+CMS ERROR: 314": DescriptiveError = "SIM busy"
  727.     Case "+CMS ERROR: 315": DescriptiveError = "SIM wrong"
  728.     Case "+CMS ERROR: 316": DescriptiveError = "SIM PUK required"
  729.     Case "+CMS ERROR: 317": DescriptiveError = "SIM PIN2 required"
  730.     Case "+CMS ERROR: 318": DescriptiveError = "SIM PUK2 required"
  731.     Case "+CMS ERROR: 320": DescriptiveError = "memory failure"
  732.     Case "+CMS ERROR: 321": DescriptiveError = "Invalid memory index"
  733.     Case "+CMS ERROR: 322": DescriptiveError = "Memory full"
  734.     Case "+CMS ERROR: 330": DescriptiveError = "SMSC address unknown"
  735.     Case "+CMS ERROR: 331": DescriptiveError = "No network service"
  736.     Case "+CMS ERROR: 332": DescriptiveError = "Network timeout"
  737.     Case "+CMS ERROR: 340": DescriptiveError = "No +CNMA acknowledgement expected"
  738.     Case "+CMS ERROR: 17": DescriptiveError = "Network failure"
  739.     Case "+CMS ERROR: 22": DescriptiveError = "Congestion"
  740.     Case "+CMS ERROR: 500": DescriptiveError = "Unknown Error"
  741.     Case Else
  742.         DescriptiveError = sResult
  743.     End Select
  744.     Err.Clear
  745. End Function
  746. Public Property Get PhoneBook_AvailableIndex() As Long
  747.     On Error Resume Next
  748.     ' get next available index
  749.     Dim rsCnt As Long
  750.     Dim phEntry As String
  751.     Dim pCapacity As Long
  752.     Call Me.PhoneBook_MemoryStorage(ReadPhoneBookSetting)
  753.     pCapacity = Me.PhoneBook_Capacity
  754.     PhoneBook_AvailableIndex = -1
  755.     For rsCnt = 1 To pCapacity
  756.         ' read entry at specified index
  757.         phEntry = Me.PhoneBook_ReadEntry(rsCnt)
  758.         ' if successfull return index,cellno,fullname
  759.         If Len(phEntry) = 0 Then
  760.             PhoneBook_AvailableIndex = rsCnt
  761.             Exit For
  762.         End If
  763.         DoEvents
  764.     Next
  765.     RaiseEvent Response(PhoneBook_AvailableIndex)
  766.     Err.Clear
  767. End Property
  768. Public Function PhoneBook_AddEntry(ByVal sNumber As String, ByVal sName As String) As String
  769.     On Error Resume Next
  770.     'add an entry to the phonebook
  771.     Dim availableIndex As Long
  772.     availableIndex = Me.PhoneBook_AvailableIndex
  773.     If availableIndex = -1 Then
  774.         PhoneBook_AddEntry = "Phonebook Full"
  775.     Else
  776.         PhoneBook_AddEntry = Me.PhoneBook_WriteEntry(availableIndex, sNumber, sName)
  777.     End If
  778.     RaiseEvent Response(PhoneBook_AddEntry)
  779.     Err.Clear
  780. End Function
  781. Public Function SMS_MessageFormat(MessageFormatAction As MessageFormatEnum) As String
  782.     On Error Resume Next
  783.     ' message format management
  784.     Dim mAnswer As String
  785.     Select Case MessageFormatAction
  786.     Case TextFormat
  787.         SMS_MessageFormat = Request("AT+CMGF=1", , resultPos, vbCrLf)
  788.     Case PDUFormat
  789.         SMS_MessageFormat = Request("AT+CMGF=0", , resultPos, vbCrLf)
  790.     Case ReadFormat
  791.         mAnswer = Request("AT+CMGF?", , resultPos, vbCrLf)
  792.         mAnswer = Trim$(MvField(mAnswer, 2, ":"))
  793.         Select Case mAnswer
  794.         Case 0
  795.             SMS_MessageFormat = "PDU"
  796.         Case 1
  797.             SMS_MessageFormat = "TEXT"
  798.         End Select
  799.     End Select
  800.     RaiseEvent Response(SMS_MessageFormat)
  801.     Err.Clear
  802. End Function
  803. Public Function SMS_MemoryStorage(SelectMemory As SmsMemoryStorageEnum) As String
  804.     On Error Resume Next
  805.     ' select phonebook memory
  806.     Dim mAnswer As String
  807.     Select Case SelectMemory
  808.     Case SimMemory
  809.         mAnswer = Request("AT+CPMS=" & Me.Quote & "SM" & Me.Quote & "," & Me.Quote & "SM" & Me.Quote & "," & Me.Quote & "SM" & Me.Quote, "", resultPos, vbCrLf)
  810.         mAnswer = MvField(mAnswer, 2, ":")
  811.         Select Case mAnswer
  812.         Case "ERROR"
  813.             mReadDelete = ""
  814.             mReadDeleteUsed = -1
  815.             mReadDeleteCapacity = -1
  816.             mWriteSend = ""
  817.             mWriteSendUsed = -1
  818.             mWriteSendCapacity = -1
  819.             mReceived = ""
  820.             mReceivedUsed = -1
  821.             mReceivedCapacity = -1
  822.         Case Else
  823.             mReadDelete = "SM"
  824.             mReadDeleteUsed = Val(MvField(mAnswer, 1, ","))
  825.             mReadDeleteCapacity = Val(MvField(mAnswer, 2, ","))
  826.             mWriteSend = "SM"
  827.             mWriteSendUsed = Val(MvField(mAnswer, 3, ","))
  828.             mWriteSendCapacity = Val(MvField(mAnswer, 4, ","))
  829.             mReceived = "SM"
  830.             mReceivedUsed = Val(MvField(mAnswer, 5, ","))
  831.             mReceivedCapacity = Val(MvField(mAnswer, 6, ","))
  832.             mAnswer = "OK"
  833.         End Select
  834.     Case MobileEquipmentMemory
  835.         mAnswer = Request("AT+CPMS=" & Me.Quote & "ME" & Me.Quote & "," & Me.Quote & "ME" & Me.Quote & "," & Me.Quote & "ME" & Me.Quote, "", resultPos, vbCrLf)
  836.         mAnswer = MvField(mAnswer, 2, ":")
  837.         Select Case mAnswer
  838.         Case "ERROR"
  839.             mReadDelete = ""
  840.             mReadDeleteUsed = -1
  841.             mReadDeleteCapacity = -1
  842.             mWriteSend = ""
  843.             mWriteSendUsed = -1
  844.             mWriteSendCapacity = -1
  845.             mReceived = ""
  846.             mReceivedUsed = -1
  847.             mReceivedCapacity = -1
  848.         Case Else
  849.             mReadDelete = "ME"
  850.             mReadDeleteUsed = Val(MvField(mAnswer, 1, ","))
  851.             mReadDeleteCapacity = Val(MvField(mAnswer, 2, ","))
  852.             mWriteSend = "ME"
  853.             mWriteSendUsed = Val(MvField(mAnswer, 3, ","))
  854.             mWriteSendCapacity = Val(MvField(mAnswer, 4, ","))
  855.             mReceived = "ME"
  856.             mReceivedUsed = Val(MvField(mAnswer, 5, ","))
  857.             mReceivedCapacity = Val(MvField(mAnswer, 6, ","))
  858.             mAnswer = "OK"
  859.         End Select
  860.     Case BothMemories
  861.         mAnswer = Request("AT+CPMS=" & Me.Quote & "MT" & Me.Quote & "," & Me.Quote & "MT" & Me.Quote & "," & Me.Quote & "MT" & Me.Quote, "", resultPos, vbCrLf)
  862.         mAnswer = MvField(mAnswer, 2, ":")
  863.         Select Case mAnswer
  864.         Case "ERROR"
  865.             mReadDelete = ""
  866.             mReadDeleteUsed = -1
  867.             mReadDeleteCapacity = -1
  868.             mWriteSend = ""
  869.             mWriteSendUsed = -1
  870.             mWriteSendCapacity = -1
  871.             mReceived = ""
  872.             mReceivedUsed = -1
  873.             mReceivedCapacity = -1
  874.         Case Else
  875.             mReadDelete = "MT"
  876.             mReadDeleteUsed = Val(MvField(mAnswer, 1, ","))
  877.             mReadDeleteCapacity = Val(MvField(mAnswer, 2, ","))
  878.             mWriteSend = "MT"
  879.             mWriteSendUsed = Val(MvField(mAnswer, 3, ","))
  880.             mWriteSendCapacity = Val(MvField(mAnswer, 4, ","))
  881.             mReceived = "MT"
  882.             mReceivedUsed = Val(MvField(mAnswer, 5, ","))
  883.             mReceivedCapacity = Val(MvField(mAnswer, 6, ","))
  884.             mAnswer = "OK"
  885.         End Select
  886.     Case ReadMemorySetting
  887.         mAnswer = Request("AT+CPMS?", "", resultPos, vbCrLf)
  888.         mAnswer = MvField(mAnswer, 2, ":")
  889.         mAnswer = Replace$(mAnswer, Me.Quote, "")
  890.         mReadDelete = MvField(mAnswer, 1, ",")
  891.         mReadDeleteUsed = Val(MvField(mAnswer, 2, ","))
  892.         mReadDeleteCapacity = Val(MvField(mAnswer, 3, ","))
  893.         mWriteSend = MvField(mAnswer, 4, ",")
  894.         mWriteSendUsed = Val(MvField(mAnswer, 5, ","))
  895.         mWriteSendCapacity = Val(MvField(mAnswer, 6, ","))
  896.         mReceived = MvField(mAnswer, 7, ",")
  897.         mReceivedUsed = Val(MvField(mAnswer, 8, ","))
  898.         mReceivedCapacity = Val(MvField(mAnswer, 9, ","))
  899.         mAnswer = "OK"
  900.     Case BroadcastMessageStorage
  901.         mAnswer = Request("AT+CPMS=" & Me.Quote & "BM" & Me.Quote & "," & Me.Quote & "BM" & Me.Quote & "," & Me.Quote & "BM" & Me.Quote, "", resultPos, vbCrLf)
  902.         mAnswer = MvField(mAnswer, 2, ":")
  903.         Select Case mAnswer
  904.         Case "ERROR"
  905.             mReadDelete = ""
  906.             mReadDeleteUsed = -1
  907.             mReadDeleteCapacity = -1
  908.             mWriteSend = ""
  909.             mWriteSendUsed = -1
  910.             mWriteSendCapacity = -1
  911.             mReceived = ""
  912.             mReceivedUsed = -1
  913.             mReceivedCapacity = -1
  914.         Case Else
  915.             mReadDelete = "BM"
  916.             mReadDeleteUsed = Val(MvField(mAnswer, 1, ","))
  917.             mReadDeleteCapacity = Val(MvField(mAnswer, 2, ","))
  918.             mWriteSend = "BM"
  919.             mWriteSendUsed = Val(MvField(mAnswer, 3, ","))
  920.             mWriteSendCapacity = Val(MvField(mAnswer, 4, ","))
  921.             mReceived = "BM"
  922.             mReceivedUsed = Val(MvField(mAnswer, 5, ","))
  923.             mReceivedCapacity = Val(MvField(mAnswer, 6, ","))
  924.             mAnswer = "OK"
  925.         End Select
  926.     Case StatusReportStorage
  927.         mAnswer = Request("AT+CPMS=" & Me.Quote & "SR" & Me.Quote & "," & Me.Quote & "SR" & Me.Quote & "," & Me.Quote & "SR" & Me.Quote, "", resultPos, vbCrLf)
  928.         mAnswer = MvField(mAnswer, 2, ":")
  929.         Select Case mAnswer
  930.         Case "ERROR"
  931.             mReadDelete = ""
  932.             mReadDeleteUsed = -1
  933.             mReadDeleteCapacity = -1
  934.             mWriteSend = ""
  935.             mWriteSendUsed = -1
  936.             mWriteSendCapacity = -1
  937.             mReceived = ""
  938.             mReceivedUsed = -1
  939.             mReceivedCapacity = -1
  940.         Case Else
  941.             mReadDelete = "SR"
  942.             mReadDeleteUsed = Val(MvField(mAnswer, 1, ","))
  943.             mReadDeleteCapacity = Val(MvField(mAnswer, 2, ","))
  944.             mWriteSend = "SR"
  945.             mWriteSendUsed = Val(MvField(mAnswer, 3, ","))
  946.             mWriteSendCapacity = Val(MvField(mAnswer, 4, ","))
  947.             mReceived = "SR"
  948.             mReceivedUsed = Val(MvField(mAnswer, 5, ","))
  949.             mReceivedCapacity = Val(MvField(mAnswer, 6, ","))
  950.             mAnswer = "OK"
  951.         End Select
  952.     Case TerminalAdapterStorage
  953.         mAnswer = Request("AT+CPMS=" & Me.Quote & "TA" & Me.Quote & "," & Me.Quote & "TA" & Me.Quote & "," & Me.Quote & "TA" & Me.Quote, "", resultPos, vbCrLf)
  954.         mAnswer = MvField(mAnswer, 2, ":")
  955.         Select Case mAnswer
  956.         Case "ERROR"
  957.             mReadDelete = ""
  958.             mReadDeleteUsed = -1
  959.             mReadDeleteCapacity = -1
  960.             mWriteSend = ""
  961.             mWriteSendUsed = -1
  962.             mWriteSendCapacity = -1
  963.             mReceived = ""
  964.             mReceivedUsed = -1
  965.             mReceivedCapacity = -1
  966.         Case Else
  967.             mReadDelete = "TA"
  968.             mReadDeleteUsed = Val(MvField(mAnswer, 1, ","))
  969.             mReadDeleteCapacity = Val(MvField(mAnswer, 2, ","))
  970.             mWriteSend = "TA"
  971.             mWriteSendUsed = Val(MvField(mAnswer, 3, ","))
  972.             mWriteSendCapacity = Val(MvField(mAnswer, 4, ","))
  973.             mReceived = "TA"
  974.             mReceivedUsed = Val(MvField(mAnswer, 5, ","))
  975.             mReceivedCapacity = Val(MvField(mAnswer, 6, ","))
  976.             mAnswer = "OK"
  977.         End Select
  978.     End Select
  979.     SMS_MemoryStorage = mAnswer
  980.     RaiseEvent Response(SMS_MemoryStorage)
  981.     Err.Clear
  982. End Function
  983. Public Function SMS_CentreNumber(CentreNumberAction As CentreNumberEnum, Optional SMSC As String = "") As String
  984.     On Error Resume Next
  985.     ' centre number management
  986.     Dim mAnswer As String
  987.     Select Case CentreNumberAction
  988.     Case SetCentreNumber
  989.         mAnswer = Request("AT+CSCA=" & Me.Quote & SMSC & Me.Quote, "", resultPos, vbCrLf)
  990.     Case ReadCentreNumber
  991.         mAnswer = Request("AT+CSCA?", "", resultPos, vbCrLf)
  992.         mAnswer = MvField(mAnswer, 2, ":")
  993.         mAnswer = MvField(mAnswer, 1, ",")
  994.         mAnswer = Replace$(mAnswer, Me.Quote, "")
  995.     End Select
  996.     SMS_CentreNumber = mAnswer
  997.     RaiseEvent Response(SMS_CentreNumber)
  998.     Err.Clear
  999. End Function
  1000. Public Property Get SMS_ReadDeleteStorage() As String
  1001.     On Error Resume Next
  1002.     SMS_ReadDeleteStorage = mReadDelete
  1003.     Err.Clear
  1004. End Property
  1005. Public Property Get SMS_ReadDeleteStorageUsed() As Long
  1006.     On Error Resume Next
  1007.     SMS_ReadDeleteStorageUsed = mReadDeleteUsed
  1008.     Err.Clear
  1009. End Property
  1010. Public Property Get SMS_ReadDeleteStorageCapacity() As Long
  1011.     On Error Resume Next
  1012.     SMS_ReadDeleteStorageCapacity = mReadDeleteCapacity
  1013.     Err.Clear
  1014. End Property
  1015. Public Property Get SMS_WriteSendStorage() As String
  1016.     On Error Resume Next
  1017.     SMS_WriteSendStorage = mWriteSend
  1018.     Err.Clear
  1019. End Property
  1020. Public Property Get SMS_WriteSendStorageUsed() As Long
  1021.     On Error Resume Next
  1022.     SMS_WriteSendStorageUsed = mWriteSendUsed
  1023.     Err.Clear
  1024. End Property
  1025. Public Property Get SMS_WriteSendStorageCapacity() As Long
  1026.     On Error Resume Next
  1027.     SMS_WriteSendStorageCapacity = mWriteSendCapacity
  1028.     Err.Clear
  1029. End Property
  1030. Public Property Get SMS_ReceivedStorage() As String
  1031.     On Error Resume Next
  1032.     SMS_ReceivedStorage = mReceived
  1033.     Err.Clear
  1034. End Property
  1035. Public Property Get SMS_ReceivedStorageUsed() As Long
  1036.     On Error Resume Next
  1037.     SMS_ReceivedStorageUsed = mReceivedUsed
  1038.     Err.Clear
  1039. End Property
  1040. Public Property Get SMS_ReceivedStorageCapacity() As Long
  1041.     On Error Resume Next
  1042.     SMS_ReceivedStorageCapacity = mReceivedCapacity
  1043.     Err.Clear
  1044. End Property
  1045. Public Property Get PhoneBook_Used() As Long
  1046.     On Error Resume Next
  1047.     PhoneBook_Used = mpbUsed
  1048.     Err.Clear
  1049. End Property
  1050. Public Property Get PhoneBook_Capacity() As Long
  1051.     On Error Resume Next
  1052.     PhoneBook_Capacity = mpbCapacity
  1053.     Err.Clear
  1054. End Property
  1055. Public Property Get PhoneBook_Memory() As String
  1056.     On Error Resume Next
  1057.     ' update property
  1058.     PhoneBook_Memory = mpbMemory
  1059.     Err.Clear
  1060. End Property
  1061. Public Property Get SubscriberNumber() As String
  1062.     On Error Resume Next
  1063.     ' get the subscriber number
  1064.     SubscriberNumber = Request("AT+CNUM", , resultPos, vbCrLf)
  1065.     RaiseEvent Response(SubscriberNumber)
  1066.     Err.Clear
  1067. End Property
  1068. Public Property Get InternationalMobileSubscriberIdentity() As String
  1069.     On Error Resume Next
  1070.     ' get the international mobile subscriber identity
  1071.     InternationalMobileSubscriberIdentity = Request("AT+CIMI", , resultPos, vbCrLf)
  1072.     RaiseEvent Response(InternationalMobileSubscriberIdentity)
  1073.     Err.Clear
  1074. End Property
  1075. Public Function SMS_ReadMessageEntry(msgIndex As Long) As String
  1076.     On Error Resume Next
  1077.     ' read the message stored at location
  1078.     Dim mAnswer As String
  1079.     Dim tmpAns As String
  1080.     Dim MsgType As String
  1081.     Dim msgFrom As String
  1082.     Dim msgDate As String
  1083.     Dim msgTime As String
  1084.     Dim msgContents As String
  1085.     Dim pPos As Long
  1086.     mAnswer = Request("AT+CMGR=" & msgIndex, , , vbCrLf)
  1087.     mAnswer = MvRest(mAnswer, 2, Me.VM)
  1088.     mAnswer = Trim$(Replace$(mAnswer, "+CMGR:", ""))
  1089.     tmpAns = MvField(mAnswer, 1, VM)
  1090.     Select Case tmpAns
  1091.     Case "OK"
  1092.         mAnswer = ""
  1093.     Case Else
  1094.         MsgType = MvField(mAnswer, 1, ",")
  1095.         MsgType = Replace$(MsgType, Quote, "")
  1096.         msgFrom = MvField(mAnswer, 2, ",")
  1097.         msgFrom = Replace$(msgFrom, Quote, "")
  1098.         msgDate = MvField(mAnswer, 4, ",")
  1099.         msgDate = Replace$(msgDate, Quote, "")
  1100.         msgDate = FixSmsDate(msgDate)
  1101.         msgTime = MvField(mAnswer, 5, ",")
  1102.         msgTime = MvField(msgTime, 1, VM)
  1103.         msgTime = Replace$(msgTime, Quote, "")
  1104.         pPos = InStr(1, msgTime, "+")
  1105.         If pPos > 0 Then
  1106.             msgTime = Left$(msgTime, pPos - 1)
  1107.         End If
  1108.         msgContents = MvRest(mAnswer, 2, VM)
  1109.         msgContents = Replace$(msgContents, VM & VM & "OK" & VM, "")
  1110.         msgContents = RemAllVM(msgContents)
  1111.         mAnswer = msgIndex & FM & MsgType & FM & msgFrom & FM & msgDate & " " & msgTime & FM & msgContents
  1112.     End Select
  1113.     SMS_ReadMessageEntry = mAnswer
  1114.     RaiseEvent Response(SMS_ReadMessageEntry)
  1115.     Err.Clear
  1116. End Function
  1117. Public Sub SMS_ListView(progBar As Variant, LstView As Variant, Optional mIcon As String = "", Optional mSmallIcon As String = "", Optional MsgType As SmsTypesEnum)
  1118.     On Error Resume Next
  1119.     ' load contents of the selected message store messages
  1120.     ' to the listview
  1121.     Dim rsCnt As Long
  1122.     Dim phEntry As String
  1123.     Dim lstItem As Variant
  1124.     Dim spLine() As String
  1125.     Dim nCollection As New Collection
  1126.     Set nCollection = SMS_ReadMessages
  1127.     progBar.Max = nCollection.Count
  1128.     progBar.Min = 0
  1129.     progBar.Value = 0
  1130.     ' create headings
  1131.     LstViewMakeHeadings LstView, "Msg ID,Cellphone No.,Contents,Time"
  1132.     ' loop through the messages starting from location 1 to the full capacity of the phone
  1133.     For rsCnt = 1 To nCollection.Count
  1134.         progBar.Value = rsCnt
  1135.         ' read entry at specified index
  1136.         phEntry = nCollection(rsCnt)
  1137.         ' if successfull return msg index, type,cellnumber,date,message
  1138.         If Len(phEntry) > 0 Then
  1139.             spLine = Split(phEntry, FM)
  1140.             Select Case MsgType
  1141.             Case Rec
  1142.                 If spLine(1) = "REC READ" Or spLine(1) = "REC UNREAD" Then
  1143.                     GoTo AddLine
  1144.                 Else
  1145.                     GoTo NextLine
  1146.                 End If
  1147.             Case RecRead
  1148.                 If spLine(1) = "REC READ" Then
  1149.                     GoTo AddLine
  1150.                 Else
  1151.                     GoTo NextLine
  1152.                 End If
  1153.             Case RecUnread
  1154.                 If spLine(1) = "REC UNREAD" Then
  1155.                     GoTo AddLine
  1156.                 Else
  1157.                     GoTo NextLine
  1158.                 End If
  1159.             Case StoSent
  1160.                 If spLine(1) = "STO SENT" Then
  1161.                     GoTo AddLine
  1162.                 Else
  1163.                     GoTo NextLine
  1164.                 End If
  1165.             Case StoUnsent
  1166.                 If spLine(1) = "STO UNSENT" Then
  1167.                     GoTo AddLine
  1168.                 Else
  1169.                     GoTo NextLine
  1170.                 End If
  1171.             End Select
  1172. AddLine:
  1173.             Set lstItem = LstView.ListItems.Add(, , spLine(0))
  1174.             lstItem.SubItems(1) = spLine(2)
  1175.             lstItem.SubItems(2) = spLine(4)
  1176.             lstItem.SubItems(3) = spLine(3)
  1177.             If Len(mIcon) > 0 Then lstItem.Icon = mIcon
  1178.             If Len(mSmallIcon) > 0 Then lstItem.SmallIcon = mSmallIcon
  1179.         End If
  1180. NextLine:
  1181.         DoEvents
  1182.     Next
  1183.     progBar.Value = 0
  1184.     Err.Clear
  1185. End Sub
  1186. Private Function MvRest(ByVal strData As String, Optional ByVal startPos As Long = 1, Optional ByVal Delim As String = "") As String
  1187.     On Error Resume Next
  1188.     ' get the string from a substring position to the end of the
  1189.     ' delimited string
  1190.     Dim spData() As String
  1191.     Dim spCnt As Long
  1192.     Dim intLoop As Long
  1193.     Dim strL As String
  1194.     Dim strM As String
  1195.     MvRest = ""
  1196.     strM = ""
  1197.     If Len(Delim) = 0 Then Delim = Me.VM
  1198.     If Len(strData) = 0 Then
  1199.         Err.Clear
  1200.         Exit Function
  1201.     End If
  1202.     spData = Split(strData, Delim)
  1203.     spCnt = UBound(spData)
  1204.     Select Case startPos
  1205.     Case -1
  1206.         MvRest = Trim$(spData(spCnt))
  1207.     Case Else
  1208.         strL = ""
  1209.         startPos = startPos - 1
  1210.         For intLoop = startPos To spCnt
  1211.             strL = spData(intLoop)
  1212.             If intLoop = spCnt Then
  1213.                 strM = strM & strL
  1214.             Else
  1215.                 strM = strM & strL & Delim
  1216.             End If
  1217.         Next
  1218.         MvRest = strM
  1219.     End Select
  1220.     Err.Clear
  1221. End Function
  1222. Public Function SMS_DeleteEntry(Location As Long) As String
  1223.     On Error Resume Next
  1224.     ' delete a sms and refresh if ok
  1225.     Dim mAnswer As String
  1226.     mAnswer = Request("AT+CMGD=" & Location, , resultPos, vbCrLf)
  1227.     SMS_DeleteEntry = mAnswer
  1228.     If mAnswer = "OK" Then Call SMS_MemoryStorage(ReadMemorySetting)
  1229.     RaiseEvent Response(SMS_DeleteEntry)
  1230.     Err.Clear
  1231. End Function
  1232. Private Function SMS_ReadMessages() As Collection
  1233.     On Error Resume Next
  1234.     ' read all sms messages from selected memory
  1235.     Dim mAnswer As String
  1236.     Dim nCollection As New Collection
  1237.     Dim rsCnt As Long
  1238.     Dim rsTot As Long
  1239.     Dim rsStr As String
  1240.     Dim rsLines() As String
  1241.     Dim msgIndex As String
  1242.     Dim MsgType As String
  1243.     Dim msgFrom As String
  1244.     Dim msgDate As String
  1245.     Dim msgTime As String
  1246.     Dim msgContents As String
  1247.     Dim pPos As Long
  1248.     mAnswer = Me.SMS_MessageFormat(TextFormat)
  1249.     If mAnswer = "OK" Then
  1250.         mAnswer = Me.Request("AT+CMGL=" & Quote & "ALL" & Quote, , , vbCrLf)
  1251.     End If
  1252.     rsLines = Split(mAnswer, "+CMGL:")
  1253.     rsTot = UBound(rsLines)
  1254.     For rsCnt = 0 To rsTot
  1255.         rsLines(rsCnt) = Trim$(rsLines(rsCnt))
  1256.         rsStr = rsLines(rsCnt)
  1257.         msgIndex = MvField(rsStr, 1, ",")
  1258.         If IsNumeric(msgIndex) = True Then
  1259.             MsgType = MvField(rsStr, 2, ",")
  1260.             MsgType = Replace$(MsgType, Quote, "")
  1261.             msgFrom = MvField(rsStr, 3, ",")
  1262.             msgFrom = Replace$(msgFrom, Quote, "")
  1263.             If msgFrom = "6" Then
  1264.                 ' report
  1265.                 GoTo NextRecord
  1266.             End If
  1267.             msgDate = MvField(rsStr, 5, ",")
  1268.             msgDate = Replace$(msgDate, Quote, "")
  1269.             msgDate = FixSmsDate(msgDate)
  1270.             msgTime = MvField(rsStr, 6, ",")
  1271.             msgTime = MvField(msgTime, 1, VM)
  1272.             msgTime = Replace$(msgTime, Quote, "")
  1273.             pPos = InStr(1, msgTime, "+")
  1274.             If pPos > 0 Then
  1275.                 msgTime = Left$(msgTime, pPos - 1)
  1276.             End If
  1277.             msgContents = MvRest(rsStr, 2, VM)
  1278.             msgContents = Replace$(msgContents, VM & VM & "OK" & VM, "")
  1279.             msgContents = RemAllVM(msgContents)
  1280.             rsStr = msgIndex & FM & MsgType & FM & msgFrom & FM & msgDate & " " & msgTime & FM & msgContents
  1281.             nCollection.Add rsStr
  1282.         End If
  1283. NextRecord:
  1284.     Next
  1285.     Set SMS_ReadMessages = nCollection
  1286.     Err.Clear
  1287. End Function
  1288. Private Function SMS_SendSmall(sNumber As String, sMessage As String) As String
  1289.     On Error Resume Next
  1290.     ' send an sms to a phone, set textmode format just in case
  1291.     Dim mAnswer As String
  1292.     mAnswer = Request("AT+CMGS=" & Quote & sNumber & Quote, , resultPos, vbCr)
  1293.     Select Case mAnswer
  1294.     Case ">"
  1295.         mAnswer = Request(sMessage, , 4, Chr$(26))
  1296.     Case Else
  1297.         mAnswer = "ERROR"
  1298.     End Select
  1299.     SMS_SendSmall = mAnswer
  1300.     RaiseEvent Response(SMS_SendSmall)
  1301.     Err.Clear
  1302. End Function
  1303. Public Function SMS_Send(sNumber As String, sMessage As String) As String
  1304.     On Error Resume Next
  1305.     ' send an sms to a phone, set textmode format just in case
  1306.     Dim mAnswer As String
  1307.     Dim msgSent As Long
  1308.     Dim msgOne As Long
  1309.     Dim msgTwo As Long
  1310.     msgOne = 0
  1311.     msgTwo = 0
  1312.     mAnswer = SMS_MessageFormat(TextFormat)
  1313.     If mAnswer = "OK" Then
  1314.         If Len(sMessage) > 160 Then
  1315.             mAnswer = SMS_SendSmall(sNumber, MSMS_Rea   Oim iormaSeomallIcond Selectm3ne = 0FrtPos As Lo= LstView.LiS_Rea   Oim iorar
  1316. Endt(a   Oim iorar
  1317. Enteld(rsStr,On Erlue     GoTo N  On ES,On Sub
  1318. Privatx & FM & MsgType 
  1319.     If Le"gFrom = "6" Then
  1320.             From = "6" Then
  1321.     ectionected-DDDDDDDDDD-n
  1322.     es ",")iss r"
  1323.     Case "+CME ERR        Fromer
  1324.    Dimtmber, MSMS_Rea   Oim iormaSeomallIcond Selectm3ne = 0Fr, ""    Err.Clear
  1325. End Function
  1326. Private Fung, sMo rsToDttexg ectio Fung, sMo rDim rsCnt o ecttio Fung,essageFormde vedStorage() As String
  1327.     O : sMo t > 0rmde vefsmjrAT+CMGS> 0rmde ve+CMGS> 0rmdeTime, "etring
  1328.     O : sMwO"ectio Fung, sMo rDim rsCnt o ecttio Fung,essageFord an sms to a phone, set index,c"+CME ERROR:TFvents
  1329.     Nexo Function
  1330. TL
  1331.             Else
  1332.                 sttexg ectise
  1333. ormaSeomallIcond Selectm3ne = 0Fr, ""     DoEvelIcond         Descriptive
  1334.                 ct
  1335.   ents = a        sttexg ectise=,n cEs = a        sttexg ectise=,n cEs = a        
  1336. ormaSeomallIcond Sele_SendSmall((((((te=,n cEs = a 
  1337.     nLKcor5=,n cEs = a((te=,s = a((te=,s = a(    SMS_SendSmall(sNumber, MSMS_Rer Resume Next
  1338.     ' send an sms to a phone, set textmode format just i3lic Subote, "ssssssssssssB5rsTte headings
  1339.     LstViewMt i3gDate)
  1340.       mWrtcol state"
  1341.     Cic SuboMmWrtm msgnts, Ve, "    rror Resume Next
  1342.     ' send an sms to a phone, set tRbor Resume Next
  1343.     ' send al(sNumNionPrror ehcpd text1
  1344.             mWrie, "    rror Resumedetoe Next
  1345.     ' s,dmWrtm msgnts, Ve, "    rror Resume Next
  1346.     ' send an sms to a phone, set tRbor Resume Next
  1347.     ' send al(sNumNionPrror ehcpd text1
  1348. DumNion,PrivatDescrim$(rsLineResponssms to a phone, set index,c"+CME ERROR:TFvents
  1349.     Nexo Function
  1350. TL
  1351.             El5       mAAAAAAAAAAAAA FromhvFieAAAAAformatErr.Clear
  1352. End FunctioT mAAAAAA+O String
  1353.     Dim msgFrom Aa  nAset index,c"+CME ERROR:TFvents
  1354.     Nexo Functims to a phone, set tRbor Rtims to a phone, ndex,c"ents As String
  1355.     Dim pPos As LonmsgFr            mReceivedCapao.,Cxt
  1356.     ' send an sms to t tRborlnswer, gContents As String
  1357.     Dim pPos As Long
  1358.     mAnsw    ms
  1359.         If  , rcoX    m 0 Then, ndex,c"entd(rsStr     Next
  1360.     ) As Str RtiU(MvField(mAnswer, 1, ","))bborlnswer, gContents Aser, gTU(MvField(mA Dim sp1e$(msgDate,  &MSMS_Rer Resume Next
  1361.     'e Next2, ":")tents Ar.Cl