Wednesday, April 10, 2013

How to send SMS from VB 6.0 via Internet

At  last I got time to write one of important topic here.
How to send SMS from VB6.0 via Internet

When I got this work to implement in our project, first I got very excited but when I tried to search this topic on Internet via Google etc, I had to struggle a lot to find the correct method.

Well We can send SMS from VB6.0 by two ways

  1. By using Internet (this method is explained Here )
  2. By Using Mobile Phone (Not explained here)


After long time, I finally got chance to provide download link to demo project which is below
The downloaded file is rar compressed. In case you don't have software to extract it, just download wrar320 or higher version free of cost from the internet via Google etc.
Please note: You need some valid Developer API.
Please either contact company or create an demo account to get developer API from the site, I had mentioned Below.

Download SMS Demo project Setup without code 2.67mb

Here I would try to explain HOW TO SEND SMS FROM VB via INTERNET


  1. The very first thing is that U need to contact to any SMS Providers (e.g. in India some are
    1. http://www.mysmsmantra.com/
    2. http://www.smscountry.com/ (click on Register now button at top)
    3. http://www.freesmsapi.com/ (click on Sign Up button at top)
    4. http://mirchsms.com/bulk_sms.html (please contact at no. provided at top or email at bottom to request to get trial sms api ). I also tested it very well, you may also refer my name to them.)
  2. Now get the Developer API from these SMS Providers either by purchasing account or if you want to test before purchasing then you can ask these SMS Providers to provide you a free trial account so that you can test their service) 
    1. Below is one of the example of Developer API
    2. 'http://bulksms.mysmsmantra.com:8080/WebSMS/SMSAPI.jsp?username=demouser&password=399501089&sendername=DM&mobileno=919999999999&message=Hello"
  3. Now just use the following code in your VB program to send SMS
    1. Dim WinHttpReq As Object
    2. Dim sResult As String, strURL As String
    3. Set WinHttpReq = CreateObject("Msxml2.XMLHTTP")
    4. strURL="http://bulksms.mysmsmantra.com:8080/WebSMS/SMSAPI.jsp?username=demouser&password=399501089&sendername=DM&mobileno=919999999999&message=Hello"
    5. 'Replace the Message & MobileNo with the no to whom you want to send SMS
    6. With WinHttpReq
    7.       .Open "GET", strURL, False
    8.     .Send
    9.     sResult = .responseText
    10.  End With
    11. MsgBox "Status of Sent SMS  is=" & sResult
  4. Some Important notes We should keep in mind while Sending SMS
    1. Check the Maximum Message Length that you can send as allowed by your SMS Service Providers
    2. Check whether you have to make your Message encode according to WWW standards, confirm it from your SMS Providers
    3. While sending data over internet/network, some letters can not be sent as it is, they need to be converted to send them to internet. e.g " &"  can not be send as it, it needs to be converted to send it over internet.
      1. URL encoding converts characters into a format that can be transmitted over the Internet.
      2. For more information see following link
        1. http://www.w3schools.com/html/html_urlencode.asp
    4. Always Allow the access of your program to get connected with Internet which would be asked by the Firewall of your OS or Antivirus program else you could not send SMS 
    5. As sending SMS may take time, you should do appropriate changes in your program to show user that your program is busy in sending SMS like change Mouse Pointer Shape from normal to HourGlass & after sending make it normal.

After long time, I finally got chance to provide download link to demo project which is below
The downloaded file is rar compressed. In case you don't have software to extract it, just download wrar320 or higher version free of cost from the internet via Google etc.
Please note: You need some valid Developer API.
Please either contact company or create an demo account to get developer API from the site, I had mentioned above.


Below is a sample which I used in my project 






Private Sub cmdSMSTest_Click()
    'validate information
  'Message(max 160 Chars)


    Me.MousePointer = 11 'Hourglass
    Call SendMySMS(myMob, myMsg, True, Trim(Me.txtSMSDeveloperAPI),  Trim(Me.txtSMSMobileText), Trim(Me.txtSMSMsgText))
    Me.MousePointer = 0 'Default


End Sub


Public Function SendMySMS(ByVal myMob As String, ByVal myMsg As String, Optional ByVal IsTest As Boolean = False, Optional ByVal UserDeveloperAPI As String = "", Optional ByVal MobText As String = "", Optional ByVal MsgText As String = "", Optional ByVal AskToSend As Boolean = True, Optional ByVal ShowStatus As Boolean = True) As Boolean


'Here you write your code

Following is the sample code to test it--- but of course you need Developer API to use the code


Private Sub cmdSMSTest_Click()
    'validate information
    'Message(max 160 Chars)
    If Me.chkSMSActivateService.Value = 0 Or Len(Me.txtSMSDeveloperAPI) < 1 Or Len(Me.txtSMSMobileText) < 1 Or Len(Me.txtSMSMessageText) < 1 Then
        MsgBox "Please enter all setting values"
        Me.txtSMSDeveloperAPI.SetFocus
        Exit Sub
    End If
 
 
    Dim s As String
    Dim myMob As String
    Dim myMsg As String
 
    s = "Enter Mobile nos separated by , then put @ now write your msg not more than 160 chars"
    s = s & vbCrLf & "e.g 9971745868,9811994797@Hi this is test sms by ABM Infotech"
    s = InputBox(s, , "9971745868,9811360935@Hi this is test sms by ABM Infotech")
    myMsg = Mid(s, InStr(1, s, "@", vbTextCompare) + 1)
    If Len(myMsg) > 155 Then
        myMsg = Left$(myMsg, 155)
    End If
    myMob = Mid(s, 1, InStr(1, s, "@", vbTextCompare) - 1)
 
    Me.MousePointer = 11 'Hourglass
    Call SendMySMS(myMob, myMsg, True, Trim(Me.txtSMSDeveloperAPI), Trim(Me.txtSMSMobileText), Trim(Me.txtSMSMessageText))
    Me.MousePointer = 0 'Default

End Sub
Public Sub SendMySMS(ByVal myMob As String, ByVal myMsg As String, Optional ByVal IsTest As Boolean = False, Optional ByVal UserDeveloperAPI As String = "", Optional ByVal MobText As String = "", Optional ByVal MsgText As String = "", Optional ByVal AskToSend As Boolean = True, Optional ByVal ShowStatus As Boolean = True)
    'myMob,myMsg, Optional IsTest,UserDeveloperAPI , MobText, MsgText,AskToSend ,ShowStatus As Boolean = True
    On Error GoTo ArunKakkarErr
 
    Dim sMobText1 As String
    Dim sMobText2() As String
    Dim sMobText3() As String
 
    Dim sResult As String, strURL As String
    strURL = ""
 
    If IsTest Then
     
    Else 'retrieve settings from db
         '''SMS_IsActivate        1,0 SMS_DeveloperAPI SMS_MobileText SMS_MessageText
         If UserPreferencesGetValue("SMS_IsActivate", "0") = "0" Then Exit Sub
         UserDeveloperAPI = UserPreferencesGetValue("SMS_DeveloperAPI")
         MobText = UserPreferencesGetValue("SMS_MobileText")
         MsgText = UserPreferencesGetValue("SMS_MessageText")
    End If
 
 
    'To put 91 etc for more than one mobile nos
    sMobText2 = Split(MobText, "=")
    sMobText1 = ""
    If UBound(sMobText2) > 0 Then
        sMobText1 = sMobText2(1) '2nd element
    End If
    If Len(sMobText1) > 0 Then
        sMobText3 = Split(myMob, ",")
        If UBound(sMobText3) > 0 Then
            myMob = ""
            For i = LBound(sMobText3) To UBound(sMobText3)
                If myMob = "" Then
                    myMob = sMobText3(i) '1st Mobile No
                Else
                    myMob = myMob & "," & sMobText1 & sMobText3(i) '2nd, 3rd, 4th Mob No
                End If
            Next i
        End If
    End If
 
 
    strURL = UserDeveloperAPI & "&" & MobText & myMob & "&" & MsgText & myMsg
 
    If AskToSend Then
        If MsgBox("Do you want to send SMS?", vbYesNo + vbDefaultButton1) = vbNo Then
            Exit Sub
         
        End If
    End If
    Dim WinHttpReq As Object
 
    Set WinHttpReq = CreateObject("Msxml2.XMLHTTP")
    'strURL = "http://bulksms.mysmsmantra.com:8080/WebSMS/SMSAPI.jsp?username=demouser&password=399501089&sendername=DM&mobileno=919999999999&message=Hello"
    'Replace the Message & MobileNo with the no to whom you want to send SMS
    With WinHttpReq
          .Open "GET", strURL, False
        .Send
        sResult = .responseText
    End With
    If ShowStatus Then MsgBox "Status of Sent SMS  is=" & sResult
   
    Exit Sub
ArunKakkarErr:
    MsgBox ("Sorry there is some error while sending sms" & vbCrLf & Err.Description)
 
End Sub

Public Function UserPreferencesGetValue(ByVal SettingName As String, Optional ByVal DefaultValue As String = "", Optional ByVal myTable As String = "UserPreferences", Optional ByVal NameCol As String = "SettingName", Optional ByVal ValueCol As String = "SettingValue")
    Dim s As String
    s = ""
    Dim rptRs As New ADODB.Recordset
    If rptRs.State Then rptRs.Close
    rptRs.Open "select * from " & myTable & " where " & NameCol & "='" & SettingName & "'", Scon, adOpenStatic, adLockReadOnly
    If rptRs.EOF = False Then '  if already present then return
        s = IIf(IsNull(rptRs!SettingValue) = False, rptRs!SettingValue, DefaultValue)
    Else ' if not present then return default
        s = DefaultValue
    End If
    UserPreferencesGetValue = s
End Function

Public Sub UserPreferencesSetValue(ByVal SettingName As String, ByVal SettingValue As String, Optional ByVal myTable As String = "UserPreferences", Optional ByVal NameCol As String = "SettingName", Optional ByVal ValueCol As String = "SettingValue")
    Dim rptRs As New ADODB.Recordset
    If rptRs.State Then rptRs.Close
    rptRs.Open "select * from " & myTable & " where " & NameCol & "='" & SettingName & "'", Scon, adOpenStatic, adLockReadOnly
    If rptRs.EOF = False Then '  if already present then update
        Scon.Execute "Update " & myTable & " set " & ValueCol & "  = '" & SettingValue & "' where " & NameCol & " = '" & SettingName & "'"
    Else ' if not present then insert
        Scon.Execute "Insert into " & myTable & " (" & NameCol & "," & ValueCol & ") values ('" & SettingName & "','" & SettingValue & "')"
    End If
End Sub

Public Sub AKakkar_Error(Optional ByVal Source As String = "")
    Dim s As String
    s = "Sorry for the inconvinence, There is some error"
    s = s & vbCrLf & "ABM Source=" & Source
    s = s & vbCrLf & "Error No=" & Err.Number
    s = s & vbCrLf & "Error Description=" & Err.Description
    s = s & vbCrLf & "Error Source=" & Err.Source
    MsgBox s, vbCritical
End Sub
Note:::>>>> If someone need sample program, just mail me, I would like to help you.


Now after learning it you can explore it in details to get more powerful options for your programs.
Best of Luck for Programming.

21 comments:

  1. Ρrеtty nіce ρoѕt. I sіmрlу
    ѕtumbled upon your ωeblog аnd ωishеԁ to mentіon that
    I've truly loved surfing around your blog posts. After all I'll be ѕubscribing foг
    yоur fеed anԁ I hopе you ωritе agаin ѕoon!



    Feel free to ѕurf to mу webрage; Author's external home page...

    ReplyDelete
  2. I was extremely pleased to uncover this page. I want to to
    thank you for your time for this particularly wonderful read!

    ! I definitely loved every part of it and i also
    have you book marked to see new things on your website.

    my blog - new york escorts

    ReplyDelete
  3. Yes! Finally someone writes about ab glider.

    ReplyDelete
  4. Hello, i think that i saw you visited my site so i came to “return the favor”.I am trying to find things to enhance my web site!I suppose its ok to use some of your ideas!!



    Here is my weblog :: pure garcinia cambogia extract

    ReplyDelete
  5. No matter if some one searches for his required thing, so he/she needs to be available that in detail,
    thus that thing is maintained over here.

    Here is my website debt

    ReplyDelete
  6. Saved as a favorite, I love your blog!

    Feel free to visit my weblog ... keratocone

    ReplyDelete
  7. Hi my friend! I want to say that this article is awesome, nice written and
    include approximately all important infos. I would like to
    peer more posts like this .

    Feel free to surf to my page Whatsapp Hack

    ReplyDelete
  8. You are advised to print the log of this whole process
    so that you can use it in future for the purpose of hard drive
    repair and maintenance. But few simple things like those mentioned above will always
    keep your system running at its highest speed.
    But they rarely notice that with the reinstallation of the programs, the computer speed will also
    become slower.

    My site; Increase Computer Speed

    ReplyDelete
  9. Appreciating the hard work you put into your blog
    and detailed information you present. It's nice to come across a
    blog every once in a while that isn't the same out
    of date rehashed information. Excellent read! I've saved your site and I'm
    adding your RSS feeds to my Google account.

    Feel free to surf to my blog :: bet angel

    ReplyDelete
  10. I used to be suggested this website by means of my cousin.
    I'm no longer certain whether this submit is written by
    him as nobody else recognise such precise about my problem.
    You're amazing! Thank you!

    My web-site Gama's Landscaping

    ReplyDelete
  11. There's aldo a hint that the PS3 version of the game will finally be fixed
    to work with DLC. I am sure expelling soon our up-to-the-minute version of a new wind turbine
    so , make sure to are another the first oness to pay money for this prticular tv show.

    Well in that location are a only a few places where sole
    can get a majority of these and additional.

    my web page Psn code generator uk

    ReplyDelete
  12. This design is spectacular! You most certainly know how to keep a reader entertained.
    Between your wit and your videos, I was almost moved to start my own blog (well, almost...HaHa!) Wonderful
    job. I really loved what you had to say, and more than that, how you presented it.
    Too cool!

    Here is my web blog porn

    ReplyDelete
  13. This design is spectacular! You most certainly know how to keep a reader
    entertained. Between your wit and your videos, I was almost moved to start my own blog (well, almost...HaHa!) Wonderful job.

    I really loved what you had to say, and more than that,
    how you presented it. Too cool!

    My homepage ... porn

    ReplyDelete
  14. Hello there I am so thrilled I found your webpage, I really found
    you by accident, while I was browsing on Aol for something else, Regardless I am here now and would just like to say thank
    you for a marvelous post and a all round exciting blog (I
    also love the theme/design), I don�t have time to read it all at the minute but I have bookmarked it and also added
    your RSS feeds, so when I have time I will be back to read more, Please do keep up the awesome
    work.

    Feel free to surf to my site; dating site

    ReplyDelete
  15. I want to to thank you for this excellent read!! I absolutely loved every
    little bit of it. I have got you bookmarked to look at new stuff you post…

    Here is my homepage - Veronica

    ReplyDelete
  16. What's up, I would like to subscribe for this
    website to get hottest updates, thus where can i do it please assist.


    Take a look at my site Somerset Business

    ReplyDelete
  17. This comment has been removed by the author.

    ReplyDelete
  18. Nice, Awesome and good Post. It's give me such a good information. Keep Posting information like this. Waiting for next post. I have some good Information to share with all that is...
    Email service provider in india
    Email service provider

    ReplyDelete
  19. Good and amazing post. Nice to read your post it's give such a good information. Waiting for next post. If you want to do marketing for your business just click
    Bulk Sms Service Provider in Bengal


    ReplyDelete
  20. This comment has been removed by the author.

    ReplyDelete