ActiveXperts SMS Component

Quicklinks

VBScript sample - Receive SMS text through an SMPP provider

The ActiveXperts SMS Component is a software development kit (SDK) to enhance an application or script with SMS or Pager functionality. SMS messages can be sent/received using a GSM modem, an SMPP provider or an HTTP compliant SMSC.


Introduction

In this example we are going to create a VBScript to receive SMS messages.

A subscription to an SMPP provider is required. For this demo you can send a limited number of messages through our own gateway.

Step 1: Download and install The ActiveXperts SMS Component

Download the ActiveXperts SMS Component from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.

Step 2: Create a new script

Create a new script using your favorite editor. You can simply use notepad. However, a VBScript editor is recommended, so you can browse through objects, objects properties and object functions.

You're now able to write a more advanced VBScript script to receive SMS using SMS Component.

Step 3: Create the ActiveXperts SMS Component objects in VBScript

Create a new VBScript file called DEMO.VBS. It is recommended to insert the following line on top of your code:

Option Explicit

This statement requires that all variable names be defined (with the Dim statement), to avoid simple typos that can cause incredible headaches and long debugging sessions for something that should have never happened.

Now, declare the ActiveXperts SMS Component SMPP objects:

Dim objSmpp
Dim objSmsMessage
Dim objSmsConstants

Create the objects like this:

Set objSmpp          = CreateObject( "AxSms.Smpp" )
Set objSmsMessage    = CreateObject( "AxSms.Message" )
Set objSmsConstants  = CreateObject( "AxSms.Constants" )

Now, add the following lines to the file to have your fist SMS Component VBScript program:

WScript.Echo "License Status: " & objSmpp.LicenseStatus

Step 4: Receive SMS messages

You can now receive SMS messages.

The following VBScript code shows how to connect to a SMPP provider and receive a SMS message:

For i = 1 To 60
  Set objMessage = objSmpp.ReceiveMessage()
  Wscript.Echo "ReceiveMessage, result: " & objSmpp.LastError
  While objSmpp.LastError = 0
    WScript.Echo "Received FromAddress: " & objMessage.FromAddress
    WScript.Echo "Body: " & objMessage.Body
    Set objMessage = objSmpp.ReceiveMessage()  
    Wscript.Echo "ReceiveMessage, result: " & objSmpp.LastError
  WEnd  
  WScript.Sleep( 1000 )
Next

Appendix: Full source code

Following you can find the full source code which is also included in the ActiveXperts SMS Component package.

' ********************************************************************
'
'    Receive messages through an SMPP connection.
'
'    This script will listen for incoming messages for one minute.
'	 ActiveXperts SMS Component
'
' (c) Copyright 2011 by ActiveXperts Software - www.activexperts.com
'
' ********************************************************************

Option Explicit

' Declare Objects
Dim objSmpp, objMessage, objSmsConstants

' Declare Variables
Dim strServer, nPort, nTimeout, strUsername, strPassword, strPhoneNumber, i

' Create Objects
Set objSmpp                   = CreateObject ( "AxSms.Smpp" )
Set objSmsConstants           = CreateObject ( "AxSms.Constants"    )

' Set Logfile
Dim fso: Set fso              = CreateObject("Scripting.FileSystemObject")
objSmpp.LogFile               = fso.GetSpecialFolder(2) & "\SMPP_receivesms.txt"
WScript.Echo "Log file can be found here:"
Wscript.Echo objSmpp.LogFile

' Display SMS Component Version
WScript.Echo "SMS Component Version " & objSmpp.Version & "; " &_
                                      "Build " & objSmpp.Build & "; " &_
                                      "Module " & objSmpp.Module

'Get username and password for ActiveXperts SMPP Demo account
GetSMSDemoAccountInfo strUsername, strPassword

' Display if the ActiveXperts SMS Component is registered.
WScript.Echo "License Status: " & objSmpp.LicenseStatus & vbCrLf 

' Set SMPP Server
strServer      = ReadInput ( "Enter hostname of SMPP server", "smpp.activexperts-labs.com", False )

