Minggu, 04 Desember 2011

Latihan 3 - Menghitung Rata Rata Nilai - Visual Basic

Buat Desain Seperti ini :





masukan script di bawah ini sesuai dengan procedurenya :

Dim rata As Double
Dim hasil As String
Private Sub Command1_Click()
If Command1.Caption = "Baru" Then
Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text1.SetFocus
Command1.Caption = "Proses"
ElseIf Command1.Caption = "Proses" Then

'Perhitungan rata rata
rata = (Val(Text1.Text) + Val(Text2.Text) + Val(Text3.Text)) / 3
Text4.Text = CInt(rata)

'perhitungan hasil
If rata >= 60 Then
hasil = "Lulus"
Else
hasil = "Tidak Lulus"
End If
Text5.Text = hasil
Command1.Caption = "Baru"
End If
End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Form_Load()
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
End Sub


1 komentar: