Click here to Skip to main content
13,045,790 members (47,777 online)
Rate this:
Please Sign up or sign in to 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

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


End If
End If
Timer2.Enabled = True

End Function
Posted 17-Oct-12 23:18pm
Updated 17-Oct-12 23:27pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1


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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 11 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100