TextBox a Girilen Rakamı Yazıya Çevirme
Bu örneğimizde TextBox a girilecek olan rakamaların, yazı olarak karşılığını yazdıracağız. Aşağıdaki şekli inceleyin.
Şekil 1
Forma yazılacak kodlar:
Imports VB = Microsoft.VisualBasic
Public Class Form1
Private Sub btnCevir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCevir.Click
RichTextBox1.Text = GetSayilar((txtsayi.Text))
End Sub
Private Sub txtsayi_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtsayi.KeyPress
Dim KeyAscii As Short = Asc(e.KeyChar)
KeyAscii = IIf(IsNumeric(Chr(KeyAscii)) Or (InStr(txtsayi.Text, ".") = 0 And KeyAscii = 46) Or KeyAscii = 8, KeyAscii, 0)
If KeyAscii = 0 Then
e.Handled = True
End If
End Sub
Function GetSayilar(ByRef x As String) As String
Dim bir(10) As String
Dim iki(10) As String
Dim Uc(10) As String
Dim Yüz As String
Dim Bin As String
Dim yüzbin As String
Dim Onmilyon As String
Dim Milyar As String
Dim Milyon As String
Dim Trilyon As String
bir(0) = "Sıfır" : bir(1) = "Bir" : bir(2) = "İki" : bir(3) = "Üç" : bir(4) = "Dört" : bir(5) = "Beş" : bir(6) = "Altı" : bir(7) = "Yedi" : bir(8) = "Sekiz" : bir(9) = "Dokuz"
iki(0) = "On" : iki(1) = "Onbir" : iki(2) = "Oniki" : iki(3) = "Onüç" : iki(4) = "Ondört" : iki(5) = "Onbeş" : iki(6) = "Onaltı" : iki(7) = "Onyedi" : iki(8) = "Onsekiz" : iki(9) = "Ondokuz"
Uc(2) = "Yirmi" : Uc(3) = "Otuz" : Uc(4) = "Kırk" : Uc(5) = "Elli" : Uc(6) = "Altmış" : Uc(7) = "Yetmiş" : Uc(8) = "Seksen" : Uc(9) = "Doksan"
Yüz = "Yüz" : Bin = "Bin" : yüzbin = "Yüz Bin" : Onmilyon = "On Milyon" : Milyar = "Milyar"
Milyon = "Milyon" : Trilyon = "Trilyon"
Dim inp, RetVal As String
inp = CStr(Val(x))
Select Case Len(inp)
Case 1
RetVal = bir(CInt(x))
Case 2
If Int(CDbl(VB.Right(inp, 1))) > 0 And CDbl(VB.Left(inp, 1)) > 1 Then RetVal = GetSayilar(CStr(Int(CDbl(VB.Right(inp, 1))))) ‘ 20 den 90 adım 10
If CDbl(VB.Left(inp, 1)) > 1 Then RetVal = Uc(CInt(VB.Left(inp, 1))) & RetVal ‘ 20-99
If CDbl(VB.Left(inp, 1)) = 1 Then RetVal = iki(CInt(VB.Right(inp, 1))) ‘11-19
Case 3
If Int(CDbl(VB.Right(inp, 2))) > 0 Then RetVal = GetSayilar(CStr(Int(CDbl(VB.Right(inp, 2)))))
RetVal = GetSayilar(Int(CDbl(VB.Left(inp, 1)))) & Yüz & RetVal
Case 4
If Int(CDbl(VB.Right(inp, 3))) > 0 Then RetVal = GetSayilar(CStr(Int(CDbl(VB.Right(inp, 3)))))
RetVal = GetSayilar(Int(CDbl(VB.Left(inp, 1)))) & Bin & RetVal
Case 5
If Int(CDbl(VB.Right(inp, 3))) > 0 Then RetVal = GetSayilar(CStr(Int(CDbl(VB.Right(inp, 3)))))
RetVal = GetSayilar(Int(CDbl(VB.Left(inp, 2)))) & Bin & RetVal
Case 6
If CInt(VB.Right(inp, 5)) > 0 Then RetVal = GetSayilar(CStr(CInt(VB.Right(inp, 5))))
RetVal = GetSayilar(Int(CDbl(VB.Left(inp, 1)))) & yüzbin & RetVal
Case 7
If CInt(VB.Right(inp, 5)) > 0 Then RetVal = GetSayilar(CStr(CInt(VB.Right(inp, 5))))
RetVal = GetSayilar(Int(CDbl(VB.Left(inp, 2)))) & yüzbin & RetVal
Case 8
If CInt(VB.Right(inp, 7)) > 0 Then RetVal = GetSayilar(CStr(CInt(VB.Right(inp, 7))))
RetVal = GetSayilar(Int(CDbl(VB.Left(inp, 1)))) & Onmilyon & RetVal
Case 9
If CInt(VB.Right(inp, 7)) > 0 Then RetVal = GetSayilar(CStr(CInt(VB.Right(inp, 7))))
RetVal = GetSayilar(Int(CDbl(VB.Left(inp, 2)))) & Onmilyon & RetVal
Case 10
If CInt(VB.Right(inp, 9)) > 0 Then RetVal = GetSayilar(CStr(CInt(VB.Right(inp, 9))))
RetVal = GetSayilar(Int(CDbl(VB.Left(inp, 1)))) & Milyar & RetVal
Case 11
If CInt(VB.Right(inp, 9)) > 0 Then RetVal = GetSayilar(CStr(CInt(VB.Right(inp, 9))))
RetVal = GetSayilar(Int(CDbl(VB.Left(inp, 2)))) & Milyar & RetVal
Case 12
If Val(VB.Right(inp, 11)) > 0 Then RetVal = GetSayilar(VB.Right(inp, 11))
RetVal = GetSayilar(Int(CDbl(VB.Left(inp, 1)))) & Milyon & RetVal
Case 13
If Val(VB.Right(inp, 11)) > 0 Then RetVal = GetSayilar(VB.Right(inp, 11))
RetVal = GetSayilar(Int(CDbl(VB.Left(inp, 2)))) & Milyon & RetVal
Case 14
If Val(VB.Right(inp, 13)) > 0 Then RetVal = GetSayilar(VB.Right(inp, 13))
RetVal = GetSayilar(Int(CDbl(VB.Left(inp, 1)))) & Trilyon & RetVal
Case 15
If Val(VB.Right(inp, 13)) > 0 Then RetVal = GetSayilar(VB.Right(inp, 13))
RetVal = GetSayilar(Int(CDbl(VB.Left(inp, 2)))) & Trilyon & RetVal
End Select
GetSayilar = " " & RetVal & " "
GetSayilar = Replace(GetSayilar, " ", " ")
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With Me
.Text = "Rakam ı Yazıya Çeviren Program"
.MaximizeBox = False
End With
RichTextBox1.ReadOnly = True
End Sub
End Class
‘Faydalı olması dileğiyle. Bir sonraki makalede görüşmek üzere...Bahadirsa