[VB] sms pdu encoding and decoding 1

Source: Internet
Author: User

'With decode encode

Function analyze (recmsg as string) as Boolean
Dim Tel as string, MSG as string, time as string
Analyze = analyzerecmsg (buffer, tel, MSG, time)
If analyze = true then
'User Processing
Mobiletel. Text = Tel
Sendmsg. Text = msg
'Label1.caption = Time
End if
End Function

Public Function analyzerecmsg (byval recmsg as string, byref mobilenumber as string, byref MSG as string, byref msgtime as string) as Boolean
Dim I as integer, J as integer
Dim analyzemsg as string
Dim length as integer
Analyzerecmsg = false
I = instr (recmsg, "+ cmgr :")
If I length then
MSG = decode (MSG)
End if
Analyzerecmsg = true
End Function

'================================================ ======================================
'The following is a set of Chinese character encoding and decoding functions.

Public Function encode (txtmessage as string) as string
Dim high as string, low as string, oneword as string
Dim I as integer
For I = 1 to Len (txtmessage) 'converts the short message into Encoding
Oneword = mid (txtmessage, I, 1)
Low = hex (ASCB (midb (oneword, 1, 1 )))
High = hex (ASCB (midb (oneword, 2, 1 )))
If Len (high) = 1 then high = "0" + high
If Len (low) = 1 then low = "0" + low
Encoding obtained by encode = encode + high + low
Next I
End Function

Public Function decode (encodemessage as string) as string
Dim word (2) as byte
Dim ASCII as string
Dim temp as string
Dim J as integer, POS as integer
Pos = 1
J = 1
Do
If j> = Len (encodemessage) then
Exit Function
End if
ASCII = mid (encodemessage, J, 2)
J = J + 2

Word (POS) = Val ("& H" + ASCII)
Pos = pos-1
If Pos = "0" and oneword "" Then exit function
Else
If oneword = "" then
Do
I = I + 1
Oneword = mid (recdecodemsg, I, 1)
Loop while oneword = "" and I

  • Next article:Compilation of assembly language command parameter programs
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.