Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: VB8.0 VB6
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 18-Oct-12 0:18am
Edited 18-Oct-12 0:27am

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
0 Sergey Alexandrovich Kryukov 7,448
1 OriginalGriff 5,996
2 Peter Leow 4,292
3 CHill60 2,858
4 Mika Wendelius 2,850

Advertise | Privacy | Mobile
Web01 | 2.8.150224.1 | Last Updated 11 Feb 2013
Copyright © CodeProject, 1999-2015
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