UTS VB

Pemilihan (Case)

Select Case Combo1.Text
    Case "BR001"
        Text1.Text = "Kulkas 2 Pintu"
        Text2.Text = "2.000.000"
    Case "BR002"
        Text1.Text = "LCD 32 Inci"
        Text2.Text = "2.500.000"
    Case "BR003"
        Text1.Text = "VCD"
        Text2.Text = "500.000"
    End Select
End Sub

Pengulangan (Faktorial)

Dim n, fak, i As Integer

Private Sub Cmdfornext_Click()
n = Txtnfak.Text
fak = 1
For i = 1 To n
    fak = fak * i
Next i
txtfornext.Text = fak
End Sub

Private Sub cmddowhile_Click()
fak = 1
n = Txtnfak.Text
i = 1
Do While i <= n
    fak = fak * i
    i = i + 1
Loop
txtdowhile.Text = fak
End Sub

Private Sub cmddountil_Click()
fak = 1
n = Txtnfak.Text
i = 1
Do Until i = n
    i = i + 1
    fak = fak * i
Loop
txtdountil.Text = fak
End Sub

Function (String)
Private Sub Command1_Click()
Text2.Text = Val(Text1.Text) 'menghitung nilai value
Text4.Text = Left(Text3.Text, 4) '4 karakter diambil dari kiri
Text6.Text = Right(Text5.Text, 5) '5 karakter diambil dari kanan
Text8.Text = LTrim(Text7.Text) 'menghapus jarak di kiri
Text10.Text = RTrim(Text9.Text) 'menghapus jarak di kanan
Text12.Text = Trim(Text11.Text) 'menhapus jarak kanan&kiri
Text14.Text = Mid(Text13.Text, 4, 5) 'diambil mulai dari karakter ke 4 sebanyak 5 karakter
Text16.Text = LCase(Text15.Text) 'mengecilkan semua huruf
Text18.Text = UCase(Text17.Text) 'membesarkan semua huruf
Text20.Text = Len(Text19.Text) 'menghitung jumlah karakter
End Sub


Function (Date)
Private Sub Command1_Click()
'button date value
Dim tgl As Date
tgl = DateValue("7 november 1982")
MsgBox tgl, vbOKOnly, "Konversi Tanggal"
End Sub

Private Sub Command2_Click()
' button DayMonthyear
Dim hari, bulan, tahun As Integer
Dim tgl As Date
tgl = Nov
hari = Day(tgl)
bulan = Month(tgl)
tahun = Year(tgl)
MsgBox "Tanggal : " & hari & " Bulan : " & bulan & " Tahun : " & tahun, _
vbOKOnly, "Hari Bulan Tahun"
End Sub

Private Sub Command3_Click()
' button HourMinuteSec
Dim jam, menit, detik As Integer
Dim tgl As Date
tgl = Now
jam = Hour(tgl)
menit = Minute(tgl)
detik = Second(tgl)
MsgBox "Jam : " & jam & " Menit : " & menit & " Detik : " & detik, _
vbOKOnly, "HH:MM:SS"
End Sub

Private Sub Command4_Click()
'time value
Dim waktu As Date
waktu = TimeValue("20:30:45")
MsgBox " TimeValue : " & waktu, vbOKOnly, "Hasil Konversi"
End Sub
Private Sub Command5_Click()
'Datediff
x = DateDiff("s", CDate("02/18/1992"), CDate("10/18/2012"))
MsgBox x
End Sub

Function (Point Of Sales)
Pada Module
Function GetNamaBarang(kode As String) As String
    Select Case (kode)
        Case "BR0001"
            GetNamaBarang = "Lemari Es"
        Case "BR0002"
            GetNamaBarang = "LCD 32 inch"
        Case "BR0003"
            GetNamaBarang = "Air Conditioner"
        Case "BR0004"
            GetNamaBarang = "Mesin Cuci"
    End Select
End Function

Function GetHargaBarang(kode As String) As Currency
    Select Case (kode)
        Case "BR0001"
            GetHargaBarang = 1500000
        Case "BR0002"
            GetHargaBarang = 3000000
        Case "BR0003"
            GetHargaBarang = 1000000
        Case "BR0004"
            GetHargaBarang = 2000000
    End Select
End Function

Function TotalHarga(qty As Integer, harga As Currency) As Currency
TotalHarga = qty * harga
End Function

Function Kembalian(bayar, totbay As Currency) As Currency
Kembalian = bayar - totbay
End Function

Coding Utana
Sub kosongkan()
    cbKode.Text = ""
    txtBayar.Text = ""
    txtHarga.Text = ""
    txtKembali.Text = ""
    txtNama.Text = ""
    txtQty.Text = ""
    txtTotal.Text = ""
End Sub

Private Sub cbKode_Click()
    txtNama = GetNamaBarang(cbKode.Text)
    txtHarga = GetHargaBarang(cbKode.Text)
    txtQty.SetFocus
End Sub

Private Sub Command1_Click()
    kosongkan
    cbKode.SetFocus
End Sub

