Sabtu, 03 Desember 2011

Latihan 2 - Form Nilai - Visual Basic

Buat desain seperti ini :

 klik 2x di form dan masukan script ini :

Private Sub Form_Load()
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False
Text6.Enabled = False
Combo1.Enabled = False

Combo1.AddItem "Teknik Informatika"
Combo1.AddItem "Manajemen Informatika"
Combo1.AddItem "Komputer Akutansi"
Combo1.AddItem "Desain Grafis"
End Sub



kemudian di tombol proses klik 2x dan masukan script ini :

Private Sub Command1_Click()
If Command1.Caption = "Proses" Then
Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
Text4.Enabled = True
Text5.Enabled = True
Text6.Enabled = True
Combo1.Enabled = True
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
Combo1.ListIndex = -1
Combo1.Text = "[pilih jurusan]"
Text5.SetFocus
Command1.Caption = "Hitung"
ElseIf Command1.Caption = "Hitung" Then
Dim angka As Double
Dim huruf As String
Dim keterangan As String

'mengecek inputan kosong
If Text5.Text = "" Or Text6.Text = "" Or Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Or Combo1.ListIndex = -1 Then
MsgBox "Harap isi data dengan lengkap, jangan ada yang kosong", , "Konfirmasi"

'mengecek inputan nilai angka atau huruf
ElseIf Not IsNumeric(Text1.Text) Or Not IsNumeric(Text2.Text) Or Not IsNumeric(Text3.Text) Or Not IsNumeric(Text4.Text) Then
MsgBox "Harap isi Nilai dengan Angka", , "Konfirmasi"

'mengecek apakah inputan nilai dari 0-100
ElseIf (Val(Text1.Text) < 0 Or Val(Text1.Text) > 100) Or (Val(Text2.Text) < 0 Or Val(Text2.Text) > 100) Or (Val(Text3.Text) < 0 Or Val(Text3.Text) > 100) Or (Val(Text4.Text) < 0 Or Val(Text4.Text) > 100) Then
MsgBox "Harap isi Nilai antara 0 - 100", , "Konfirmasi"

Else
'perhitungan angka
angka = (0.1 * Val(Text1.Text)) + (0.2 * Val(Text2.Text)) + (0.3 * Val(Text3.Text)) + (0.4 * Val(Text4.Text))

'perhitungan huruf
If angka >= 86 Then
huruf = "A"
ElseIf angka >= 75 Then
huruf = "B"
ElseIf angka >= 60 Then
huruf = "C"
ElseIf angka >= 50 Then
huruf = "D"
Else
huruf = "E"
End If

'pemberian keterangan
If huruf = "A" Then
keterangan = "Baik Sekali"
ElseIf huruf = "B" Then
keterangan = "Baik"
ElseIf huruf = "C" Then
keterangan = "Cukup"
ElseIf huruf = "D" Then
keterangan = "Kurang"
Else
keterangan = "Buruk"
End If

Text7.Text = Str(angka)
Text8.Text = huruf
Text9.Text = keterangan

Command1.Caption = "Proses"
End If
End If
End Sub


untuk keluar masukan script ini :

Private Sub Command2_Click()
Unload Me
End Sub

Tidak ada komentar:

Posting Komentar