1

これを使用して、VB6のmCoreActiveXコンポーネントを使用してSMSを送信しています。このコードは正常に機能していますが、1つのSMSを複数回送信することがあります(実際、アプリケーションを閉じるまでに数百回)。私は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

エラーが1つある場合は、falseになり、そのメッセージだけでなく後続のすべてblnAllMsgsSentのメッセージについてもテーブルが更新されないため、ステータスがまだであるため、次のタイマーイベントで再送信されます。sentpending

また、前のメッセージのIDを含めることができるように、更新SQLのチェックの外で使用するid場合にのみ設定します。RS!message <> ""

于 2012-10-18T09:49:10.543 に答える