Joke Collection Website - Blessing messages - How to write mobile phone short messages with VB6.0
How to write mobile phone short messages with VB6.0
This function is realized. This function is mainly applied to a format conversion function that comes with VB: ChrW () converts Chinese into Unicode code.
Common function chg(rmsg As String) As String
Adjust the step size to a string
Dim temp in string form
Mark I as an integer
Dim b is an integer
tep = rmsg
i = Len(tep)
b = i / 4
If i = b * 4, then
b = b - 1
tep = Left(tep,b * 4)
other
tep = Left(tep,b * 4)
If ... it will be over.
chg = " "
For i = 1 to b
temp = " & ampH " & ampMid(tep,(i - 1) * 4 + 1,4)
chg = chg & ampChrW(CInt(Val(temp)))
Next, I
End function
As mentioned above, in order to send short messages in PDU mode, the mobile phone number and the other party's mobile phone number must also be converted into PDU format. The following function implements this transformation:
Common function telc(num As String) As String
Mark tl as an integer
Dim ltem, rtem, ttem as strings
Dim ti is an integer.
ttem = " "
Tl = Len (number)
If tl 1 1 and tl 13, then
MsgBox "Wrong number." The symbol of & element thallium
Exit function
If ... it will be over.
If tl = 1 1
tl = tl + 2
Num = "86" & number
If ... it will be over.
For ti = 1 to tl step 2
ltem = Mid(num,ti, 1)
rtem = Mid(num,ti + 1, 1)
If ti = tl, rtem = "F "
Ttem = ttem & amprtem & project.
Next layer
telc = ttem
End function
There are two ways to express the mobile phone number: 1 1 digit and 13 digit (with country code 86). Generally, mobile phones are sent in the form of 13 digits, so another function of the above function is to automatically transfer the mobile phone number in the format of 1 1 digits.
Change it to 13 bit, and then convert it into PDU string.
The sending of short messages is mainly realized by means of Mscomm control of VB. About Mscomm control, the previous technical introduction part has a detailed introduction. The sending of SMS is completed by AT+CMGS instruction and sent in PDU mode.
The numbering code is as follows:
Const prex = "089 1 "
const midx = " 1 1000d 9 1 "
Const sufx = "000800 "
The public function Sendsms(csca is a string, num is a string, msg is a string) As _Boolean.
Dim pdu, psmsc, pnum, pmsg as strings.
Hazy and cold as a string
Dim length is an integer.
Length = Length (Message)
Length = 2 * length
Leng = hexadecimal (length)
If the length is < 16, then leng = "0" & cold.
psmsc = Trim(telc(csca))
Pnum = Trim(telc))
pmsg = Trim(ascg(msg))
Pdu = prex & psmsc & amp midx & amp pnum & amp sufx & amp cold & amp serum gonadotropin.
Sleep (1)
Mobile communication. Output = "AT+CMGF=0" + vbCr
Mobile communication. CMGS = " & amp; Str( 15+length)+vbCr
Mobile communication. Output = PDU&chr $ (26)
Sleep (1)
Sendsms = True
End function
Because the mobile phone can only handle one thing at a time, this function is only responsible for sending short messages, and the part about sending short messages successfully and reading short messages is handled together. Judging whether the mobile phone short message is sent successfully.
Whether it is mainly determined by the return code after the execution of the AT+CMGS command (see the introduction of the AT command in the previous section).
In order to prevent the mobile phone from making mistakes because it is too busy, some measures have been taken here to give the mobile phone enough time to handle the sending, receiving and deleting operations. The Sleep () function is designed for this purpose, and it is used for sending and deleting operations.
After work, the program will pause for one second to avoid the phone being too busy.
Unicode encoding and decoding function
Compared with sending SMS, the main job of receiving SMS is just the opposite. The sending of SMS needs to convert the content of SMS to Unicode code, while the receiving of SMS needs to be connected.
The received Unicode code is converted into Chinese characters. The following function will realize the decoding function. Like the coding function of SMS sending, a function AscW () built in VB is also applied here to convert Unicode coding.
Change to Chinese:
Common function ascg(smsg As String) As String
Dim si and sb are integers.
Mark stmp as an integer
Mark stemp as a string
sb = Len(smsg)
ascg = " "
For si = 1 for sb
stmp = AscW(Mid(smsg,si, 1))
If Abs(stmp) < 127, then
Stemp = "00"& hexadecimal (stmp)
other
Stemp = hexadecimal (stmp)
If ... it will be over.
ascg = ascg & ampstemp
Next si
Ascg = fine tuning (ascg)
End function
2 SMS receiving function
Compared with the sending function of SMS, the receiving of SMS is quite simple, and only the following three lines of code are needed. But the technology it uses is no less than sending short messages, and Mscomm controls are mainly used here.
Output properties of and and AT+CMGR instructions.
Public subreads (rnum in string form)
Mobile communication. Output = "AT+CMGF= 1" + vbCr
Mobile communication. CMGR = " & amp; rnum + vbCr
End joint
Thank you ~ ~
- Related articles
- Customer birthday message
- How to use wechat font color code
- Do things by phone or by text message?
- Program of Hometown Show Competition
- The willful loan has not been reviewed for an hour. Was it rejected?
- Apple's mobile phone probe subscription cannot be cancelled. There is no cancel button at all?
- I can't open my SMS inbox, model: altek T8680. I have formatted the memory card and forgot where the short message is stored.
- What is the website for querying Chongqing high school entrance examination results?
- How to send text messages to greet others? He is our VIP customer, so we should greet him and tell him what discounts are available in our store.
- What is the art of swearing without dirty words?