SMS for the office / SMS for software developers



SMS software for GSM modem/phones SMS Tutorials >

Sending SMS from VB6 (Visual Basic 6)


This tutorial illustrates how to send and receive SMS from Visual Basic 6 (VB6) using the SMSLibX ActiveX component (DLL library).

The tutorial shows how to:

  • build a new SMS application in Visual Basic (VB6) step-by-step;
  • integrate SMS communication into an already existing VB6 application;
  • download some ready-to-use SMS source code examples in VB6 and adapt them to your needs.


The reference environment is Microsoft Visual Basic 6.
A minimal expertise on Visual Basic programming is required.


Installing SMSLibX

  1. Download and install SMSLibX on your PC.
  2. (Optional) Download and install our VB6 source code examples.
  3. Connect and install your GSM modem or phone to your PC.
    If you don't have a compatible GSM modem/phone, then you can use SMSLibX in simulation mode.


Integrating SMSLibX on VB6

  1. Open an existent Visual Basic project or create a new one.
  2. Set up a reference to SMSLibX library (Project > References menu).
    If you can't find SMSLibX into the list, please search it with the Browse button.
  3. Open or create a new form or class module, then open its source code (View > Code menu).
    Please avoid integrating SMSLibX into common modules (.bas), as they're not able to catch events.

Now you're ready to use SMSLibX objects and methods directly in your source code.


Sending and receiving SMS with VB6

The following Visual Basic (VB6) source code might be used into a VB6 form in order to send and receive SMS messages. With few modifications this code can be inserted in a VB6 class module too.

The WithEvents clause is essential in order to catch events raised by the SMSModem object.

' Declare SMSModem object
Public WithEvents Modem As SMSModem

' Send SMS
Private Sub cmdSendMessage_Click()
  ' Open modem communication
  Set Modem = New SMSModem
  Modem.LogTrace = True
  Modem.OpenComm ModemType, ModemPort, , smsNotifyAll
  ' Send message
  Call Modem.SendTextMessage(PhoneNumber, MessageText)

End Sub

' Receive SMS by event
Private Sub Modem_MessageReceived(Message As SMSLibX.SMSDeliver)
  MsgBox "New message received from " & Message.Originator & ":" _
    & vbCrLf & vbCrLf & Message.Body, _
    vbInformation, "New message received"
End Sub


Using SMSLibX in your IDE

For a brief introduction on SMSLibX usage we recommend the Quick start section from SMSLibX Help.

SMSLibX is fully integrated into the Microsoft development environment:

  • To display contextual help on a selected SMSLibX item, just click F1.
  • To browse SMSLibX library items, please open the Object Viewer (F2) and select SMSLibX library.
  • You can use code completion when writing code using SMSLibX objects (Ctrl+SPACE, Ctrl+J etc.)


SMS source code examples in VB6 (Visual Basic 6)

The following examples provided with VB6 source code are available for download:

  • Example1
    Minimal example with SMS sending and event-based SMS receival.

  • Example2
    A complete example showing most SMSLibX features.
    This example is in fact the original source code of the SMSLibX Test Utility distributed together with SMSLibX installation.

Both examples are pre-configured for simulation mode (they do not send real SMS).

Once you got them working on yoir PC, you can configure them in order to use your actual GSM modem/phone by opening the main form source code (View > Code menu) and modifying the 'TO DO' items.

If you experience some troubles, please refer to the "Troubleshooting" section.


SMSLibX events and VB6 programming

Please read these notes carefully – they are very important for a good SMSLibX programming practice!


MsgBox and received SMS messages

If your VB6 application makes use of MsgBox and InputBox, please note that VB6 suppresses events from timers, forms, controls and ActiveX components while one of these dialogs is open.
Events are not simply delayed but definitively suppressed (please see Microsoft Knowledge Base 76557 article).

Due to this disagreeable behaviour, if a MsgBox is open your application may loose events notifying received messages - and any other event generated by SMSLibX.

As work-around, we suggest redefining the VB6 MsgBox function and replacing it with the MessageBox API from Windows (which does not suppress events: please see Microsoft Knowledge Base 76557 article for details).
A concrete MsgBox re-definition example is available in the source code of the Example2.


Yielding control in your loops

If your VB6 application cycles over a list of SMS messages to be sent - or performs some other time-consuming operations - then you should provide a DoEvents statement in your loop (or time-consuming operaton).

This will permit SMSLibX to continue raising its events in real-time (such as received messages, delivery reports and modem status events).

Moreover, your SMSLibX event listeners (the code you write inside an event procedure) should never contain time-consuming operations, since SMSLibX relies on the event calling thread for further message capture and notification.




SMSLibX registration problems

When opening the examples you might experience some troubles due to missing SMSLibX registration on your system.

Should the following errors appear:

  1. [...] Cannot find project or library...
  2. ActiveX component cannot create object...

please restore SMSLibX references as explained in the first part of this tutorial.


Other problems with SMSLibX

Please refer to the Troubleshooting section of SMSLibX Help.



  • SMS for your business

    - Working teams
    Contact your customers and mobile co-workers by SMS.
    - Mobile marketing
    Contact your audience with friendly SMS communication.

  • SMS for public services

    - Services and associations
    Contact service subscribers and associates by SMS.
    - Commercial consultants
    Remind fiscal deadlines to your customers with an SMS.
    - Medical offices
    Send appointment reminders to your patients by SMS.
    - Schools
    Keep in contact with parents and students by SMS.

  • Do more with SMS...