Announcement

Announcement Module
Collapse
No announcement yet.

Fungsi terbilang (VB)

Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Fungsi terbilang (VB)

    Rekan2 ada yang punya fungsi terbilang untuk menyebutkan bilangan angka dalam bahasa Visual Basic?

    Thanks.

  • #2
    Re: Fungsi terbilang (VB)

    coba script dibawah ini, namun kelemahannya tidak bisa ada pecahan (harus bulat). tinggal panggil fungsi num2word dengan n sebagai bilangan (dalam string)



    Private Kata1(9) As String
    Private Kata2(5) As String

    Private Function getdigit1(n As String) As String
    If Mid(n, 1, 1) <> "0" Then
    If Mid(n, 1, 1) = "1" Then
    getdigit1 = getdigit1 + " Seratus"
    Else
    getdigit1 = getdigit1 + " " + Kata1(Mid(n, 1, 1)) + " Ratus"
    End If
    End If
    End Function

    Private Function getdigit2(n As String, ByVal m As Integer) As String
    If Mid(n, 2, 1) <> "0" Then
    If Mid(n, 2, 1) = "1" Then
    If Val(Mid(n, 3, 1)) > 1 Then
    getdigit2 = getdigit2 + " " + Kata1(Mid(n, 3, 1)) + " Belas"
    Else
    If Mid(n, 3, 1) = "0" Then
    getdigit2 = getdigit2 + " Sepuluh"
    Else
    getdigit2 = getdigit2 + " Sebelas"
    End If
    End If
    Else
    If Mid(n, 2, 1) <> "0" Then
    getdigit2 = getdigit2 + " " + Kata1(Mid(n, 2, 1)) + " Puluh" + getdigit3(n, m)
    Else
    getdigit2 = getdigit2 + getdigit3(n, m)
    End If
    End If
    Else
    getdigit2 = getdigit2 + getdigit3(n, m)
    End If
    End Function

    Private Function getdigit3(n As String, ByVal m As String) As String
    If Mid(n, 3, 1) <> "0" Then
    If m = 1 And Right(n, 1) = "1" And Mid(n, 2, 1) = "0" Then
    If Mid(n, 1, 1) = "0" Then
    getdigit3 = getdigit3 + " Se"
    Else
    getdigit3 = getdigit3 + " " + Kata1(Mid(n, 3, 1))
    End If
    Else
    getdigit3 = getdigit3 + " " + Kata1(Mid(n, 3, 1))
    End If
    End If
    End Function

    Public Function num2word(n As String) As String
    '--Untuk mengubah angka menjadi kata kata
    Dim i As Integer
    Dim j As Integer
    Dim t As String
    Call SetKata
    i = 1
    j = Len(n)
    j = j Mod 3
    If j <> 0 Then n = Right("000" + n, Len(n) + 3 - j)
    For j = Len(n) / 3 To 1 Step -1
    t = t + getdigit1(Mid(n, i, 3)) + getdigit2(Mid(n, i, 3), j - 1) + Kata2(j - 1)
    i = i + 3
    Next
    num2word = t + " Rupiah"
    End Function

    Private Sub SetKata()
    '--Memberi harga awal
    Kata1(1) = "Satu"
    Kata1(2) = "Dua"
    Kata1(3) = "Tiga"
    Kata1(4) = "Empat"
    Kata1(5) = "Lima"
    Kata1(6) = "Enam"
    Kata1(7) = "Tujuh"
    Kata1(8) = "Delapan"
    Kata1(9) = "Sembilan"

    Kata2(1) = " Ribu"
    Kata2(2) = " Juta"
    Kata2(3) = " Milyard"
    Kata2(4) = " Trilyun"
    Kata2(5) = " Bilyun"
    End Sub

    Comment


    • #3
      Re: Fungsi terbilang (VB)

      Function Num2Word(ByVal n As Currency) As String
      Dim satuan As Variant
      satuan = Array("", "Satu", "Dua", "Tiga", "Empat", "Lima", "Enam", "Tujuh", "Delapan", "Sembilan", "Sepuluh", "Sebelas")
      Select Case n
      Case 0 To 11
      Num2Word = " " + satuan(Fix(n))
      Case 12 To 19
      Num2Word = Num2Word(n Mod 10) + " Belas"
      Case 20 To 99
      Num2Word = Num2Word(Fix(n / 10)) + " Puluh" + Num2Word(n Mod 10)
      Case 100 To 199
      Num2Word = " Seratus" + Num2Word(n - 100)
      Case 200 To 999
      Num2Word = Num2Word(Fix(n / 100)) + " Ratus" + Num2Word(n Mod 100)
      Case 1000 To 1999
      Num2Word = " Seribu" + Num2Word(n - 1000)
      Case 2000 To 999999
      Num2Word = Num2Word(Fix(n / 1000)) + " Ribu" + Num2Word(n Mod 1000)
      Case 1000000 To 999999999
      Num2Word = Num2Word(Fix(n / 1000000)) + " Juta" + Num2Word(n Mod 1000000)
      Case Else
      Num2Word = Num2Word(Fix(n / 1000000000)) + " Milyar" + Num2Word(n Mod 1000000000)
      End Select
      End Function

      cara pemakaian: Text1.Text=Num2Word(txt_neto.Text) + " Rupiah"

      Comment

      Working...
      X