Automatic SMS on an Event from PC to Mobile VB6 Code


Here is VB-6 programming Code for sending automatic SMS on an Event like “fire at home” or  “Power Failure” or “House Security Broken” or “Locker Broken” etc.   In these Events an electromechanically relay will actuate through electronic unit  and  pre typed event message will select and sent SMS  from PC to Mobile.

Download code

Visit My web page :

VB6 Code

Option Explicit

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

Dim message As Integer

Dim Pat, Eve, Msg, Msg1, Msg2, Msg3

Private Sub Form_Load()

‘MSComm1.PortOpen = False

MSComm1.Settings = “9600,n,8,1”     ‘Change this with the Baud rate of your modem

MSComm1.CommPort = 5                   ‘Change this with the port your Modem is attached,

MSComm1.PortOpen = True

With MSComm1

‘.CommPort = 5

.Settings = “9600,N,8,1”

.Handshaking = comRTS

.RTSEnable = True

.DTREnable = True

.RThreshold = 1

.SThreshold = 1

.InputMode = comInputModeText

.InputLen = 0

‘.PortOpen = True ‘must be the last

End With

End Sub

Private Sub Command1_Click()

‘ Send an ‘AT’ command to the phone

MSComm1.Output = “AT” & vbCrLf

Sleep 500

MSComm1.Output = “AT+CMGF=1” & vbCrLf           ‘This line can be removed if your modem will always be in Text Mode…

Sleep 500

MSComm1.Output = “AT+CMGS=” & Chr(34) & 9794150541# & Chr(34) & vbCrLf  ‘Replace (TxtNumber.Text) this with your mobile Phone’s No.

Sleep 1000

MSComm1.Output = Label8.Caption & Chr(26)      ‘Replace (TxtMessage.Text) this with your Message .

Sleep 2000

‘MsgBox “Message Send”

End Sub

Private Sub Timer1_Timer()

Label3.Caption = Format(Date, “dd-mm-yyyy”)

Label4.Caption = Time


Text2.Text = MSComm1.CommPort

Text3.Text = MSComm1.Settings


Eve = Text1.Text

If Eve = 0 Then GoTo Msg1

If Eve = 1 Then GoTo Msg2

If Eve = 2 Then GoTo Msg3



Label8.Caption = “No Event System is on Stanby”

GoTo Last



Label8.Caption = “11-KV OFF Power has Failed at ” & Label4.Caption

GoTo Last



Label8.Caption = “11-KV ON Power has Resumed at ” & Label4.Caption

GoTo Last



Sleep (2000)

If Text1.Text = 0 Then GoTo NOSMS Else GoTo SMS



Call Command1_Click

Text1.Text = 0



End Sub

Private Sub Command2_Click()


End Sub

**********************************The End *******************************

About adeebraza1236

I am an electronic instrumentation engineer by profession but I am working as a design engineer. I can design electronic hardware interface circuits for computer based security system, Computer based industrial control system for automation and process control Etc. My Interests: Electronics Circuit designing with PCB Designing, Computer software development using VB & C , PC based security system, Designing LED Lights, UPS, Inverter Etc
This entry was posted in Uncategorized, Visual Basic 6 Code and tagged , , , . Bookmark the permalink.

2 Responses to Automatic SMS on an Event from PC to Mobile VB6 Code

  1. Ahsan says:

    AOA. I tried your code, but the Excel VBA environment returned the error that MSComm1 is an undefined variable. Any idea why this might be? Thanks

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s