Convert Whole Number and Decimal to Words in VB.NET
Submitted by donbermoy on Saturday, April 25, 2015 - 23:20.
Today, I will teach you how to create a program that converts a whole number and a decimal into words using vb.net. This is so useful in making systems when you convert it in the receipt section that the numbers are converted into words.
Now, let's start this tutorial!
1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application.
2. Next, add one TextBox named TextBox1 for the input, one Label named Label1 for the output, and one Button named Button1 for converting the input into words. You must design your interface like this:
3. Now, we will create a Module named Module1 for the Number to Words code.
We will create a Function named NumberToWord(ByVal MyNumber)
Initialize the following:
Convert MyNumber to a string, trimming extra spaces.
Find decimal place.
Find decimal place.
If we find decimal place...
Convert last 3 digits of MyNumber to number in word.
Strip off last three digits
4. For the conversion of hundreds, create a function named ConvertHundreds(ByVal MyNumber)
5. For the conversion of tens, create a function named ConvertTens(ByVal MyTens)
6. For the conversion of digits, create a function named ConvertDigit(ByVal MyDigit)
7. Now, we will code for our Form.
We will first filter the inputting of numbers in our TextBox.
8. Lastly, code for the Form_Load then use the NumberToWord function we have created in our Module.
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Best Regards,
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]
Add and Follow me on Facebook: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

- Dim Temp
- Dim Num, Digits As String
- Dim DecimalPlace, iCount
- Dim Hundreds, Words As String
- Dim place(9) As String
- place(0) = " Thousand "
- place(2) = " Hundred "
- place(4) = " "
- place(6) = " "
- place(8) = " "
- On Error Resume Next
If MyNumber between 1 To 99 Only.
- Dim TM As String ' If MyNumber between 1 To 99 Only.
- If Len(MyNumber) > 0 And Len(MyNumber) <= 2 Then
- If Len(TM) = 1 Then
- Words = ConvertDigit(TM)
- NumberToWord = Words & Digits
- Exit Function
- Else
- If Len(TM) = 2 Then
- Words = ConvertTens(TM)
- NumberToWord = Words & Digits
- Exit Function
- End If
- End If
- End If
- iCount = 0
- Do While MyNumber <> ""
- 'Strip last two digits
- If Len(MyNumber) = 1 Then
- Words = ConvertDigit(Temp) & place(iCount)
- Else
- Words = ConvertDigit(Temp) & place(iCount) & Words
- End If
- Else
- Words = ConvertTens(Temp) & place(iCount)
- Else
- '=================================================================
- Words = Words
- Else
- Words = ConvertTens(Temp) & place(iCount) & Words
- End If
- End If
- End If
- iCount = iCount + 2
- Loop
- NumberToWord = " " & Words & Hundreds & Digits & ""
- End Function
- Private Function ConvertHundreds(ByVal MyNumber)
- Dim Result As String
- ' Exit if there is nothing to convert.
- ' Append leading zeros to number.
- ' Do we have a hundreds place digit to convert?
- End If
- ' Do we have a tens place digit to convert?
- If Mid(MyNumber, 2, 1) <> "0" Then
- Result = Result & ConvertTens(Mid(MyNumber, 2))
- Else
- ' If not, then convert the ones place digit.
- Result = Result & ConvertDigit(Mid(MyNumber, 3))
- End If
- End Function
- Private Function ConvertTens(ByVal MyTens)
- Dim Result As String
- ' Is value between 10 and 19?
- Case 10 : Result = "Ten"
- Case 11 : Result = "Eleven"
- Case 12 : Result = "Twelve"
- Case 13 : Result = "Thirteen"
- Case 14 : Result = "Fourteen"
- Case 15 : Result = "Fifteen"
- Case 16 : Result = "Sixteen"
- Case 17 : Result = "Seventeen"
- Case 18 : Result = "Eighteen"
- Case 19 : Result = "Nineteen"
- Case Else
- End Select
- Else
- ' .. otherwise it's between 20 and 99.
- Case 2 : Result = "Twenty "
- Case 3 : Result = "Thirty "
- Case 4 : Result = "Forty "
- Case 5 : Result = "Fifty "
- Case 6 : Result = "Sixty "
- Case 7 : Result = "Seventy "
- Case 8 : Result = "Eighty "
- Case 9 : Result = "Ninety "
- Case Else
- End Select
- ' Convert ones place digit.
- End If
- ConvertTens = Result
- End Function
- Private Function ConvertDigit(ByVal MyDigit)
- Case 1 : ConvertDigit = "One"
- Case 2 : ConvertDigit = "Two"
- Case 3 : ConvertDigit = "Three"
- Case 4 : ConvertDigit = "Four"
- Case 5 : ConvertDigit = "Five"
- Case 6 : ConvertDigit = "Six"
- Case 7 : ConvertDigit = "Seven"
- Case 8 : ConvertDigit = "Eight"
- Case 9 : ConvertDigit = "Nine"
- Case Else : ConvertDigit = ""
- End Select
- End Function
- Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
- If Not Char.IsDigit(e.KeyChar) AndAlso Not e.KeyChar = "."c Then
- e.Handled = True
- e.Handled = False
- End If
- End If
- End Sub
Output:

Add new comment
- 3248 views