You are here:
ActiveXperts.com > SMS Messaging Server > How to create a new Message > Visual Basic .NET
Quicklinks
SMS Messaging Server is an SMS messaging framework that enables companies to send, receive and process SMS- and e-mail messages. The framework is designed support virtually any scenario where low-and high volume SMS messaging is required. Use SMS Messaging Server in the following scenarios:
SMS Messaging Server can be well integrated into VBScript environments. This document describes how the SMS Messaging Server can be integrated into VBScript projects.
Download ActiveXperts SMS Messaging Server from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.
Launch Microsoft Visual Studio (for instance 'Microsoft Visual Studio 2005') from the Start menu. Choose 'New' from the 'File' menu and click on 'Project'. In the 'New Project' dialog, select a Visual Studio template (for instance: 'Console Application'). Select a name for the application (for instance: 'DemoApp') and a name for the solution (for instance: 'DemoSolution'). Also, select the directory where you want to store the project (for instance: 'C:\MyProjects):
(Click on the picture to enlarge)
Now that a new project has been created, you must add a reference to the SMS Messaging Server API in the project to be able to use the it. To do so, choose 'Add Reference...' from the 'Project' menu. In the 'Add Reference' dialog that pops up, select the 'COM' tab and select the 'ActiveXperts SMS Messaging Server API Type Library' as shown in the following picture:
(Click on the picture to enlarge)
Click 'OK' to close the 'Add Reference' dialog.
On top of your code, type the following line to use the SMS Messaging Server API namespace:
Imports AXMMCFGLib
In your Main function, declare and create the following objects:
Public objMessageDB As IXMessageDB Public objConstants As IXConstants
You can now send an SMS message.
The following code shows how to send a SMS message:
Imports AXMMCFGLib
Module Module1
Public objMessageDB As IXMessageDB
Public objConstants As IXConstants
Sub Main()
Dim numRecordID As Integer
objMessageDB = New XMessageDB()
objConstants = New XConstants()
objMessageDB.Open()
If (objMessageDB.LastError <> 0) Then
Console.WriteLine("Unable to open database, error: " & objMessageDB.LastError)
Exit Sub
End If
numRecordID = CreateSmsMessage()
If (numRecordID > 0) Then
PrintMessage(numRecordID)
End If
objMessageDB.Close()
Console.WriteLine("Ready.")
End Sub
Function CreateSmsMessage()
CreateSmsMessage = 0
Dim objMessage As IXMessage
objMessage = objMessageDB.Create()
If (objMessageDB.LastError <> 0) Then
Console.WriteLine("Create failed, error: " & objMessageDB.LastError)
Exit Function
End If
Console.WriteLine("Message successfully created, recordID: " & objMessage.ID)
objMessage.Direction = objConstants.MESSAGEDIRECTION_OUT
objMessage.Type = objConstants.MESSAGETYPE_SMS
objMessage.Status = objConstants.MESSAGESTATUS_PENDING
objMessage.ChannelID = 0
objMessage.ScheduledTime = ""
objMessage.Recipient = "+31624896641"
objMessage.Body = "SMS Messaging Server - Test SMS Message"
objMessageDB.Save(objMessage)
If (objMessageDB.LastError <> 0) Then
Console.WriteLine("Update message failed, error: " & objMessageDB.LastError)
Exit Function
End If
CreateSmsMessage = objMessage.ID
End Function
Sub PrintMessage(ByVal numID)
Dim objMessage As XMessage
objMessage = objMessageDB.Load(numID)
If (objMessageDB.LastError <> 0) Then
Console.WriteLine("Failed to load message " & numID)
Exit Sub
End If
Console.WriteLine(" ID : " & objMessage.ID)
Console.WriteLine(" Direction : " & objMessageDB.GetDirectionDescription(objMessage.Direction))
Console.WriteLine(" Type : " & objMessageDB.GetTypeDescription(objMessage.Type))
Console.WriteLine(" Status : " & objMessageDB.GetStatusDescription(objMessage.Status))
Console.WriteLine(" StatusDetails : " & objMessageDB.GetStatusDetailsDescription(objMessage.StatusDetails))
Console.WriteLine(" ChannelID : " & objMessage.ChannelID)
Console.WriteLine(" MessageReference : " & objMessage.MessageReference)
Console.WriteLine(" ScheduledTime : " & objMessage.GetScheduledTimeString())
Console.WriteLine(" LastUpdate : " & objMessage.GetLastUpdateString())
Console.WriteLine(" Sender : " & objMessage.Sender)
Console.WriteLine(" Recipient : " & objMessage.Recipient)
Console.WriteLine(" Subject : " & objMessage.Subject)
Console.WriteLine(" Body : " & objMessage.Body)
Console.WriteLine(" Trace : " & objMessage.Trace)
End Sub
End Module