Private Sub Command2_Click()
    Dim pesan As Integer
    pesan = MsgBox("Apakah anda yakin akan keluar,,??", vbOKCancel, "Konfirmasi")
    If pesan = 1 Then End
End Sub

Private Sub Form_Load()
    kosongkan
    'Call kosongkan
    
    cbKode.AddItem "BR0001"
    cbKode.AddItem "BR0002"
    cbKode.AddItem "BR0003"
    cbKode.AddItem "BR0004"
End Sub

Private Sub txtBayar_KeyPress(KeyAscii As Integer)
    'proses untuk enter
    If KeyAscii = 13 Then
        txtKembali = Kembalian(txtBayar.Text, txtTotal.Text) 'function kembalian
        Command1.SetFocus
    End If
    
    'untuk membatasi dari 1-9
    If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack) Then 'untuk menentukan tombol apa saja yang bisa d tekan
        KeyAscii = 0
    End If
End Sub

'proses memakai tombol enter
Private Sub txtQty_KeyPress(KeyAscii As Integer)
    'proses untuk enter
    If KeyAscii = 13 Then
        txtTotal = TotalHarga(txtQty, txtHarga) 'function total harga
        txtBayar.SetFocus
    End If
    
    'untuk membatasi dari 1-9
    If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack) Then 'untuk menentukan tombol apa saja yang bisa d tekan
        KeyAscii = 0
    End If
End Sub


Procedur (Luas Segitiga)
Sub LuasSegitiga() 'procedure untuk menghitung luas segitiga
    alas = Text1
    tinggi = Text2
    luas = (alas * tinggi) / 2
    Text3 = luas
End Sub

Sub LuasSegitga2(alas, tinggi As Integer)
    luas = (alas * tinggi) / 2
    Text3 = luas
End Sub

Private Sub Command1_Click()
    'LuasSegitiga
    LuasSegitga2 Text1, Text2
End Sub

Array
Dim barang(20) As Integer
Dim n As Integer

Private Sub Command1_Click()
    n = n + 1
    barang(n) = Trim(Text1.Text)
    
    Text1.Text = ""
    Text1.SetFocus
    
        List1.Clear
    For i = 1 To n
        List1.AddItem barang(i)
    Next i
End Sub

Private Sub Command2_Click()
    Dim rata As Double
    Dim jumlah As Integer
    jumlah = 0
    For i = 1 To n
        jumlah = barang(i) + jumlah
    Next i
    rata = jumlah / n
    List1.AddItem ""
    List1.AddItem "Rata-Rata = " & rata
End Sub

Private Sub Command3_Click()
angkaMax = barang(1)
For i = 2 To n
If barang(i) > angkaMax Then angkaMax = barang(i)
Next
List1.AddItem ""
List1.AddItem "Harga Maksimum = " & angkaMax

End Sub

Private Sub Command4_Click()
angkaMin = barang(1)
For i = 2 To n
If barang(i) < angkaMin Then angkaMin = barang(i)
Next
List1.AddItem ""
List1.AddItem "Harga Minimum = " & angkaMin
End Sub

Private Sub Form_Load()
   n = 0
End Sub

Penggajian
Private Sub kosongkan() 'procedure kosongkan
    TextNama = ""
    TextJmlAnak = ""
    TextGajiPokok = ""
    TextTnjAnak = ""
    TextTnjSuami = ""
    TextGajiKotor = ""
    TextPajak = ""
    TextGajiBersih = ""
    Combo1 = ""
    Combo2 = ""
End Sub

Private Sub Combo1_Click()
Select Case Combo1.Text
    Case "2A"
        TextGajiPokok.Text = 1000000
    Case "2B"
        TextGajiPokok.Text = 1500000
    Case "3A"
        TextGajiPokok.Text = 2000000
    Case "3B"
        TextGajiPokok.Text = 2500000
    End Select
End Sub

Private Sub Combo2_Click()
Select Case Combo2.Text
    Case "Menikah"
        TextTnjSuami.Text = 0.1 * TextGajiPokok
        TextJmlAnak.Text = ""
        TextTnjAnak.Text = ""
    Case "Belum Menikah"
        TextTnjSuami.Text = 0
        TextJmlAnak.Text = 0
        TextTnjAnak.Text = 0
        TextGajiKotor = TextGajiPokok
        TextPajak = 0.1 * TextGajiKotor
        TextGajiBersih = TextGajiKotor - TextPajak
    End Select
End Sub

Private Sub Command1_Click()
    kosongkan
End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Form_Load()
    kosongkan
End Sub

Private Sub TextJmlAnak_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    If TextJmlAnak = 1 Then
        TextTnjAnak = 0.05 * TextGajiPokok
        ElseIf TextJmlAnak >= 2 Then
        TextTnjAnak = 0.1 * TextGajiPokok
    End If
    TextGajiKotor = Val(TextGajiPokok) + Val(TextTnjAnak) + Val(TextTnjSuami)
    TextPajak = 0.1 * TextGajiKotor
    TextGajiBersih = TextGajiKotor - TextPajak
End If
End Sub


Komentar

Postingan Populer