How to convert numbers into words in visual basic
Are you looking for visual basic source code that will convert the numbers into words then here is the best solution for you. In this post, we are going to learn how to write a program to convert numbers into words in visual basic 6.0. Most of the students are searching for this program. Because of this type programs are asked in many types of exams, so we should not ignore this type of program. Below I have given easy source code and also given the project file of this program so that you can easily download this program and convert numbers into words.
Before starting the program, I tell you that for converting numbers into words in visual basic 6 we need to understand how to work numbers and words in vb6. So, for this question, I will make a separate post. Still, nowhere I will give you a free source code for your program therefore don’t worry about that. For creating the program to convert numbers into words in vb6, just follow the following steps and after that, you can easily make that program.
Steps for the program to convert numbers into words in visual basic 6.0
- First, create a new form
- Then draw three labels, in those labels two labels display information, and another one is for displaying the converted numbers into words.
- After that draw three buttons, one label is for converting the numbers to words another one is for clear entered in displayed information, and one button exits the form.
- Then write the code on buttons (source code is given below, there are separate sources for each button)
- After that right-click on the main form, & add a new module, and write the given code on that module.
Source code for the main form to convert numbers into words in visual basic 6
Option Explicit
Private Sub Command1_Click()
lblNumToWords.Caption = ""
txtNumber.Text = ""
End Sub
Private Sub txtNumber_GotFocus()
With txtNumber
.SelStart = 0
.SelLength = Len(.Text)
End With
End Sub
Private Sub txtNumber_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyBack Then Exit Sub
If InStr("0123456789", Chr$(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End Sub
Private Sub txtNumber_Change()
lblNumToWords = ""
End Sub
Private Sub cmdDoIt_Click()
lblNumToWords = NumToWords(txtNumber)
End Sub
Private Sub cmdExit_Click()
End
End SubSource code for a module to convert numbers into words
Option Explicit
Function NumToWords(strNumberString As String) As String
Dim intGroupX As Integer
Dim intUnitDigit As Integer
Dim intTensDigit As Integer
Dim intHundDigit As Integer
Dim intGroupStartPos As Integer
Dim intNbrLeadingZeros As Integer
Dim intX As Integer
Dim strWorkNumber As String
Dim strGroupVerbage As String
Dim arrUnitName As Variant
Dim arrCompoundName As Variant
Dim arrTensName As Variant
Dim arrGroupName As Variant
arrUnitName = Array("", "One", "Two", "Three", "Four", "Five", _
"Six", "Seven", "Eight", "Nine")
arrCompoundName = Array("", "Eleven", "Twelve", "Thirteen", _
"Fourteen", "Fifteen", "Sixteen", _
"Seventeen", "Eighteen", "Nineteen")
arrTensName = Array("", "Ten", "Twenty", "Thirty", "Forty", _
"Fifty", "Sixty", "Seventy", "Eighty", _
"Ninety")
arrGroupName = Array("", "Thousand", "Million", "Billion", _
"Trillion", "Quadrillion", "Quintillion", _
"Sextillion", "Septillion", "Octillion", _
"Nintillion", "Decillion")
If Not IsAllDigits(strNumberString) Then
MsgBox "Numeric argument required.", vbInformation, _
"Invalid Argument"
NumToWords = ""
Exit Function
End If
If Len(strNumberString) > 36 Then
MsgBox "Argument must not exceed 36 digits.", vbInformation, _
"Argument Too Big"
NumToWords = ""
Exit Function
End If
intNbrLeadingZeros = 36 - Len(strNumberString)
strWorkNumber = strNumberString
For intX = 1 To intNbrLeadingZeros
strWorkNumber = "0" & strWorkNumber
Next
intGroupStartPos = 34
For intGroupX = 0 To 11
intUnitDigit = Val(Mid$(strWorkNumber, intGroupStartPos + 2, 1))
intTensDigit = Val(Mid$(strWorkNumber, intGroupStartPos + 1, 1))
intHundDigit = Val(Mid$(strWorkNumber, intGroupStartPos, 1))
If intUnitDigit = 0 And intTensDigit = 0 Then
strGroupVerbage = ""
ElseIf intUnitDigit = 0 Then
strGroupVerbage = arrTensName(intTensDigit)
ElseIf intTensDigit = 1 Then
strGroupVerbage = arrCompoundName(intUnitDigit)
ElseIf intTensDigit = 0 Then
strGroupVerbage = arrUnitName(intUnitDigit)
Else
strGroupVerbage = arrTensName(intTensDigit) & "-" _
& arrUnitName(intUnitDigit)
End If
If intHundDigit <> 0 Then
strGroupVerbage = arrUnitName(intHundDigit) & " Hundred " _
& strGroupVerbage
End If
If strGroupVerbage <> "" Then
strGroupVerbage = strGroupVerbage & " " _
& arrGroupName(intGroupX)
End If
NumToWords = strGroupVerbage & " " & NumToWords
intGroupStartPos = intGroupStartPos - 3
Next
NumToWords = Trim$(NumToWords)
If NumToWords = "" Then NumToWords = "ZERO"
End Function
Function IsAllDigits(strTestString As String) As Boolean
Dim intX As Integer
For intX = 1 To Len(strTestString)
If InStr("0123456789", Mid$(strTestString, intX, 1)) > 0 Then
' continue
Else
IsAllDigits = False
Exit Function
End If
Next
IsAllDigits = True
End FunctionWhy do you need to write a visual basic program that converts numbers into words in vb6?
Yes! Yes, I know that nowadays there are a lot of solutions available for this program but I think most of the students are not satisfied with that solutions, therefore, I have tried to provide an easy solution for you. By using this solution you can easily convert numbers or amounts into words. Now here we are going to see why we need a visual basic program to convert numbers into words.
Mainly this program is very useful for college students who are learning visual basic programming. In this program, you can know how to work numbers operation in vb6. Sometimes many students think that this program is not useful for us because they are confused in is it still worth learning visual basic 6.0? But, if you are BCA or computer science student then you can understand the value of these types of visual basic programs examples.
This program will very helpful for developing banking applications. For example in the bank when we want to withdraw money then we are filling the slip in that slip we are entering the money amount in numbers as well as words, If there are we use this type of logic in software then that will very helpful for many peoples. If you know properly how to convert numbers into words in vb6 then you can use the logic of this program in other programming languages like c,c++, PHP, etc.
How to work this visual basic program to convert numbers into words
The working flow of this program is very easy. You want to just enter the numbers in the textbox and then click on the convert button after that the numbers will be automatically converted to words. If you want to know the coding flow of this program then I will provide another separate video for you. If you want the video for this post then comment to me.
Most of the time this program is asked in many exams but a lot of students don’t know how to convert numbers into words in vb6, therefore, they can’t solve this type of program. But don’t worry now because here I have given a very easy solution for you, just copy this source code and run your program. If you can’t copy this program then you can request me for the project file. Just fill out the contact form and give me your email.
0 Comments