1

我正在使用它在 VB6 中使用 mCore ActiveX 组件发送短信。这段代码运行良好,但有时它会多次发送一条短信(事实上,在我关闭应用程序之前已经发送了数百次)。请指导我,因为我对 VB6 非常熟悉

Public Function SendSMS()

    On Error Resume Next

    Dim strSendResult As String
    Dim ij  As Integer
    Dim message As String
    Dim 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


                ij = ij + 1
                RS.MoveNext

            Loop

        End If
        RS.Close
    Else
        SetCommParameters
    End If
    Timer2.Enabled = True
End Function
4

1 回答 1

0

如果有一个错误,则blnAllMsgsSent变为 false 并且该表永远不会更新sent该消息以及所有后续消息,导致它们在下一个计时器事件中重新发送,因为它们的状态仍然是pending

您还只设置了idifRS!message <> ""但随后在更新 SQL 中的检查之外使用它,以便它可以包含来自先前消息的 id。

于 2012-10-18T09:49:10.543 回答