You are here:
ActiveXperts.com > SMS and MMS Toolkit > How to Use the SMS and MMS Toolkit > GSM phone or modem > Visual Basic for Applications
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 VBA projects.
Download the SMS and MMS Toolkit from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.
Create the form displayed in the image below. To create the buttons, textarea's and drop down menu's, click "View", "Toolbars", "Control toolbox".
(Click on the picture to enlarge)
In this sample, we're creating a form that is able to send an SMS in Microsoft Excel. Sending an SMS with our SMS and MMS Toolkit can be done in just a few lines of code. The core of this little system is the SmsProtocolGsm object witch is the first line of code that must be typed down in your code. After that, just add the phone-number, the message, tell the system what port the device is connected to and eventually send the message.
You can configure a lot of extra options. Few of them are used in this sample. More information about those options are to be found in the products manual whitch is shipped with our product. In this sample we are configuring a logfile, the message type, we are checking the status of the SMS (Whether it has been sent or not) and we're displaying the modems connected to the computer.
In this sample we work with forms. It is possible to work with just the fields too. To create an excel file whitch is able to send an SMS, first of all, create a new excel file with the form that is displayed below in it.
(Click on the picture to enlarge)
A lot of things in this form are optional. Basically you only need the fields mentioned below:
Make sure you don't forget to create a submit button.
The first and most important thing is to create the ActiveXperts objects. To do that means we need to type some code. You can add code
to an excel sheet. Click "View", "Toolbars" and then "Control Toolbox". You will see a "Design Mode"-icon (
), click it. Double
click the submit button you created in your form. The MicroSoft Visual Basic Editor will now be opened. You can type all code here.
The ActiveXperts objects have to be public variables because they are used in different subs. Use the following code for that.
'Declare the object variables
Public objGsmProtocol As Object
Public objSmsMessage As Object
Public objSmsConstants As Object
To fill these variables with the ActiveXperts Software, we're creating a function so in any situation we're sure the object is loaded properly. Use the following code:
Sub createobjects()
'########################### set the objects ###########################
If objGsmProtocol Is Nothing Then
Set objGsmProtocol = CreateObject("ActiveXperts.SmsProtocolGsm")
Set objSmsMessage = CreateObject("ActiveXperts.SmsMessage")
Set objSmsConstants = CreateObject("ActiveXperts.SmsConstants")
Else
End If
End Sub
In the sample we created a seperate sub for sending the SMS. If the submit button is clicked fist a check is preformed. If the phone number is correct the SMS will be sent. The objects we've created work with the SMS and MMS Toolkit. Every property of the toolkit can used with a dot. Every object has its own properties whitch can be found in the products manual that is shipped with the product. Here is an example of how to call to a property. This script wil print the version of the SMS and MMS Toolkit's version in a messagebox.
Sub createobjects()
Dim objGsmProtocol as Object
Set objGsmProtocol = CreateObject("ActiveXperts.SmsProtocolGsm")
msgbox(objGsmProtocol.Version)
End Sub
To send the SMS we need to collect the information entered the user and use it to send the SMS. When you're writing your script make sure the script stops if any command has not executed properly. You are able to check this using the "LastError" property in our toolkit. Here is an example what you could make your script look like.
Sub sendSMS() 'empty some fields in the form txtStatus.Value = "" txtStatusRecipient.Value = "" txtTime.Value = "" 'create the objects createobjects objGsmProtocol.Clear objSmsMessage.Clear '################# configure the logfile and the device ################## 'set the logfile objGsmProtocol.Logfile = txtLogfile.Value 'select the device objGsmProtocol.Device = cbDevice.Value '############################ Enter the pincode ########################## If objGsmProtocol.LastError = 0 Then If txtPincode.Value <> "" Then objGsmProtocol.EnterPin (txtPincode.Value) Else End If Else End If '######################## Fill in the message type ####################### If objGsmProtocol.LastError = 0 Then 'set default objSmsMessage.Format = objSmsConstants.asMESSAGEFORMAT_TEXT 'unicode multipart messages If cbAllowMultipartMessages = True Then objSmsMessage.Format = objSmsConstants.asMESSAGEFORMAT_TEXT_MULTIPART Else End If 'unicode imidiate display If cbImidiateDisplay = True Then objSmsMessage.Format = 1 Else End If 'unicode messages If cbUnicode = True Then objSmsMessage.Format = objSmsConstants.asMESSAGEFORMAT_UNICODE 'unicode multipart messages If cbAllowMultipartMessages = True Then objSmsMessage.Format = objSmsConstants.asMESSAGEFORMAT_UNICODE_MULTIPART Else End If 'unicode imidiate display If cbImidiateDisplay = True Then objSmsMessage.Format = objSmsConstants.asMESSAGEFORMAT_UNICODE_FLASH Else End If Else End If Else End If '###################### Request message report ########################### If objGsmProtocol.LastError = 0 Then If cbRequestDeliveryReport = True Then objSmsMessage.RequestDeliveryStatus = True Else End If Else End If '#################### Create and send the message ######################## If objGsmProtocol.LastError = 0 Then 'create the SMS objSmsMessage.Recipient = txtRecipient.Value objSmsMessage.Data = txtMessage.Value Else End If If objGsmProtocol.LastError = 0 Then 'send the SMS objGsmProtocol.Send( objSmsMessage ) Else End If '########################### Get the results ############################## 'get the result txtResult.Value = objGsmProtocol.LastError & " : " &_ & objGsmProtocol.GetErrorDescription(objGsmProtocol.LastError) End Sub
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.