“Latihan Olah Nilai” dengan Visual Basic 6.0
“Latihan Olah Nilai” yang terdapat pada eBook “Panduan Praktik Pemrograman Komputer”.
Tidak banyak modifikasi yang dibuat. Hanya sekedar menambahkan fitur tombol “Baru”. Untuk lebih lengkapnya dapat dilihat pada kode sumber yang disertakan.
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0"; "MSCOMCTL.OCX"
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "Data Nilai Mahasiswa"
ClientHeight = 4950
ClientLeft = 45
ClientTop = 405
ClientWidth = 7695
BeginProperty Font
Name = "Segoe UI"
Size = 9
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 4950
ScaleWidth = 7695
StartUpPosition = 2 'CenterScreen
Begin MSComctlLib.StatusBar StatusBar1
Align = 2 'Align Bottom
Height = 375
Left = 0
TabIndex = 20
Top = 4575
Visible = 0 'False
Width = 7695
_ExtentX = 13573
_ExtentY = 661
_Version = 393216
BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628}
NumPanels = 1
BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628}
EndProperty
EndProperty
End
Begin VB.CommandButton Command1
Caption = "&Baru"
Enabled = 0 'False
Height = 495
Index = 1
Left = 240
TabIndex = 19
Top = 3480
Width = 7215
End
Begin VB.CommandButton Command1
Caption = "K&eluar"
Height = 495
Index = 0
Left = 5160
TabIndex = 18
Top = 4320
Width = 2295
End
Begin VB.Frame Frame1
Caption = "Keterangan Nilai:"
Height = 2535
Index = 1
Left = 4080
TabIndex = 3
Top = 840
Width = 3375
Begin VB.TextBox Text1
BeginProperty Font
Name = "Segoe UI"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Index = 7
Left = 1560
Locked = -1 'True
TabIndex = 17
Top = 1680
Width = 1455
End
Begin VB.TextBox Text1
BeginProperty Font
Name = "Segoe UI"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Index = 6
Left = 1560
Locked = -1 'True
TabIndex = 15
Top = 1080
Width = 1455
End
Begin VB.TextBox Text1
Alignment = 1 'Right Justify
BeginProperty Font
Name = "Segoe UI"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Index = 5
Left = 1560
Locked = -1 'True
TabIndex = 13
Top = 480
Width = 1455
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Keterangan:"
Height = 225
Index = 7
Left = 360
TabIndex = 16
Top = 1740
Width = 945
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Grade:"
Height = 225
Index = 6
Left = 840
TabIndex = 14
Top = 1140
Width = 510
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Nilai Akhir:"
Height = 225
Index = 5
Left = 480
TabIndex = 12
Top = 540
Width = 870
End
End
Begin VB.Frame Frame1
Caption = "Nilai:"
Height = 2535
Index = 0
Left = 240
TabIndex = 2
Top = 840
Width = 3615
Begin VB.TextBox Text1
Alignment = 1 'Right Justify
BeginProperty Font
Name = "Segoe UI"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Index = 4
Left = 1800
MaxLength = 3
TabIndex = 11
Top = 1920
Width = 1455
End
Begin VB.TextBox Text1
Alignment = 1 'Right Justify
BeginProperty Font
Name = "Segoe UI"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Index = 3
Left = 1800
MaxLength = 3
TabIndex = 9
Top = 1400
Width = 1455
End
Begin VB.TextBox Text1
Alignment = 1 'Right Justify
BeginProperty Font
Name = "Segoe UI"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Index = 2
Left = 1800
MaxLength = 3
TabIndex = 7
Top = 840
Width = 1455
End
Begin VB.TextBox Text1
Alignment = 1 'Right Justify
BeginProperty Font
Name = "Segoe UI"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Index = 1
Left = 1800
MaxLength = 3
TabIndex = 5
Top = 300
Width = 1455
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "UAS (40%):"
Height = 225
Index = 4
Left = 660
TabIndex = 10
Top = 1980
Width = 870
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "UTS (30%):"
Height = 225
Index = 3
Left = 680
TabIndex = 8
Top = 1455
Width = 855
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Tugas (20%):"
Height = 225
Index = 2
Left = 520
TabIndex = 6
Top = 900
Width = 1020
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Kehadiran (10%):"
Height = 225
Index = 1
Left = 240
TabIndex = 4
Top = 360
Width = 1335
End
End
Begin VB.TextBox Text1
BeginProperty Font
Name = "Segoe UI"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Index = 0
Left = 3000
TabIndex = 1
Top = 240
Width = 2655
End
Begin VB.Line Line1
Index = 0
X1 = 240
X2 = 7440
Y1 = 4200
Y2 = 4200
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Nama:"
Height = 225
Index = 0
Left = 2040
TabIndex = 0
Top = 315
Width = 525
End
Begin VB.Line Line1
BorderColor = &H00FFFFFF&
BorderWidth = 4
Index = 1
X1 = 240
X2 = 7440
Y1 = 4200
Y2 = 4200
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0:
Unload Me
Case 1:
Dim i%
For i = 0 To 7
Text1(i).Text = Empty
Next
Command1(1).Enabled = False
Text1(0).SetFocus
End Select
End Sub
Private Sub Form_Unload(Cancel As Integer)
If MsgBox("Keluar program ?", vbQuestion + vbYesNo, "Perhatian") = vbNo Then
Cancel = 1
End If
End Sub
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
Select Case Index
Case 0:
If (KeyAscii >= Asc("0") And KeyAscii <= Asc("9")) Then
Beep
KeyAscii = 0
End If
If (KeyAscii = 13) Then
SendKeys "{tab}"
KeyAscii = 0
End If
Case 1:
If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or _
KeyAscii = vbKeyBack Or KeyAscii = vbKeyReturn) Then
Beep
KeyAscii = 0
End If
If (KeyAscii = 13) Then
If Val(Text1(Index).Text) > 100 Then
Pesan_Kesalahan
Text1(Index).Text = Empty
Text1(Index).SetFocus
Exit Sub
Else
SendKeys "{tab}"
KeyAscii = 0
End If
End If
Case 2:
If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or _
KeyAscii = vbKeyBack Or KeyAscii = vbKeyReturn) Then
Beep
KeyAscii = 0
End If
If (KeyAscii = 13) Then
If Val(Text1(Index).Text) > 100 Then
Pesan_Kesalahan
Text1(Index).Text = Empty
Text1(Index).SetFocus
Exit Sub
Else
SendKeys "{tab}"
KeyAscii = 0
End If
End If
Case 3:
If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or _
KeyAscii = vbKeyBack Or KeyAscii = vbKeyReturn) Then
Beep
KeyAscii = 0
End If
If (KeyAscii = 13) Then
If Val(Text1(Index).Text) > 100 Then
Pesan_Kesalahan
Text1(Index).Text = Empty
Text1(Index).SetFocus
Exit Sub
Else
SendKeys "{tab}"
KeyAscii = 0
End If
End If
Case 4:
If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or _
KeyAscii = vbKeyBack Or KeyAscii = vbKeyReturn) Then
Beep
KeyAscii = 0
End If
If (KeyAscii = 13) Then
If Val(Text1(Index).Text) > 100 Then
Pesan_Kesalahan
Text1(Index).Text = Empty
Text1(Index).SetFocus
Exit Sub
Else
Dim Nilai_Akhir%, Grade_Mahasiswa$, Keterangan$
Nilai_Akhir = (0.1 * Val(Text1(1).Text)) + _
(0.2 * Val(Text1(2).Text)) + _
(0.3 * Val(Text1(3).Text)) + _
(0.4 * Val(Text1(4).Text))
Text1(5).Text = Nilai_Akhir
If Val(Text1(5).Text) >= 80 Then
Grade_Mahasiswa = "A"
Keterangan = "Sangat Baik"
ElseIf Val(Text1(5).Text) >= 65 Then
Grade_Mahasiswa = "B"
Keterangan = "Baik"
ElseIf Val(Text1(5).Text) >= 55 Then
Grade_Mahasiswa = "C"
Keterangan = "Cukup"
ElseIf Val(Text1(5).Text) >= 45 Then
Grade_Mahasiswa = "D"
Keterangan = "Kurang"
Else
Grade_Mahasiswa = "E"
Keterangan = "Sangat Kurang"
End If
Text1(6).Text = Grade_Mahasiswa
Text1(7).Text = Keterangan
Command1(1).Enabled = True
Command1(1).SetFocus
End If
End If
End Select
End Sub
Private Sub Pesan_Kesalahan()
MsgBox "Kesalahan memasukan data" & vbCrLf & vbCrLf & _
"Nilai maksimum masukan data bernilai 100", vbCritical, _
"Kesalahan Input"
End Sub
Unduh Kode Sumber
Label: VB6
0 Komentar:
Posting Komentar
Berlangganan Posting Komentar [Atom]
<< Beranda