' Set SMPP ServerPort
nPort          = ReadInput ( "Enter portnumber of SMPP server", 2775, False )

' Set SMPP SystemID
strUsername    = ReadInput ( "Enter account systemID", strUsername, False )

' Set SMPP Password
strPassword    = ReadInput ( "Enter account password", strPassword, False )

' Set your phonenumber
strPhoneNumber = "S" & ReadInput ( "Enter your phonenumber", "+", False )

nTimeout = 2000

' Connect to smpp provider
objSmpp.Connect strServer, nPort, nTimeout

WScript.Echo "Connect, result: " & objSmpp.LastError
If ( objSmpp.LastError <> 0 ) Then 
  WScript.Sleep 3000
  WScript.Quit
End If 

objSmpp.Bind objSmsConstants.SMPP_BIND_TRANSCEIVER, strUsername, strPassword, "", 
             objSmsConstants.SMPP_VERSION_34, 0, 0, strPhoneNumber, nTimeout
Wscript.Echo "Bind, result: "
If ( objSmpp.LastError <> 0 ) Then
  WScript.Sleep 3000
  WScript.Quit
End If


WScript.Echo "Connected to provider" & vbCrLf & vbCrLf & "Send an SMS message to the SMPP gateway"
WScript.Echo "(Mobile number: +31625380808) and click OK" & vbCrLf & "This demo will check for new"
WScript.Echo "messages during 60 seconds."
  
For i = 1 To 60
    Set objMessage = objSmpp.ReceiveMessage()
    Wscript.Echo "ReceiveMessage, result: " & objSmpp.LastError
    While objSmpp.LastError = 0
      WScript.Echo "Received FromAddress: " & objMessage.FromAddress
      WScript.Echo "Body: " & objMessage.Body
      Set objMessage = objSmpp.ReceiveMessage()  
      Wscript.Echo "ReceiveMessage, result: " & objSmpp.LastError
    WEnd  
  WScript.Sleep( 1000 )
Next

objSmpp.Disconnect ' Disconnect
WScript.Echo "Disconnected."

WScript.Echo "Ready."
WScript.Sleep 3000


' ***************************************************************************
' Function ReadInput
' ***************************************************************************
Function ReadInput( ByVal strTitle, ByVal strDefault, ByVal bAllowEmpty )

  Dim strInput, strReturn

  Do
     strInput = inputbox( strTitle, "Enter value", strDefault )
     If ( strInput <> "" ) Then
          strReturn = strInput
     End If
  Loop until strReturn <> "" Or bAllowEmpty

  ReadInput = strReturn
End Function

' ***************************************************************************
' Function GetSMSDemoAccountInfo
' ***************************************************************************
Function GetSMSDemoAccountInfo(ByRef strSystemID, ByRef strPassword)
  Dim objRegistery, objFileSystem, objTextFile
  Dim strInstallRoot, strAccountFile
  
  Set objRegistery            = CreateObject("WScript.Shell")
  Set objFileSystem           = CreateObject("Scripting.FileSystemObject")
  
  strInstallRoot              = 
  objRegistery.RegRead("HKLM\SOFTWARE\\ActiveXperts\\SMS Component\\InstallRoot")
  strAccountFile              = strInstallRoot
  strAccountFile              = strAccountFile & "\\Utilities\\activexperts-labs.txt"

  If objFileSystem.FileExists(strAccountFile) Then
    Set objTextFile           = objFileSystem.OpenTextFile(strAccountFile)
                                objTextFile.ReadLine 'Skip firstline
    strSystemID               = objTextFile.ReadLine '2nd line SystemID
    strPassword               = objTextFile.ReadLine '3rd line Password
    objTextFile.Close  
  End If
End Function

You can download the full source code of this project from the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/sms-component. There are many other working samples included with the product or on the FTP site.

NOTE: Demo Projects are created with Microsoft Visual Studio 2008

The ActiveXperts SMS Component project ships with a set of Microsoft Visual Studio .NET samples. The projects are created with Microsoft Visual Studio 2008.

Users with a later version of Microsoft Visual Studio can open such a project. The Visual Studio Conversion Wizard will guide you through the process of converting the project to the version used.