Sending an SMS with Visual Basic

Source text: TcSmsSrvVbTest.exe

Task

A simple Visual Basic program for sending an SMS.

Description

In this example, the ADS-OCX is used to establish an ADS connection to the TwinCAT SMS Server. The SMS text and the telephone number can be entered on a form. The message is then sent by clicking a button.

Form

Sending an SMS with Visual Basic 1:

The input fields have the names ebText and ebNumber, and the button is named btSend.

The ADS-OCX must also be dragged on to the form. You will find more precise information in the documentation for the ADS-OCX.

Visual Basic program

Option Explicit

Private Sub Form_Load()
    ' port of the TwinCAT SMS server
    AdsOCX1.AdsAmsServerPort = 10400
End Sub

Private Sub btSend_Click()
    On Error GoTo ERRORHANDLER
    Dim message As String
 
    ' create the XML message   
    message = "<Msg><Targets><Target><No>" & _
    ebNumber & _
    "</No></Target></Targets><Body><![CDATA[" & _
    ebText & _
    "]]></Body></Msg>"

    AdsOCX1.AdsSyncWriteStringReq &H4000, 1, LenB(message), message
  
    Exit Sub
ERRORHANDLER:
    MsgBox "Error " & Err.Number & ": " & Err.Description
End Sub