Send SMS using VB code

By: Emiley J Emailed: 1757 times Printed: 2448 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

If you are looking for a simple program to send SMS from your PC using VB then here is the code.

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Form_Load()
'Change this with the Baud rate of your modem (The one you use with Hyper Terminal)
' Change this with the port your Modem is attached 

End Sub

Private Sub Command1_Click()
'This line can be removed if your modem will always be in Text Mode...
MSComm1.Output = "AT+CMGF=1" & vbCrLf                          
Sleep 500
'Replace this with your mobile Phone's No.
MSComm1.Output = "AT+CMGS=+91232538538" & vbCrLf       
Sleep 1000
MSComm1.Output = "Hello This is my test message"
Sleep 2000
If InStr(MSComm1.Input, "OK") Then
    MsgBox "Message Send"
    MsgBox "Message Not Send"
End If

End Sub Home | All Tutorials | Latest Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.

Bookmark and Share


1. View Comment

Plz. help me in getting code to read messages using GSM modem using java.

View Tutorial          By: Jaydatta at 2009-04-03 20:58:57
2. View Comment

i tried with d above code but am getting an error with d MScomm connection. Do i need to add any controls to my code?

View Tutorial          By: Aishwarya at 2009-04-05 04:41:17
3. View Comment

aishwarya.. i also have that error.. have you solve the error for tt?

View Tutorial          By: Geok Lin at 2009-04-06 02:26:49
4. View Comment

Plz tell me the classes to import for this code and the declaration of the Variable MScomm

View Tutorial          By: Nitin at 2009-11-10 02:54:50
5. View Comment

I got error during using above code if There is need of any component for this code then pls declare here

View Tutorial          By: Sunil at 2009-12-28 05:22:45
6. View Comment

Hi, You need to place a control on your form

go to project - component and check Microsoft comm control 6.0

View Tutorial          By: Ranjit at 2010-02-09 02:29:40
7. View Comment

i am try this codeing in vb . i am using nokia n73 .the code has been executed but sms can't plz help me

View Tutorial          By: kanyaraj at 2010-02-09 19:10:10
8. View Comment

I have try this code.
Code has Run succeefully but sms has not send
plz help me

View Tutorial          By: Avinash at 2010-06-07 05:38:26
9. View Comment

Hai.. i tried with d above code but am getting an error with d MScomm connection. Plz tell how to recover the error?

View Tutorial          By: muthupandi at 2010-08-17 09:49:23
10. View Comment

Pl provide me code to send sms using USB modems.

View Tutorial          By: Prayag Singh at 2010-09-27 22:50:34
11. View Comment

pl tel me how to open port no

i can one error in the above code but i have one errer
"port no is Invalid"
please tel me how to open port

View Tutorial          By: SUdhir at 2011-01-28 00:21:55
12. View Comment

hi I am execute this code But message can't send
plz help me

View Tutorial          By: Sudhir Patil at 2011-02-01 10:28:28
13. View Comment

i hav d same error as sudhir has "INVALID PORT NUMBER" pls help me guyzz. i m doin in VB 6.0

View Tutorial          By: JAY SHAH at 2011-02-14 09:33:12
14. View Comment

ahmm I guess This is a VB6 program? or how can I go to component using vb2005. . .
@JAY SHAH: If its invalid port number then your modem was not connected or not recognize by your pc or try to import it
Imports System.IO.Ports

View Tutorial          By: kelvin at 2011-02-27 14:07:44
15. View Comment

what is - MSComm1. You haven declared it as a variable in the code? thanks :)

View Tutorial          By: Craig at 2011-05-01 16:37:13
16. View Comment


View Tutorial          By: jAYGANESH at 2011-06-22 02:14:43
17. View Comment

I used code when command button clik , it wil show no mesaage send. If InStr(MSComm1.Input, "OK") Then

here the value is come Zero.

what is error, plz help me

View Tutorial          By: sekh umar at 2011-06-23 01:40:21
18. View Comment

The code is working for me as i have included " in the proper place.

MSComm1.Output = "AT+CMGF=1" & vbCrLf
Sleep 500
MSComm1.Output = "AT+CSCA=""+919440099997""" & vbCrLf
Sleep 500
'Replace this with your mobile Phone's No.
MSComm1.Output = "AT+CMGS=""+91" & TxtTo.Text & """" & vbCrLf

View Tutorial          By: MOHAN at 2011-06-29 04:08:04
19. View Comment

can you gave us a sample form that has a design

View Tutorial          By: niknik at 2011-07-01 09:39:21
20. View Comment

i want source code of Send SMS on Mobile by Net.

View Tutorial          By: Ankit Patel at 2011-07-05 08:43:14
21. View Comment

i tried your code but i got an error on this line


saying that "the device is not open"
how to solve this?
thank you

View Tutorial          By: edward at 2011-12-09 11:32:30
22. View Comment

run time error is there ,doest worked... please help out..

View Tutorial          By: ali at 2012-02-25 21:52:21
23. View Comment

I have ran this code but each port has raised an "invalid port" error, what should i do?

View Tutorial          By: Jawnie at 2012-03-29 07:23:22
24. View Comment

I executed your code but i get the error "OK +CMS ERROR : 302"

View Tutorial          By: Denzil at 2013-01-18 09:33:37
25. View Comment

can anyone tell how to send sms in using pc suite?
plz tell me...

View Tutorial          By: dubail at 2013-04-06 14:17:44

Your name (required):

Your email(required, will not be shown to the public):

Your sites URL (optional):

Your comments:

More Tutorials by Emiley J
Password must include both numeric and alphabetic characters - Magento
What is Hadoop?
Returning multiple values from a web service
Tomcat and httpd configured in port 8080 and 80
Java Webservices using Netbeans and Tomcat
Java WebService connected to Database
How to Deploy a Java Web Service
Call a webservice in Java
Java WebService - Create your first web service in Java
package javax.jws does not exist
Getting Started with Android
HTML5 Location - getCurrentPosition() in HTML5
HTML5 Canvas - Using Canvas in HTML5
HTML5 - Introduction
HTML5 Video - Handling video in HTML5

More Tutorials in
Scope in
Unstructured Exception Handling in
Structured Exception Handling in
Creating Sub Procedures in
Creating Functions in
Passing a Variable Number of Arguments to Procedures in
Specifying Optional Arguments with default values in Procedures in
Preserving a Variable's Values between Procedure Calls in
Procedure Delegates in
Properties in
Understanding Scope in
Using Resume Next and Resume Line in
Using On Error GoTo 0 in
Getting an Exception's Number and Description in
Raising an Exception Intentionally in

More Latest News
Most Viewed Articles (in )
How to export from DataGridView to excel using
Your first VB.NET Crystal Reports - A step by step guide
How to export from database to excel using
Insert cell data in an Excel file using OLEDB in
The Option and Imports Statements in VB .NET
Handling Dates and Times in
Sub Procedures and Functions in
A tutorial on Chat Server and Chat Client in
To read the entire worksheet in an Excel workbook through Code
What's New in VB .NET? A comparison of VB vs
Arrays and Dynamic Arrays in
How To Connect To A MySql Database in
How to Open and Edit Cells in an Excel 2007 file in VB.NET
Using Resume Next and Resume Line in
For Loop in
Most Emailed Articles (in
How to export from DataGridView to excel using
How to send email using VB.NET code
Data types in
Arrays and Dynamic Arrays in
If…Else Statements in
ArrayList data structure in
Name Value Collecion in
Implicit & explicit type Conversion in
String equals, Copy to & Copy to in
File stream operations in binary reader and writer
Insert cell data in an Excel file using OLEDB in
Update cell data in an Excel file using OLEDB in
How to find IP Address of Host using .net code
Specifying Optional Arguments with default values in Procedures in