Sunday, January 13, 2013

Perulangan dan Percabangan Pada Visual Basic

Share on :

 
contoh  percabangan (Case_Of) =

Dim Upah, Gaji, Jamkerja As Long
Const Lembur As Long = 17500

Private Sub cmdhitung_Click()
If txtnama.Text = "" Then
    MsgBox "Nama Tidak Boleh Kosong", vbCritical, "Field Error"
    txtnama.SetFocus
    Exit Sub
End If

If cmbgolongan.Text = "" Then
    MsgBox "Golongan Belum Dipilih", vbCritical, "Field Error"
    cmbgolongan.SetFocus
    Exit Sub
End If

If txtjamkerja.Text = "" Then
    MsgBox "Jam Kerja Tidak Boleh Kosong", vbCritical, "Field Error"
    txtjamkerja.SetFocus
    Exit Sub
End If

If Not IsNumeric(txtjamkerja.Text) Then
    MsgBox "Harus Angka!", vbCritical, "Field Error"
    txtjamkerja.SetFocus
    Exit Sub
End If

lblnama.Caption = txtnama.Text
lblgolongan.Caption = cmbgolongan.Text
lbljamkerja.Caption = txtjamkerja.Text & " Jam"

Select Case cmbgolongan.Text
Case "A"
    Upah = 7000
    Jamkerja = txtjamkerja.Text
    If Jamkerja <= 48 Then
        Gaji = Upah * Jamkerja
        lblgaji.Caption = "Rp. " & Gaji & " /Minggu"
    End If
    If Jamkerja > 48 Then
        Gaji = ((Jamkerja - 48) * Lembur) + (48 * Upah)
        lblgaji.Caption = "Rp. " & Gaji & " /Minggu"
    End If
Case "B"
    Upah = 9000
    Jamkerja = txtjamkerja.Text
    If Jamkerja <= 48 Then
        Gaji = Upah * Jamkerja
        lblgaji.Caption = "Rp. " & Gaji & " /Minggu"
    End If
    If Jamkerja > 48 Then
        Gaji = ((Jamkerja - 48) * Lembur) + (48 * Upah)
        lblgaji.Caption = "Rp. " & Gaji & " /Minggu"
    End If
Case "C"
    Upah = 12000
    Jamkerja = txtjamkerja.Text
    If Jamkerja <= 48 Then
        Gaji = Upah * Jamkerja
        lblgaji.Caption = "Rp. " & Gaji & " /Minggu"
    End If
    If Jamkerja > 48 Then
        Gaji = ((Jamkerja - 48) * Lembur) + (48 * Upah)
        lblgaji.Caption = "Rp. " & Gaji & " /Minggu"
    End If
Case "D"
    Jamkerja = txtjamkerja.Text
    If Jamkerja <= 48 Then
        Gaji = Upah * Jamkerja
        lblgaji.Caption = "Rp. " & Gaji & " /Minggu"
    End If
    If Jamkerja > 48 Then
        Gaji = ((Jamkerja - 48) * Lembur) + (48 * Upah)
        lblgaji.Caption = "Rp. " & Gaji & " /Minggu"
    End If
End Select

End Sub

Private Sub cmdkeluar_Click()
Tanya = MsgBox("Apakah Anda Yakin?", vbQuestion + vbYesNo, "Akhiri Program")
Select Case Tanya
Case vbYes
    End
Case vbNo
    Cancel = 1
End Select

End Sub

Private Sub cmdulangi_Click()
    txtnama.Text = ""
    cmbgolongan.ListIndex = 0
    txtjamkerja.Text = ""
    lblnama.Caption = ""
    lblgolongan.Caption = ""
    lbljamkerja.Caption = ""
    lblgaji.Caption = ""
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Tanya = MsgBox("Apakah Anda Yakin?", vbQuestion + vbYesNo, "Akhiri Program")
Select Case Tanya
Case vbYes
    End
Case vbNo
    Cancel = 1
End Select
End Sub

0 komentar:

Post a Comment