Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to answer sms automatically?

Status
Not open for further replies.

Mandy_crw

Programmer
Jul 23, 2020
591
PH
I have these codes taken from this site where i can send sms using GSM phone, i tried edting it and use, everything worked well... Until i thought of putting a little feature in it, like everytime someone will text it will automatically reply to the message received.... i have added some codes but it only reply automatically when the spinner is pointed to the message itself... i intend to answer autmatically everytime a text message is received.... the red text are the added codes please help... thanks

PROCEDURE ReadSMS
LPARAMETERS tSMSNum
LOCAL tChar, i, tRead, lQuoteNum, tDateTime, tData, balik

TRY
tData = "AT+CMGR=" + TRANSFORM(tSMSNum) + CHR(13)

WITH this.oSMS
STORE 0 TO .Rthreshold,.Sthreshold
.InBufferCount = 0
.Output = tData
ENDWITH
tData = ""

i = SECONDS() + this.nTimeOut
DO WHILE (i > SECONDS()) .and. !("OK" $ tData) .and. !("ERROR" $ tData)
IF (this.oSMS.InBufferCount > 0)
tChar = this.oSMS.Input
tData = tData + tChar
ENDIF
ENDDO

STORE 1 TO this.oSMS.Rthreshold, this.oSMS.Sthreshold

IF !EMPTY(tData) .and. !("ERROR" $ tData)
lQuoteNum = 0
STORE "" TO tRead, tSender, tDateTime, tMessage
FOR i = 1 To LEN(tData)
tChar = SUBSTR(tData, i, 1)
IF tChar = ["]
lQuoteNum = lQuoteNum + 1
ENDIF
IF (lQuoteNum = 1) .and. !(tChar=["])
tRead = tRead + tChar
ENDIF
IF (lQuoteNum = 3) .and. !(tChar=["])
tSender = tSender + tChar
ENDIF
IF (lQuoteNum = 5) .and. !(tChar=["])
tDateTime = tDateTime + tChar
ENDIF
IF (lQuoteNum = 6) .and. !(tChar=["])
tMessage = tMessage + tChar
ENDIF
ENDFOR

this.nabasana = (tRead = "REC READ")
this.sender = tSender
this.senddeyt = LEFT(tDateTime, 8)
this.dlvrydeyt = SUBSTR(tDateTime,10,8)
tMessage = RIGHT(tMessage,LEN(tMessage)-2)
this.mensahe = SUBSTR(tMessage, 1, AT(CHR(13),tMessage) - 1)

Z = SUBSTR(tsender,4,13)

IF SUBSTR(tmessage,1,2) = "ON"

INDEX ON MOBILE TO MOBILEX

SEEK Z

IF FOUND ()

X = TRANSFORM(TPAYMENT,"###,###,###.##")

thisform.sms.sendsms(ALLTRIM(Z),ALLTRIM(X))

ENDIF
ENDIF


balik = .t.
ENDIF
CATCH
balik = .f.
ENDTRY
RETURN (balik)
ENDPROC

ENDDEFINE

DEFINE CLASS myOLE as OLEControl

OLEClass = "MSCommLib.MSComm.1"

* --------------------------------------------------------------------------

PROCEDURE OnComm
IF (this.CommEvent = 2) .and. (this.InBufferCount>0)
this.parent.myBuffer = this.Input

IF !EMPTY(this.parent.myBuffer) .and. !("ERROR" $ this.parent.myBuffer)
lQuoteNum = 0
STORE "" TO tSender, tDateTime, tMessage
FOR i = 1 To LEN(this.parent.myBuffer)
tChar = SUBSTR(this.parent.myBuffer, i, 1)
IF tChar = ["]
lQuoteNum = lQuoteNum + 1
ENDIF
IF (lQuoteNum = 1) .and. !(tChar=["])
tSender = tSender + tChar
ENDIF
IF (lQuoteNum = 3) .and. !(tChar=["])
tDateTime = tDateTime + tChar
ENDIF
IF (lQuoteNum = 4) .and. !(tChar=["])
tMessage = tMessage + tChar
ENDIF
ENDFOR

WITH this.parent
.nabasana = .f.
.sender = tSender
.senddeyt = LEFT(tDateTime, 8)
.dlvrydeyt = SUBSTR(tDateTime,10,8)
.mensahe = ALLTRIM(tMessage)

=MESSAGEBOX("Sender : "+.sender+CHR(013)+;
"Date : "+.senddeyt+CHR(013)+;
"Time : "+.dlvrydeyt+CHR(013)+;
"Message : "+.mensahe,64,"Incoming SMS Received !!",500)

ENDWITH
ENDIF
ENDIF
ENDPROC
ENDDEFINE
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top