You are on page 1of 2

Public Class Form1 Dim num1() As String = {"one", "two", "three", "four", "five", "six", "seven ", "eigth",

"nine"} Dim num2() As String = {"ten", "twenty", "thirty", "fourty", "fifty", "sixty ", "seventy", "eighty", "ninety"} Dim num3() As String = {"eleven", "twelve", "thirteen", "fourteen", " fiftee n", "sixteen", "seventeen", "eightteen", "nineteen"} Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles Button1.Click TextBox2.Text = "" If TextBox1.Text >= 0 And TextBox1.Text <= 10000 Then For x As Integer = TextBox1.TextLength To 1 Step -1 If x = 4 Then TextBox2.Text = num1(TextBox1.Text.Substring(0, 1) - 1) & " thousand " ElseIf x = 3 Then If TextBox1.TextLength = 3 Then TextBox2.Text = TextBox2.Text & num1(TextBox1.Text.Subst ring(0, 1) - 1) & " hundred " Else If Mid(TextBox1.Text, TextBox1.TextLength - 2, 1) <> 0 T hen TextBox2.Text = TextBox2.Text & num1(Mid(TextBox1.Te xt, TextBox1.TextLength - 2, 1) - 1) & " hundred " End If End If ElseIf x = 2 Then If TextBox1.TextLength = 2 Then If TextBox1.Text > 9 And TextBox1.Text < 20 Then If TextBox1.Text = 10 Then TextBox2.Text = "ten" Else TextBox2.Text = TextBox2.Text & num3(TextBox1.Te xt.Substring(0, 2) - 11) End If Exit Sub Else TextBox2.Text = TextBox2.Text & num2(TextBox1.Text.S ubstring(0, 1) - 1) & " " End If Else If Mid(TextBox1.Text, TextBox1.TextLength - 1, 2) > 9 An d Mid(TextBox1.Text, TextBox1.TextLength - 1, 2) < 20 Then If Mid(TextBox1.Text, TextBox1.TextLength - 1, 2) = 10 Then TextBox2.Text = TextBox2.Text & "ten" Else TextBox2.Text = TextBox2.Text & num3(Mid(TextBox 1.Text, TextBox1.TextLength - 1, 2) - 11) End If Exit Sub Else If Mid(TextBox1.Text, TextBox1.TextLength - 1, 1) <> 0 Then TextBox2.Text = TextBox2.Text & num2(Mid(TextBox 1.Text, TextBox1.TextLength - 1, 1) - 1) & " "

End If End If End If ElseIf x = 1 Then If TextBox1.TextLength = 1 Then If TextBox1.Text = 0 Then TextBox2.Text = "zero" Else TextBox2.Text = TextBox2.Text & num1(TextBox1.Text 1) End If Else If Mid(TextBox1.Text, TextBox1.TextLength, 1) = 0 Then 'nothing Else TextBox2.Text = TextBox2.Text & num1(Mid(TextBox1.Te xt, TextBox1.TextLength, 1) - 1) End If End If Else TextBox2.Text = "ten thousand" Exit Sub End If Next Else TextBox2.Text = "Invalid" End If If TextBox1.Text > 10000 Then TextBox2.Text = "Out of range!" End If End Sub End Class

You might also like