Pages

Jumat, 13 Juni 2014

logika dan fungsi visual basic

  1. 1.       Contoh Form Dengan Operator Logika

cmdabesar
cmdakecil
cmdasama
cmdcbesar
cmdckecil
cmdcsama
cmdproses
cmdhapus
cmdkeluar
Listing Program:
Private Sub cmdabesar_Click()
If Val(txta) > Val(txtb) Then
txthasilx = True
Else
txthasilx = False
End If
End Sub
Private Sub cmdakecil_Click()
If Val(txta) < Val(txtb) Then
txthasilx = True
Else
txthasilx = False
End If
End Sub
Private Sub cmdasama_Click()
If Val(txta) = Val(txtb) Then
txthasilx = True
Else
txthasilx = False
End If

End Sub
Private Sub cmdcbesar_Click()
If Val(txtc) > Val(txtd) Then
txthasily = True
Else
txthasily = False
End If
End Sub
Private Sub cmdckecil_Click()
If Val(txtc) < Val(txtd) Then
txthasily = True
Else
txthasily = False
End If
End Sub
Private Sub cmdcsama_Click()
If Val(txtc) = Val(txtd) Then
txthasily = True
Else
txthasily = False
End If
End Sub
Private Sub cmdhapus_Click()
txta = “”
txtb = “”
txtc = “”
txtd = “”
txthasilx = “”
txthasily = “”
txtnotx = “”
txtnoty = “”
txtandy = “”
txtory = “”
txta.SetFocus
End Sub
Private Sub cmdkeluar_Click()
End
End Sub
Private Sub cmdproses_Click()
If Not txthasilx = False Then
txtnotx = False
Else
txtnotx = True
End If
If Not txthasily = False Then
txtnoty = False
Else
txtnoty = True
End If
If txthasilx = True And txthasily = True Then
txtandy = True
Else
txtandy = False
End If
If txthasilx = True Or txthasily = True Then
txtory = True
Else
txtory = False
End If
If txthasilx = True Or txthasily = False Then
txtory = True
Else
txtory = False
End If
If txthasilx = False Or txthasily = False Then
txtory = False
Else
txtory = True
End If
If txthasilx = True Or txthasily = True Then
txtory = True
Else
txtory = False
End If
End Sub


  1. 2.       Contoh Form Dengan Fungsi IF
tabs
ttgs
tuts
tuas
trata
tgrd
tket
cmdproses
cmdbersih
cmdkeluar
Ketentuan Soal:
  • Isi nilai absen, tugas, uts dan uas
  • Klik proses maka akan muncul nilai rata-rata, grade dan keterangan
  • Nilai rata-rata = (absen+tugas+uts+uas)/4
  • Jika nilai rata >= 90, mk grade= A, keterangan= lulus
jika nilai rata >=75, mk grade= B, keterangan=lulus
jika nilai rata >=60, mk grade= C, keterangan= lulus
jika nilai rata < 60, mk grade= D, keterangan= gagal
  • Tombol bersih untuk menginput kembali
Listing Program:
Private Sub cmdbersih_Click()
tabs.Text = “”
ttgs.Text = “”
tuts.Text = “”
tuas.Text = “”
trata.Text = “”
tgrd.Text = “”
tket.Text = “”
tabs.SetFocus
End Sub
Private Sub cmdkeluar_Click()
End
End Sub
Private Sub cmdproses_Click()
trata.Text = Val(Val(tabs.Text) + Val(ttgs.Text) + Val(tuts.Text) + Val(tuas.Text)) / 4
If trata >= 90 Then
tgrd.Text = “A”
tket.Text = “LULUS”
Else
If trata >= 75 Then
tgrd.Text = “B”
tket.Text = “LULUS”
Else
If trata >= 60 Then
tgrd.Text = “C”
tket.Text = “LULUS”
Else
tgrd.Text = “D”
tket.Text = “GAGAL”
End If
End If
End If
End If
End Sub
Private Sub Form_Activate()
cmdproses.Enabled = False
tabs.SetFocus
End Sub
Private Sub tuas_Change()

cmdproses.Enabled = True

0 komentar:

Posting Komentar