Kamis, 09 Februari 2012
0 komentar

Program Mencari Nilai Terbesar (Maksimum) dan Terkecil (Minimum) serta Rata-Rata



Program Mencari Nilai Terbesar (Maksimum) dan Terkecil (Minimum) serta Rata-Rata
Berikut contoh program visual basic untuk mencari nilai tebesar (maximum) dan nilai terkecil (minimum) serta rata-rata.
Pertama buat tampilan seperti gambar di bawah ini :


Kemudian buat script seperti di bawah ini :

Dim nama() As String, nim, tugas, uts, uas(), rata_rata() As Single, awal, counter, max, min, jum As Integer
Sub input_data()
ReDim nama(counter) As String
ReDim nim(counter), tugas(counter), uts(counter), uas(counter), rata_rata(counter), freq(counter) As Single
nama(counter) = Trim(Text1.Text)
nim(counter) = Val(Text2.Text)
tugas(counter) = Val(Text3.Text)
uts(counter) = Val(Text4.Text)
uas(counter) = Val(Text5.Text)
'Mencari rata-rata setiap mahasiswa
x_tugas = tugas(counter) * 40 / 100
x_uts = uts(counter) * 30 / 100
x_uas = uas(counter) * 30 / 100
rata_rata(counter) = (x_tugas + x_uts + x_uas)
awal = 0
For i = awal To counter
List1.AddItem ("Nama : " & nama(i))
List1.AddItem ("Nim : " & nim(i))
List1.AddItem ("Tugas : " & tugas(i))
List1.AddItem ("UTS : " & uts(i))
List1.AddItem ("UAS : " & uas(i))
List1.AddItem ("NILAI RATA - RATA : " & rata_rata(i))
List1.AddItem ("-------------------------------------------------------------------------------------------")
Next i
'Mencari rata-rata keseluruhan
For i = 0 To counter
List2.AddItem (rata_rata(i)) 'Menampung hasil yang akan dibagi
jum = jum + rata_rata(i)
bagi = List2.ListCount 'Mendapatkan nilai untuk pembagi
Next i
Text8.Text = Str(jum / bagi)
'Mencari nilai maximum dari rata-rata masing-masing mahasiswa
max = Val(Text6.Text)
For i = 0 To counter
If rata_rata(i) > max Then
max = rata_rata(i)
Else
max = max
End If
Next i
Text6.Text = Str(max)
'Mencari nilai minimum dari rata-rata masing-masing mahasiswa
For i = 0 To counter
If min = 0 Then
min = 32767 'batas nilai integer
Else
min = min
End If
If rata_rata(i) < min Then
min = rata_rata(i)
Else
min = min
End If
Next i
Text7.Text = Str(min)
End Sub
Private Sub hapus_Click()
List1.Clear
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
End Sub
Private Sub input_Click()
Call input_data
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text1.SetFocus
End Sub
Private Sub reset_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text1.SetFocus
End Sub


Semoga bisa membantu dan mohon sharingnya kalo ada kesalan syntax
belajar mode on
* Untuk lebih lengkap, download programnya disini


 
Toggle Footer
Top