RSS

Visual Basic


MODUL VISUAL BASIC
1. MODUL VISUAL BASIC
2. Modul V. Basic

MEMBATASI INPUT TEXTBOX HANYA DENGAN ANGKA PADA VB6

Private Sub Txtjt_KeyPress(KeyAscii As Integer)
If Not ((KeyAscii >= 48) And (KeyAscii <= 57) Or KeyAscii = 8) Then

KeyAscii = 0
Txttotalp.Text = Val(Txtht.Text) * Val(Txtjt.Text)
End If
End Sub

Artinya jika bukan keyascii lebih besar sama dengan 48 dan keyascii kurang sama dengan 57 (keyascii bukan antara 48 sampai 57) atau keyascii = 8 maka keyascii = 0

hasilnya pada textbox hanya bisa diinput angka 0 sampai 9 dan backspace, sehingga dapat mencegah terjadinya error akibat user (human error).

keyascii 48 sampai 57 adalah angka (0-9), sedangkan keyascii 8 adalah backspace

KODE TERBILANG

Private Sub Txttotalp_Change()
Txtterbilang.Text = terbilang(Val(Txttotalp.Text))
End Sub

Private Function baca(X As Integer) As String
Dim i As Long
Dim ratus(9) As String
Dim belas(9) As String
Dim puluh(9) As String
Dim satuan(9) As String
Dim sbaca As String

satuan(1) = “satu”
satuan(2) = “dua”
satuan(3) = “tiga”
satuan(4) = “empat”
satuan(5) = “lima”
satuan(6) = “enam”
satuan(7) = “tujuh”
satuan(8) = “delapan”
satuan(9) = “sembilan”

For i = 1 To 9
If i = 1 Then
puluh(i) = “sepuluh”
Else
puluh(i) = satuan(i) & ” puluh”
End If
Next

For i = 1 To 9
If i = 1 Then
belas(i) = “sebelas”
Else
belas(i) = satuan(i) & ” belas”
End If
Next

For i = 1 To 9
If i = 1 Then
ratus(i) = “seratus”
Else
ratus(i) = satuan(i) & ” ratus”
End If
Next

If X >= 100 Then
sbaca = ratus(Val(Mid(Str(X), 2, 1)))
X = Val(Mid(Str(X), 3, 2))
End If

If X >= 20 Or X = 10 Then
sbaca = sbaca & ” ” & puluh(Val(Mid(Str(X), 2, 1)))
X = Val(Mid(Str(X), 3, 1))
Else
If X > 10 Then
sbaca = sbaca & ” ” & belas(Val(Mid(Str(X), 3, 1)))
X = -1
End If
End If

If X >= 1 Then
sbaca = sbaca & ” ” & satuan(Val((Str(X))))
End If

baca = sbaca
End Function
Function terbilang(X As Currency) As String
Dim ribu, juta, milyar, trilyun, ratusan As Integer
Dim sterbilang As String
Dim ptext As Byte
sterbilang = “”

If Val(X) = 1000000000000# Then
ptext = Len(Str(X)) – 13
trilyun = Val(Mid(Str(X), 2, ptext))
sterbilang = sterbilang & ” ” & baca(Val(trilyun)) & ” trilyun”
X = Val(Mid(Str(X), ptext + 2, 12))
End If

If X >= 1000000000 Then
ptext = Len(Str(X)) – 10
milyar = Val(Mid(Str(X), 2, ptext))
sterbilang = sterbilang & ” ” & baca(Val(milyar)) & ” milyar”
X = Val(Mid(Str(X), ptext + 2, 9))
End If

If X >= 1000000 Then
ptext = Len(Str(X)) – 7
juta = Val(Mid(Str(X), 2, ptext))
sterbilang = sterbilang & ” ” & baca(Val(juta)) & ” juta”
X = Val(Mid(Str(X), ptext + 2, 6))
End If

If X >= 1000 Then
ptext = Len(Str(X)) – 4
ribu = Val(Mid(Str(X), 2, ptext))
If ribu = 1 Then
sterbilang = “seribu”
Else
sterbilang = sterbilang & ” ” & baca(Val(ribu)) & ” ribu”
End If
X = Val(Mid(Str(X), ptext + 2, 3))
End If

sterbilang = sterbilang & ” ” & baca(Val(X))
terbilang = Trim(sterbilang) & ” rupiah”
End Function

 

3 responses to “Visual Basic

  1. Nurulnunue19

    Januari 17, 2012 at 6:32 pm

    assalamualaikum..
    bapak sya bingung liat kode” nya
    gag ngerti..
    hehehe

     
  2. solehudinstmikpringsewu

    Januari 20, 2012 at 9:48 pm

    mumet…………..

     
  3. saputr4kurni4

    Februari 8, 2012 at 11:53 pm

    siippp…

     

Tinggalkan Balasan

Please log in using one of these methods to post your comment:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

 
%d blogger menyukai ini: