Dim tl As Integer Dim ltem, rtem, ttem As String Dim ti As Integer
ttem = "" tl = Len(num) If tl <> 11 And tl <> 13 Then MsgBox "wrong number." & tl Exit Function End If
If tl = 11 Then tl = tl + 2 num = "86" & num End If For ti = 1 To tl Step 2 ltem = Mid(num, ti, 1) rtem = Mid(num, ti + 1, 1) If ti = tl Then rtem = "F" ttem = ttem & rtem & ltem Next ti telc = ttem End Function 手机号码有两种表示方法:11位和13位(带国家码86),一般手机发送时都是以13位形式表示的,所以以上的函数还有一个功能是自动将11位格式手机号码转换为13位形式,然后再转换为PDU串。
Public Function Sendsms(csca As String, num As String, msg As String) As _Boolean Dim pdu, psmsc, pnum, pmsg As String Dim leng As String Dim length As Integer
Dim si, sb As Integer Dim stmp As Integer Dim stemp As String
sb = Len(smsg) ascg = "" For si = 1 To sb stmp = AscW(Mid(smsg, si, 1)) If Abs(stmp) < 127 Then stemp = "00" & Hex(stmp) Else stemp = Hex(stmp) End If ascg = ascg & stemp Next si ascg = Trim(ascg) End Function 手机短信接收函数