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.
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
Hello, I need to know how to receive SMS in visual basic and the message goes to a textbox.
Thank you,
AsTheyFall
Thank you,
AsTheyFall
If your phone can be used as a GSM modem, you can use this:
Code: Select all
From my understanding this should work, as long as your phone supports the CNMI command and you use the right paramaters. 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
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.
4 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023