You are here:
ActiveXperts.com > SMS and MMS Toolkit > How to Use the SMS and MMS Toolkit > SMPP Provider > Visual Basic 5.x/6.x
Quicklinks
The SMS and MMS Toolkit is a software development kit (SDK) to enhance an application or script with SMS, MMS and Pager functionality. SMS messages can be sent using a GSM/GPRS modem, an SMPP provider, an HTTP compliant SMS provider or using a standard dialup or fixed-line SMS modem. MMS messages can be sent via a GSM/GPRS modem (MM1), an SMTP server (MM4) or an XML/SOAP compliant provider (MM7).
SMS features:
MMS features:
Pager features:
This document describes how the SMS and MMS Toolkit can be integrated into Visual Basic 5.x/6.x projects.
Download the SMS and MMS Toolkit from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.
Launch 'Microsoft Visual Basic' from the Start menu, and choose 'New' from the 'File Menu'. The 'New Project' dialog appears.
Select 'Standard Exe' and click 'OK':
(Click on the picture to enlarge)
A new Project is created, with a blank form.
First, you must add a reference to the SMS and MMS Toolkit in the project to be able to use the SMS objects. To do so, choose 'References...' from the 'Project' menu. In the 'References' dialog that pops up, enable the ActiveXperts SMS and MMS Toolkit Type Library' reference as shown in the following picture:
(Click on the picture to enlarge)
Click 'OK' to close the 'References...' dialog.
Then, select the Project form and choose 'View Code' from the context menu:
(Click on the picture to enlarge)
On top of your code, declare the following objects for SMPP:
Dim objSmppProtocol As AXmsCtrl.SmsProtocolSmpp Dim objSmsMessage As AXmsCtrl.SmsMessage Dim objSmsConstants As AXmsCtrl.SmsConstants
From the Code window, select 'Form'. The Private Sub 'Form_Load()' will be displayed now.
In the 'Form Load' function, create the SMS objects in the following way:
Set objSmppProtocol = CreateObject("ActiveXperts.SmsProtocolSmpp")
Set objSmsMessage = CreateObject("ActiveXperts.SmsMessage")
Set objSmsConstants = CreateObject("ActiveXperts.SmsConstants")
The following code shows how to send an SMS message:
Option Explicit
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Const MAX_PATH = 260
Public objSmppProtocol As AXmsCtrl.SmsProtocolSmpp
Public objSmsMessage As AXmsCtrl.SmsMessage
Public objSmsConstants As AXmsCtrl.SmsConstants
Public objStatus As AXmsCtrl.SmsDeliveryStatus
Private Sub Connect_Click()
MousePointer = vbHourglass
objSmppProtocol.Server = TextServer.Text
objSmppProtocol.SystemID = TextSystemID.Text
objSmppProtocol.SystemPassword = TextPassword.Text
objSmppProtocol.SystemType = TextSystemType.Text
objSmppProtocol.ServerPort = TextServerPort.Text
objSmppProtocol.LogFile = TextLogFile.Text
objSmppProtocol.ServerKeepAlive = 60
objSmppProtocol.ServerTimeout = 5000
'objSmppProtocol.SystemVersion = objSmsConstants.asSMPPVERSION_34
objSmppProtocol.SystemMode = objSmsConstants.asSMPPMODE_TRANSMITTER
objSmppProtocol.Connect
If GetResult = 0 Then
TextRecipient.Enabled = True
TextMessage.Enabled = True
ListView1.Enabled = True
Disconnect.Enabled = True
Connect.Enabled = False
Send.Enabled = True
End If
MousePointer = vbDefault
End Sub
Private Function Disc()
MousePointer = vbHourglass
objSmppProtocol.Disconnect
TextRecipient.Enabled = False
TextMessage.Enabled = False
ListView1.Enabled = False
Disconnect.Enabled = False
Connect.Enabled = True
Send.Enabled = False
MousePointer = vbDefault
End Function
Private Sub Disconnect_Click()
Disc
End Sub
Private Function SetDefaultLogFile()
Dim Buffer As String
Buffer = Space(MAX_PATH)
If GetTempPath(MAX_PATH, Buffer) <> 0 Then
TextLogFile.Text = Left$(Buffer, InStr(Buffer, vbNullChar) - 1) & "SmppLog.txt"
Else
TextLogFile.Text = "C:\SmppLog.txt"
End If
End Function
Private Sub Form_Load()
Set objSmppProtocol = CreateObject("ActiveXperts.SmsProtocolSmpp")
Set objSmsMessage = CreateObject("ActiveXperts.SmsMessage")
Set objSmsConstants = CreateObject("ActiveXperts.SmsConstants")
SetDefaultLogFile
End Sub
Private Function GetResult() As Long
Dim lResult As Long
lResult = objSmppProtocol.LastError ' Get Last Error
TextResult.Text = "ERROR " & objSmppProtocol.LastError & " ( " & objSmppProtocol.GetErrorDescription(lResult) & " )" ' Set Result
GetResult = lResult
End Function
Private Sub Send_Click()
Dim strReference
If objSmppProtocol.IsConnected = False Then
Disconnect_Click
End If
objSmsMessage.Recipient = TextRecipient.Text
objSmsMessage.Data = TextMessage.Text
objSmsMessage.Format = objSmsConstants.asMESSAGEFORMAT_TEXT
objSmppProtocol.LogFile = TextLogFile.Text
strReference = objSmppProtocol.Send( objSmsMessage )
If GetResult = 0 Then
Dim lList As ListItem
Set lList = ListView1.ListItems.Add(, , strReference) ' Add data to list control
lList.SubItems(1) = objSmsMessage.Recipient
lList.SubItems(2) = "n/a"
lList.SubItems(3) = "Submitted"
End If
End Sub
Private Function Query()
Dim i As Integer
If objSmppProtocol.IsConnected = False Then
Disconnect_Click
End If
For i = 1 To ListView1.ListItems.Count
Dim lList As ListItem
Set lList = ListView1.ListItems(i)
If lList.SubItems(2) = "n/a" Then
On Error Resume Next
Set objStatus objSmppProtocol.QueryStatus ( ListView1.ListItems(i).Text )
On Error Goto 0
If objSmppProtocol.LastError = 0 Then
lList.SubItems(2) = objStatus.StatusCompletedTime
lList.SubItems(3) = objStatus.StatusDescription
End If
End If
Next
End Function
Private Sub Timer1_Timer()
Query
End Sub
Private Sub Form1_Unload()
Disc
End Sub
Private Sub View_Click()
If FileExists(TextLogFile.Text) = True Then
Shell "notepad " + TextLogFile.Text, vbNormalFocus
End If
End Sub
Public Function FileExists(sFileName As String) As Boolean
FileExists = CBool(Len(Dir$(sFileName))) And CBool(Len(sFileName))
End Function
There are many working samples included with the product. You can also find them on the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/mobile-messaging-component.