问题描述
我正在使用它在VB6中使用mCore ActiveX组件发送短信。这段代码工作正常,但有时它会多次发送一条短信(事实上,在关闭我的应用程序之前已经有数百次)。请指导我,因为我对VB6非常熟悉
公共功能SendSMS()
开错误继续下一步
Dim strSendResult As String
Dim ij As Integer
Dim message As String,blnAllMsgsSent As Boolean
Dim message1
Dim id As Integer
blnAllMsgsSent = True
如果是objSMS.Connect然后
Timer2.Enabled = False
ij = 0
Sql =SELECT id ,消息,MobileNo FROM tblSendSMS where status =''Pending''order by id asc;
RS.Open Sql,Conn,adOpenDynamic
If Not RS.EOF Then
RS.MoveFirst
请勿RS.EOF
留言= RS!消息
如果RS!消息<> 然后
id = RS!id
''''现在发送消息
strSendResult = objSMS.SendSMS(MobileNo,message)
strSendResult =
如果objSMS.IsError(True,Application.exe)那么
blnAllMsgsSent = False
结束如果
结束如果
如果blnAllMsgsSent那么
Sql =更新tblSendSMS set status =''已发送''其中id =&id
Conn.Execute Sql
结束如果
''''结束发送
结束如果
ij = ij + 1
RS.MoveNext
循环
结束如果
RS.Close
Else
SetCommParameters
结束如果
Timer2.Enabled = True
结束函数
I''m using this to send an SMS using mCore ActiveX Component in VB6. This code is working fine but sometimes it sends a single SMS multiple times (in fact, hundreds of times until I close my application). Please guide me as I''m very familiar with VB6
Public Function SendSMS()
On Error Resume Next
Dim strSendResult As String
Dim ij As Integer
Dim message As String, blnAllMsgsSent As Boolean
Dim message1
Dim id As Integer
blnAllMsgsSent = True
If objSMS.Connect Then
Timer2.Enabled = False
ij = 0
Sql = "SELECT id,message,MobileNo FROM tblSendSMS where status=''Pending'' order by id asc;"
RS.Open Sql, Conn, adOpenDynamic
If Not RS.EOF Then
RS.MoveFirst
Do While Not RS.EOF
message = RS!message
If RS!message <> "" Then
id = RS!id
'''' send message now
strSendResult = objSMS.SendSMS(MobileNo, message)
strSendResult = ""
If objSMS.IsError(True, "Application.exe") Then
blnAllMsgsSent = False
End If
End If
If blnAllMsgsSent Then
Sql = "update tblSendSMS set status=''Sent'' where id=" & id
Conn.Execute Sql
End If
'''' end send
End If
ij = ij + 1
RS.MoveNext
Loop
End If
RS.Close
Else
SetCommParameters
End If
Timer2.Enabled = True
End Function
推荐答案
strSendResult = objSMS.SendSMS(MobileNo, message)
在此代码之上你有一个while循环
u可能会使用尝试Catch而不是获取错误
你应该只使用循环来发送许多数字的特定消息。
或连接消息,因为如果你超过你的消息多达160个字符
你会得到错误。因为发送单个短信只支持160个字符
如果超过160个字符,我们现在正在谈论另一个短信。
on top of this code you have a do while loop
u may use Try Catch instead to Get errors
you should only use loop to send a particular message in many numbers .
or to concatenate messages since if you exceed your message up to 160 chars
you will get error. because sending a single sms will support only 160 characters
if you exceed in 160 chars we are now talking about another sms.
这篇关于使用vb6中的mCore Active x和访问数据库发送多个SMS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!