Click here to Skip to main content
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 275
1 DamithSL 265
2 CPallini 235
3 Maciej Los 185
4 George Jonsson 170
0 OriginalGriff 5,305
1 DamithSL 4,382
2 Maciej Los 3,760
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,901


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