Click here to Skip to main content
11,409,097 members (48,808 online)
Rate this: bad
good
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

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 18-Oct-12 0:18am
Edited 18-Oct-12 0:27am
v2

1 solution

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

Solution 1

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.
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 350
1 Sergey Alexandrovich Kryukov 310
2 Maciej Los 155
3 Peter Leow 140
4 Dave Kreskowiak 115
0 Sergey Alexandrovich Kryukov 8,676
1 OriginalGriff 6,855
2 Maciej Los 3,322
3 Abhinav S 3,238
4 Peter Leow 3,034


Advertise | Privacy | Mobile
Web03 | 2.8.150414.5 | 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