Saturday, 17 December 2016

Sending SMS Messages with Visual Basic

Select a serial port from tool box and add one button,one text box and rich text box then write following code .
 Private Sub add_new_item_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       
        On Error Resume Next
        SerialPort1.PortName = "Com13"
        SerialPort1.BaudRate = 9600
        SerialPort1.Parity = Parity.None
        SerialPort1.StopBits = StopBits.One
        SerialPort1.DataBits = 8
        SerialPort1.Handshake = Handshake.RequestToSend
        SerialPort1.DtrEnable = True
        SerialPort1.RtsEnable = True
        SerialPort1.NewLine = vbCrLf

    End Sub
 Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click

        Dim message As String
        On Error Resume Next
            message = rchSubject.Text

            SerialPort1.Open()
            If SerialPort1.IsOpen() Then
                SerialPort1.Write("AT" & vbCrLf)
                SerialPort1.Write("AT+CMGF=1" & vbCrLf)
                SerialPort1.Write("AT+CMGS=" & Chr(34) & txtNumber.Text & Chr(34) & vbCrLf)
                SerialPort1.Write(message & Chr(26))
                MsgBox("Sent")
            Else
                MsgBox("Port not available")
        End If
    End Sub

0 comments:

Post a Comment