Monday, January 25, 2016

How To Send (Short Message System) sms with visual basic .net?


If YOU want to make your application can send sms below is a visual basic code for sending sms.

Yes this is simple vb code for sending sms. 
Often people want to make transactions credit with sms software.

ok just below is its form:



below is complete code:

Imports System.IO.PortsImports System.Threading.ThreadPublic Class Form1    Private Tunda As Integer
    Private WithEvents COMport As New SerialPort    Private Sub Form1_Load(ByVal sender As ObjectByVal e As System.EventArgsHandles Me.Load

        For Each COMString As String In My.Computer.Ports.SerialPortNames
            cboCOMPort.Items.Add(COMString)
        Next        cboCOMPort.Sorted = True    End Sub
     Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandlesButton1.Click

        COMport.PortName = cboCOMPort.Text
        COMport.BaudRate = 19200
        COMport.WriteTimeout = 2000

        Try           COMport.Open()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try        Sleep(300)   '....waiting 0.3 seconds          tunda  = 300
        Sleep(tunda)
        Application.DoEvents()

        If COMport.IsOpen Then
            Try
                Dim x As String = "AT+CMGF=1" & Chr(13)
                COMport.Write(x)
                Sleep(tunda)
                Dim y As String = "AT+CMGS=" & Chr(34) & txtNoHP.Text & Chr(34) & Chr(13)
                COMport.Write(y)
                Sleep(tunda)
                Dim z As String = txtPesan.Text & Chr(26)
                COMport.Write(z)
                Sleep(tunda)

            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        Else
            MsgBox("COM port tertutup.")
        End If

End
 Sub
End Class

Below sended SMS to My Hanphone:




ok