Receive SMS in Visual Basic

Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
4 posts Page 1 of 1
Contributors
User avatar
astheyfall
VIP - Donator
VIP - Donator
Posts: 160
Joined: Sun Sep 19, 2010 6:13 am

Receive SMS in Visual Basic
astheyfall
Hello, I need to know how to receive SMS in visual basic and the message goes to a textbox.

Thank you,
AsTheyFall
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: Receive SMS in Visual Basic
mandai
If your phone can be used as a GSM modem, you can use this:
Code: Select all
    Dim log As String = ""
    Dim stage As Integer = 0

    Sub sp_DataReceived(ByVal sender As SerialPort, ByVal e As SerialDataReceivedEventArgs)
        Dim buffer(sender.BytesToRead - 1) As Byte
        sender.Read(buffer, 0, buffer.Length)

        Dim rec As String = Encoding.ASCII.GetString(buffer)
        log += rec

        'MsgBox(log) 'debug

        If log.EndsWith("ERROR" & vbCrLf) Then
            sender.Close()
            MsgBox("Error at stage " & stage)

            If stage = 2 Or stage = 3 Then
                MsgBox("Error issuing CNMI command")
            End If

            MsgBox(log)
            stage = 0
            log = ""

        ElseIf log.EndsWith("OK" & vbCrLf) Then

            If stage = 0 Then
                log = ""
                stage += 1

                sender.Write("AT+CMGF=1" & vbCrLf) ' set to text mode

            ElseIf stage = 1 Then
                log = ""
                stage += 1

                sender.Write("AT+CNMI=?" & vbCrLf) 'check support for CNMI command

            ElseIf stage = 2 Then
                log = ""
                stage += 1

                sender.Write("AT+CNMI=0,1,0,0,0" & vbCrLf) 'Your manufacturer will know these paramaters

            End If

        End If

        If stage = 3 Then
            txtMessage.Text = log
        End If

    End Sub

    Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click

        Dim sp As SerialPort = New SerialPort("COM5") 'use the COM port of your modem device

        Try
            sp.Open()
        Catch ex As Exception
            MsgBox("Error opening port: " & ex.Message)
            Return
        End Try

        AddHandler sp.DataReceived, AddressOf sp_DataReceived
        sp.Write("AT" & vbCrLf) 'OK expected
    End Sub
From my understanding this should work, as long as your phone supports the CNMI command and you use the right paramaters.
User avatar
astheyfall
VIP - Donator
VIP - Donator
Posts: 160
Joined: Sun Sep 19, 2010 6:13 am

Re: Receive SMS in Visual Basic
astheyfall
Thank you but is there another way?
User avatar
Napster1488
VIP - Donator
VIP - Donator
Posts: 524
Joined: Fri Jan 07, 2011 8:41 pm

Re: Receive SMS in Visual Basic
Napster1488
astheyfall wrote:
Thank you but is there another way?
If u have Nokia Phone connected to Pc you can use the SDK to Recieve/Send SMS.
YouTube Downloader v3.0
Image
Image
Image
4 posts Page 1 of 1
Return to “Tutorial Requests”