Kamis, 24 Januari 2013

Visual Basic : Program Menghitung Nilai Akhir Matakuliah


Contoh Kasus :
1.  Gunakan fungsi manipulasi string untuk menentukan jurusan (jurusan ditentukan oleh isi digit ketiga dari kiri pada NIM).

2.  Buat agar textbox nilai yang tidak akan digunakan untuk peginputan, properti enabled-nya di set menjadi false.

Berikut Formnya :



Kemudian ketikkan listing berikut :

Private Sub Command1_Click()
‘Tombol Hitung
Dim na As Single
Dim nt As Integer
Dim nm As Integer
Dim nf As Integer
Dim nh As String

nt = Val(Text4.Text)
nm = Val(Text5.Text)
nf = Val(Text6.Text)

If Option1.Value = True Then
na = (0.4 * nm) + (0.6 * nf)
ElseIf Option2.Value = True Then
na = (0.2 * nt) + (0.4 * nm) + (0.4 * nf)
ElseIf Option3.Value = True Then
na = (0.3 * nt) + (0.4 * nm) + (0.3 * nf)
End If

If na >= 80 Then
nh = "A"
ElseIf na >= 60 Then
nh = "B"
ElseIf na >= 40 Then
nh = "C"
ElseIf na >= 30 Then
nh = "D"
ElseIf na < 30 Then
nh = "E"
End If

Text7.Text = na
Text8.Text = nh
End Sub

Private Sub Command2_Click()
‘Tombol Ulangi
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Option1.Value = False
Option2.Value = False
Option3.Value = False
Text1.SetFocus
End Sub

Private Sub Command3_Click()
‘Tombol Keluar
End
End Sub

Private Sub Option1_Click()
‘Option  C/C++
If Option1.Value = True Then
Text4.Enabled = False
End If
End Sub

Private Sub Option2_Click()
‘Option Pascal
If Option2.Value = True Then
Text4.Enabled = True
End If
End Sub

Private Sub Option3_Click()
‘Option Visual basic
If Option3.Value = True Then
Text4.Enabled = True
End If
End Sub

Private Sub Text1_LostFocus()
‘Text1
Dim jur As String

If Mid(Trim(Text1), 3, 1) = "1" Then
jur = "Sistem Informasi"
ElseIf Mid(Trim(Text1), 3, 1) = "2" Then
jur = "Teknik Informatika"
ElseIf Mid(Trim(Text1), 3, 1) = "3" Then
jur = "Manajemen Informatika"
End If

Text3.Text = jur
End Sub

Outputnya :




Artikel Terkait :

Bagikan :

2 komentar: