Home arrow Visual Basic arrow Page 5 - Developing an XML Web Service Using Visual Studio 2005
VISUAL BASIC

Developing an XML Web Service Using Visual Studio 2005


This article guides you in developing a practical “Number to Words” web service using the latest Microsoft Visual Studio 2005 as the development tool.

Author Info:
By: Jagadish Chaterjee
Rating: 4 stars4 stars4 stars4 stars4 stars / 79
December 13, 2005
TABLE OF CONTENTS:
  1. · Developing an XML Web Service Using Visual Studio 2005
  2. · Brief explanation of the “Number to Words” XML Web Service
  3. · Creating XML Web Service using Visual Studio 2005
  4. · Developing the XML Web Service
  5. · Developing the XML Web Service continued
  6. · Executing and testing the XML Web Service

print this article
SEARCH DEVARTICLES

Developing an XML Web Service Using Visual Studio 2005 - Developing the XML Web Service continued
(Page 5 of 6 )

Now, let us proceed with the “Process3DigitNumber” method, which is usually called “ConvertToWords”.

private string Process3DigitNumber(string sSource)
    {
        string sRetVal = "";
        //Make sure the source should be three digits
        sSource = "000" + sSource;
        sSource = sSource.Substring(sSource.Length - 3);
 
        //Hundred possion
        if (sSource.Substring(0, 1) != "0")
            sRetVal = ProcessSingleDigitNumber(sSource.Substring(0, 1)) + " Hundred ";
 
        //Tens and ones possion
        if (sSource.Substring(1, 1) != "0")
            sRetVal += Process2DigitNumber(sSource.Substring(1));
        else
            sRetVal += ProcessSingleDigitNumber(sSource.Substring(2));
 
        return sRetVal;
    }

Once the above method receives a number (as a string), we left pad it with zeroes to make sure that it is a three digit number.  After that, we chunk it further and send it to “Process2DigitNumber” or “ProcessSingleDigitNumber”, which are implemented as follows:

private string Process2DigitNumber(string sSource)

    {
        string sRetVal = "";
        if (sSource.Substring(0, 1) == "1")
        {
            // Process 10 to 19
            switch (sSource)
            {
                case "10": sRetVal = "Ten"; break;
                case "11": sRetVal = "Eleven"; break;
                case "12": sRetVal = "Twelve"; break;
                case "13": sRetVal = "Thirteen"; break;
                case "14": sRetVal = "Fourteen"; break;
                case "15": sRetVal = "Fifteen"; break;
                case "16": sRetVal = "Sixteen"; break;
                case "17": sRetVal = "Seventeen"; break;
                case "18": sRetVal = "Eighteen"; break;
                case "19": sRetVal = "Nineteen"; break;
            }
        }
        else
        {
            // Process 20 to 99
            switch (sSource.Substring(0, 1))
            {
                case "2": sRetVal = "Twenty "; break;
                case "3": sRetVal = "Thirty "; break;
                case "4": sRetVal = "Forty "; break;
                case "5": sRetVal = "Fifty "; break;
                case "6": sRetVal = "Sixty "; break;
                case "7": sRetVal = "Seventy "; break;
                case "8": sRetVal = "Eighty "; break;
                case "9": sRetVal = "Ninety "; break;
            }
            //Append single digit word
            sRetVal += ProcessSingleDigitNumber(sSource.Substring(1));
        }
        return sRetVal;
    }

I hope I don't need to explain much about the above method.  It simply returns the string based on the two digit value sent to it.  This method may further call “ProcessSingleDigitNumber” to process only single digits.  Let us see how that is implemented.

private string ProcessSingleDigitNumber(string sSource)
    {
        string sRetVal = "";
        switch (sSource)
        {
            case "1": sRetVal = "One"; break;
            case "2": sRetVal = "Two"; break;
            case "3": sRetVal = "Three"; break;
            case "4": sRetVal = "Four"; break;
            case "5": sRetVal = "Five"; break;
            case "6": sRetVal = "Six"; break;
            case "7": sRetVal = "Seven"; break;
            case "8": sRetVal = "Eight"; break;
            case "9": sRetVal = "Nine"; break;
            default: sRetVal = ""; break;
        }
 
        return sRetVal;
    }

And thus, our coding (development) part is successfully finished.


blog comments powered by Disqus
VISUAL BASIC ARTICLES

- Developing an XML Web Service Using Visual S...
- Creating an HTML File List with VB
- Fun with Email: VB6, CDO, MAPI, and a Remote...
- Extranet/Intranet Dictionary Cracker in VB
- Finding Default App Icons With Visual Basic
- Registry Fever With Visual Basic
- Implementing An ADO Data Control With VB6
- Printing With Visual Basic
- MSMQ Part 1/2: Architecture and Simple Imple...
- Magnifying The Desktop With Visual Basic
- Sending Email With MAPI Components in Visual...
- Two Person Chat With The Winsock Control And...
- A Real-Time ActiveX News Control
- Accessing the Windows API in Visual Basic

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials