please help me
i want to make a program in VB.NET in which two textbox and a button.
when we enter any value(currency) in first text box then its string value will show in second textbox.
for Ex-
Input
1200
Output
One thousand two hundred.
this program should work for upto 99 crores.How to write a program in VB.NET to convert Integer values Into string?
Copy The following codes into your program and then just pass the integer into the first function ConvertToSring() as shown below
Example :-
In the click event of button1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
a = Me.TextBox1.Text
Dim s As String
s = ConvertToSring(a)
Textbox2.Text = s
End Sub
Public Function ConvertToSring(ByVal num As Integer) As String 'Pass your value in this function
If num %26lt; 0 Or num %26gt; 999999999 Then
Return ';Invalid range';
End If
Dim numberString As String = ';';
Dim number As Integer = num
Dim onestens, hundred, thousandtenthousand, lakhstenlakhs, croretencrores As Integer
Try
onestens = number Mod 100
number = (number - onestens) / 100
hundred = number Mod 10
number = (number - hundred) / 10
thousandtenthousand = number Mod 100
number = (number - thousandtenthousand) / 100
lakhstenlakhs = number Mod 100
number = (number - lakhstenlakhs) / 100
croretencrores = number Mod 100
number = (number - croretencrores) / 100
Catch ex As Exception
End Try
If Not croretencrores = 0 Then
Dim sp As String 'singular or plural
Dim andstr As String 'and appender
If num Mod croretencrores = 0 Then
andstr = ';';
Else
andstr = ';And ';
End If
If croretencrores = 1 Then
sp = ';Crore ';
Else
sp = ';Crores ';
End If
numberString = numberString + TensFinder(croretencrores) + sp + andstr
End If
If Not lakhstenlakhs = 0 Then
Dim sp As String 'singular or plural
Dim andstr As String 'and appender
If (num - (croretencrores * 10000000)) Mod lakhstenlakhs = 0 Then
andstr = ';';
Else
andstr = ';And ';
End If
If lakhstenlakhs = 1 Then
sp = ';Lakh ';
Else
sp = ';Lakhs ';
End If
numberString = numberString + TensFinder(lakhstenlakhs) + sp + andstr
End If
If Not thousandtenthousand = 0 Then
Dim andstr As String 'and appender
If ((num - (croretencrores * 10000000)) - (lakhstenlakhs * 100000)) Mod thousandtenthousand = 0 Then
andstr = ';';
Else
andstr = ';And ';
End If
numberString = numberString + TensFinder(thousandtenthousand) + ';Thousand '; + andstr
End If
If Not hundred = 0 Then
Dim andstr As String 'and appender
If (((num - (croretencrores * 10000000)) - (lakhstenlakhs * 100000)) - (thousandtenthousand * 1000)) Mod hundred = 0 Then
andstr = ';';
Else
andstr = ';And ';
End If
Select Case hundred
Case 1
numberString = numberString + ';OneHundred '; + andstr
Case 2
numberString = numberString + ';TwoHundred '; + andstr
Case 3
numberString = numberString + ';ThreeHundred '; + andstr
Case 4
numberString = numberString + ';FourHundred '; + andstr
Case 5
numberString = numberString + ';FiveHundred '; + andstr
Case 6
numberString = numberString + ';SixHundred '; + andstr
Case 7
numberString = numberString + ';SevenHundred '; + andstr
Case 8
numberString = numberString + ';EightHundred '; + andstr
Case 9
numberString = numberString + ';NineHundred '; + andstr
End Select
End If
If Not onestens = 0 Then
numberString = numberString + TensFinder(onestens)
End If
Return numberString
End Function
Public Function TensFinder(ByVal twodigits As Integer)
If twodigits = 0 Then
Return ';Zero';
End If
Dim tens, ones, twodigits1 As Integer
twodigits1 = twodigits
Dim tensstring, twodigitstring As String
tensstring = ';';
twodigitstring = ';';
ones = twodigits1 Mod 10
twodigits1 = (twodigits1 - ones) / 10
If twodigits = 0 Then
GoTo label1
End If
tens = twodigits1 Mod 10
twodigits1 = (twodigits1 - tens) / 10
Select Case twodigits
Case 10
twodigitstring = ';Ten';
GoTo label2
Case 11
twodigitstring = ';Elevan';
GoTo label2
Case 12
twodigitstring = ';Twelve';
GoTo label2
Case 13
twodigitstring = ';Thirteen';
GoTo label2
Case 14
twodigitstring = ';Fourteen';
GoTo label2
Case 15
twodigitstring = ';Fifteen';
GoTo label2
Case 16
twodigitstring = ';Sixteen';
GoTo label2
Case 17
twodigitstring = ';Seventeen';
GoTo label2
Case 18
twodigitstring = ';Eighteen';
GoTo label2
Case 19
twodigitstring = ';Nineteen';
GoTo label2
Case Else
GoTo label3
End Select
label3: If Not tens = 0 Then
Select Case tens
Case 2
tensstring = ';Twenty ';
twodigitstring = ';Twenty';
Case 3
tensstring = ';Thirty ';
twodigitstring = ';Thirty';
Case 4
tensstring = ';Fourty ';
twodigitstring = ';Fourty';
Case 5
tensstring = ';Fiftey ';
twodigitstring = ';Fiftey';
Case 6
tensstring = ';Sixtey ';
twodigitstring = ';Sixtey';
Case 7
tensstring = ';Seventy ';
twodigitstring = ';Seventy';
Case 8
tensstring = ';Eighty ';
twodigitstring = ';Eighty';
Case 9
tensstring = ';Ninety ';
twodigitstring = ';Ninety';
End Select
End If
label1: Select Case ones
Case 1
twodigitstring = tensstring + ';One';
Case 2
twodigitstring = tensstring + ';Two';
Case 3
twodigitstring = tensstring + ';Three';
Case 4
twodigitstring = tensstring + ';Four';
Case 5
twodigitstring = tensstring + ';Five';
Case 6
twodigitstring = tensstring + ';Six';
Case 7
twodigitstring = tensstring + ';Seven';
Case 8
twodigitstring = tensstring + ';Eight';
Case 9
twodigitstring = tensstring + ';Nine';
End Select
label2: Return twodigitstring
End Function
'This Function Has some bugs in appending And to the String.But It won't affect the program
No comments:
Post a Comment