Send SMS using VB code

By: Emiley J Emailed: 1643 times Printed: 2110 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)
MSComm1.Settings="9600,n,8,1"        
' Change this with the port your Modem is attached 
MSComm1.CommPort=1                     
MSComm1.PortOpen=TRUE            

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"
Else
    MsgBox "Message Not Send"
End If

End Sub

VB.net Home | All VB.net Tutorials | Latest VB.net 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

Comments(25)


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 send.so 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
Thanks


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

1. U R NOT CONNECTED UR MOBILE WITH SYS
2. AFTER INSTALL PROPER SYSTEM DRIVER FOR UR MOBILE
3. THEN TRY


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

MSComm1.PortOpen=TRUE

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

MSComm1.Settings="9600,n,8,1"
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 asp.net 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 VB.net
Scope in VB.net
Unstructured Exception Handling in VB.net
Structured Exception Handling in VB.net
Creating Sub Procedures in VB.net
Creating Functions in VB.net
Passing a Variable Number of Arguments to Procedures in VB.net
Specifying Optional Arguments with default values in Procedures in VB.net
Preserving a Variable's Values between Procedure Calls in VB.net
Procedure Delegates in VB.net
Properties in VB.net
Understanding Scope in VB.net
Using Resume Next and Resume Line in VB.net
Using On Error GoTo 0 in VB.net
Getting an Exception's Number and Description in VB.net
Raising an Exception Intentionally in VB.net

More Latest News
Most Viewed Articles (in VB.net )
String Split function in VB.net
Create an Excel 2007 file in VB.NET 2005
Debug and Release Versions in .NET
Queue data structure in VB.net
How to use string chars (str.Chars() ) in VB.net
Passing a Variable Number of Arguments to Procedures in VB.net
Do Loop in VB.net
Insert Pictures in Excel 2007 from VB.NET 2005
Read Data from Excel using OLEDB in VB.NET 2005
How to export from DataGridView to excel using VB.net
Your first VB.NET Crystal Reports - A step by step guide
How to send email using VB.NET code
How to find IP Address of Host using .net code
Multi Threaded Server Socket Programming in VB.net
DataSet Class in VB.net
Most Emailed Articles (in VB.net)
Multi threaded Socket Programming in VB.net
Nested If and Single line if statement
Vb.net binary reader and writer
How to Open and Edit Cells in an Excel 2007 file in VB.NET
Format Excel 2007 Page in VB.NET
How to create an XML file in VB.net
Structured Exception Handling in VB.net
How To Connect To A MySql Database in VB.net
To read the entire worksheet in an Excel workbook through VB.net Code
Using Excel 2007 Chart in VB.NET 2005
How to send email using VB.NET code
How to find IP Address of Host using .net code
Chat client in VB.net
Properties in VB.net
“Using If with And” and Comparing two integers using If