Click here to Skip to main content
15,883,814 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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
Posted
Updated 17-Oct-12 23:27pm
v2

1 solution

Hi!

im not good in vb6 but lets talk this logically

dont put your code to send SMS in a LOOP it seems that the code is executed many times
thats why it will send a lot of message unless the condition in your loop is done or you EXIT your application.

strSendResult = objSMS.SendSMS(MobileNo, message)

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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900