.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Visual Studio >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Number to word conversion in vb

Posted By:satyapriyanayak       Posted Date: May 01, 2013    Points: 40    Category: Visual Studio    URL: http://www.dotnetspark.com  

Here we can convert any number to its respective words format. Here in this example we can convert it up to 4 digits only.
 

Public Class Form1
    Dim n, i As Integer
    Dim x As String
    Dim a As String
    Dim b As String
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim a() As String = {"One", "Two", "Three", "four", "Five", _
                                     "Six", "Seven", "Eight", "Nine", "Ten", _
                                     "Eleven", "Twelve", "Thirteen", "fourteen", _
                                     "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Ninteen"}

        Dim b() As String = {"Twenty", "Thirty", "Fourty", "Fifty", _
                             "sixty", "Seventy", "eighty", "ninty"}

        x = ""
        n = InputBox("Enter 4 digit Number Only")
        If (n <= 9999) Then
            If (n > 999 And n <= 9999) Then
                x += a((n \ 1000) - 1) & "Thousand"
                n = n Mod 1000
            End If
            x += " "
            If (n > 99 And n <= 999) Then
                x += a((n \ 100) - 1) & "Hundred"
                n = n Mod 100
            End If
            x += " "
            If (n > 19 And n <= 99) Then
                x += b((n \ 10) - 2)
                n = n Mod 10
            End If
            x += " "
            If (n > 0 And n <= 19) Then
                x += a(n - 1)
            End If
            MsgBox("The Number in words is= " & x)
        Else
            MsgBox("Number is out of range")
        End If
    End Sub
End Class


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend