::selection {background:#d90000; color:#FFFFFF;}

Popular Post

Popular Posts

Posted by : Unknown Minggu, 01 September 2013

Konversi angka ke huruf atau sebagian orang yang berkecimpung di dalam dunia pemograman menyebutnya dengan Terbilang, kebetulan kali ini saya mencoba menggunakan VB.NET 2010. Berikut fungsi terbilang menggunakan VB .NET 2010 mencakup sampai dengan bilangan Trilyun.

Terdiri dari

  • 1 GroupBox
  • 4 Label
  • 4 TextBox
  • 3 Button
CODE:
Public Class KonvertAngka
 Public Function Terbilang(ByVal x As Double) As String
 Dim isi As Double
 Dim teks As String
 Dim bagian As String
 Dim i As Integer
 Dim tanda As Boolean

 Dim letak(5)
 letak(1) = "ribu "
 letak(2) = "juta "
 letak(3) = "milyar "
 letak(4) = "triliun "
If (x = 0) Then
 Terbilang = "nol"
 Exit Function
 End If
If (x < 2000) Then
 tanda = True
 End If
teks = ""
If (x >= 1.0E+15) Then
 Terbilang = "Nilai terlalu besar"
 Exit Function
 End If
For i = 4 To 1 Step -1
 isi = Int(x / (10 ^ (3 * i)))
 If (isi > 0) Then
 bagian = ratusan(isi, tanda)
 teks = teks & bagian & letak(i)
 End If
 x = x - isi * (10 ^ (3 * i))
 Next
teks = teks & ratusan(x, False)
 Terbilang = teks
 End Function
Function ratusan(ByVal y As Double, ByVal flag As Boolean) As String
 Dim tmp As Double
 Dim bilang As String
 Dim bag As String
 Dim j As Integer
Dim angka(9)
 angka(1) = "se"
 angka(2) = "dua "
 angka(3) = "tiga "
 angka(4) = "empat "
 angka(5) = "lima "
 angka(6) = "enam "
 angka(7) = "tujuh "
 angka(8) = "delapan "
 angka(9) = "sembilan "
Dim posisi(2)
 posisi(1) = "puluh "
 posisi(2) = "ratus "
bilang = ""
 For j = 2 To 1 Step -1
 tmp = Int(y / (10 ^ j))
 If (tmp > 0) Then
 bag = angka(tmp)
 If (j = 1 And tmp = 1) Then
 y = y - tmp * 10 ^ j
 If (y >= 1) Then
 posisi(j) = "belas "
 Else
 angka(y) = "se"
 End If
 bilang = bilang & angka(y) & posisi(j)
 ratusan = bilang
 Exit Function
 Else
 bilang = bilang & bag & posisi(j)
 End If
 End If
 y = y - tmp * 10 ^ j
 Next
If (flag = False) Then
 angka(1) = "satu"
 End If
 bilang = bilang & angka(y)
 ratusan = bilang
 End Function
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
 Me.Close()
 End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 Dim angka As Double
 Dim teks As String
 angka = Val(txthasil.Text)
 teks = Terbilang(angka)
 txtterbilang.Text = teks
If txthasil.Text = "" Then
 txtterbilang.Text = "input angka!"
 End If
If Not IsNumeric(txthasil.Text) Then
 txtterbilang.Text = "Input angka, bukan huruf!"
 End If
End Sub

 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
 Dim angka1 As Long
 Dim angka2 As Long
 Dim hasil As Long
angka1 = Val(txtangka1.Text)
 angka2 = Val(txtangka2.Text)
 hasil = angka1 + angka2
 txthasil.Text = hasil
End Sub
End Class
Nah, Program sederhana “Konversi Angka ke Huruf Menggunakan VB.NET 2010″ anda juga bisa Download disini
Semoga bermanfaat.

Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © 2013 Devil Elevator - Devil-Elevator - Powered by Blogger - Designed by Candra Wijaya -