by Jeremy (5 Submissions)
Category: OLE/COM/DCOM/Active-X
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 31st July 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)
VBScript Sample: Send an SMS message through a hayes compatible, mobile phone. Tested with Nokia 6310, Nokia 6310i and Ericsson F221.
' Download it from http://www.vahland.com/pub/asmsctrl.dll
' and register it on your machine.
' Read http://www.vahland.com/pub/asmsctrl.htm for more info
Option Explicit
Dim asObj
Set asObj = CreateObject( "ActiveXperts.SMSC" )
' MODEM PROPERTIES
Do
asObj.PortID = inputbox( "On which Comport is modem or GSM connected? (1, 2, 3, ..)", "Input" )
Loop until asObj.PortID <> ""
' SENDER and RECIPIENT
asObj.Sender = "00000000000" ' Set your phone number here; only digits are allow, minimum 1 character, max. 16 characters
Do
asObj.Recipient = inputbox( "Enter the recipients phone number (only digits allowed, no spaces etc.)", "Input" )
Loop until asObj.Recipient <> ""
' MESSAGE
Do
asObj.MessageText = inputbox( "Enter the message text you want to send to the recipient. Only the first 160 characters of the message will be sent", "Input" )
Loop until asObj.MessageText <> ""
' Send the mesage to the recipient through the locally connected GSM phone
WScript.Echo "Sending the message..."
asObj.SendMessage FALSE ' FALSE means: not through provider, but through direct connected GSM
If( asObj.LastError <> 0 ) Then
WScript.Echo "Failed to send message, error: " & asObj.LastError & " (" & GetErrorString( asObj.LastError ) & ")"
WScript.Echo "To trace all commands sent/received through modem, set the 'LogFile' property,"
WScript.Echo "for instance, asObj.LogFile = " & Chr( 34 ) & "c:\mylog.txt" & Chr( 34 ) & "."
Else
WScript.Echo "Message successfully delivered"
End If
' ********************************************************************
Function GetErrorString( lError )
GetErrorString = "Unknown error"
Select Case lError
Case 0
GetErrorString = "SUCCESS"
Case 1
GetErrorString = "Evaluation period has expired"
Case 2
GetErrorString = "License was entered, but invalid"
Case 10
GetErrorString = "Invalid provider dial string"
Case 11
GetErrorString = "Message was sent to SMS provider, but no reponse received"
Case 12
GetErrorString = "Message was sent to SMS provider, SMS provider reported a synax error"
Case 13
GetErrorString = "Message was sent to SMS provider, SMS provider didn't accept message"
Case 30
GetErrorString = "Invalid sender address"
Case 31
GetErrorString = "Invalid recipient address"
Case 32
GetErrorString = "Invalid message"
Case 50
GetErrorString = "No response from modem"
Case 51
GetErrorString = "Unexpected response from modem"
Case 52
GetErrorString = "Error response from modem"
Case 53
GetErrorString = "No dialtone detected upon attempt to connect to remote party"
Case 54
GetErrorString = "No carrier reported while connecting to remote party"
Case 55
GetErrorString = "No answer reported while connecting to remote party"
Case 56
GetErrorString = "Busy tone reported while connecting to remote party"
Case 100
GetErrorString = "Generic port Error"
Case 101
GetErrorString = "Invalid parameter"
Case 102
GetErrorString = "Invalid port. Most probably, port does not exist or is in use"
Case 103
GetErrorString = "Unable to perform operation because port it already opened"
Case 104
GetErrorString = "Generic open port error"
Case 105
GetErrorString = "Unable to initialize port"
Case 106
GetErrorString = "Unable to write to port"
Case 107
GetErrorString = "Unable to write directly to port"
Case 108
GetErrorString = "Unable to read from port"
Case 109
GetErrorString = "Unable to retrieve device information"
Case 110
GetErrorString = "Unable to change device settings"
Case 111
GetErrorString = "Unable to purge the port"
Case 112
GetErrorString = "Timeout"
End Select
End Function
No comments have been posted about VBScript Sample: Send an SMS message through a hayes compatible, mobile phone. Tested with Nokia 63. Why not be the first to post a comment about VBScript Sample: Send an SMS message through a hayes compatible, mobile phone. Tested with Nokia 63.