用Visual Basic设计手机短信收发程序

http://tech.ddvip.com   2006年07月30日    社区交流

本文详细介绍用Visual Basic设计手机短信收发程序

  中文转换成Unicode码函数

  因为手机短消息的发送是以PDU串的形式发送出去的,中文字符以Unicode码来表示,所以在发送中文短消息之前必须首先将中文字符转换为Unicode码,下面的函数将实现这个功能。这个函数主要应用到VB自带的一个格式转换函数:ChrW()将中文转换为Unicode码。

  Public Function chg(rmsg As String) As String
 Dim tep As String
 Dim temp As String
 Dim i As Integer
 Dim b As Integer
 tep = rmsg
 i = Len(tep)
 b = i / 4
 If i = b * 4 Then
  b = b - 1
  tep = Left(tep, b * 4)
 Else
  tep = Left(tep, b * 4)
 End If
 chg = ""
 For i = 1 To b
  temp = "&H" & Mid(tep, (i - 1) * 4 + 1, 4)
  chg = chg & ChrW(CInt(Val(temp)))
 Next i
End Function

  短信中心手机号码的PDU串转换函数

  同上,为了发送以PDU模式发送短消息,必须将手机号码和对方手机号码也转换为PDU格式,下面的函数就是为了实现这种转换:

  Public Function telc(num As String) As String
 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

作者:hitbird    责编:豆豆技术应用

正在加载评论...