Minggu, 25 April 2010

Special Requested by Extension Class (ga pake telor)

'Warning : Segala proses di kode ini adalah fiksi.
'Jika ada kesamaan pada kejadian sebenarnya itu adalah kebetulan belaka.
'Selamat belajar, semoga sukses

Dim terbesar As Single
Dim terkecil As Single
Dim total As Single
Dim rata As Single
Dim nilai() As Single
Dim freq() As Single
Dim hitung As Single

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Not IsNumeric(Text1.Text) Then
MsgBox ("Harus angka!!")
Else
List1.AddItem (Text1.Text)
total = total + Text1.Text
rata = total / List1.ListCount
If List1.ListCount = 1 Then
terbesar = Text1.Text
terkecil = Text1.Text
End If
If terbesar <>
terbesar = Text1.Text
End If
If terkecil > Val(Text1.Text) Then
terkecil = Text1.Text
End If
Text2.Text = terbesar
Text3.Text = terkecil
Text4.Text = total
Text5.Text = rata
If List1.ListCount = 1 Then
ReDim Preserve nilai(0)
ReDim Preserve freq(0)
nilai(0) = Text1.Text
freq(0) = 1
Else
Dim ada As Boolean
For i = 0 To UBound(nilai)
If Text1.Text = nilai(i) Then
freq(i) = freq(i) + 1
ada = True
Exit For
End If
Next
If Not ada Then
ReDim Preserve nilai(i)
ReDim Preserve freq(i)
nilai(i) = Text2.Text
freq(i) = 1
End If
'---------------------------------------------
' tugas lanjutan 1
List2.Clear
For m = 0 To UBound(nilai)
List2.AddItem (nilai(m) & " : " & freq(m))
Next
'---------------------------------------------
End If
Dim tmp1 As Single, tmp2 As Single
For k = 0 To UBound(nilai)
If k = 0 Then
tmp1 = nilai(k)
tmp2 = freq(k)
ElseIf freq(k) > tmp2 Then
tmp1 = nilai(k)
tmp2 = freq(k)
End If
Text6.Text = tmp1
Next
'------------------------------------------------
' tugas lanjutan 2
For n = 0 To UBound(nilai)
If nilai(n) <> tmp1 And freq(n) = tmp2 Then
Text6.Text = Text6.Text & ", " & nilai(n)
End If
Next
'------------------------------------------------
End If
Text1.Text = ""
Text1.SetFocus
End If
End Sub

Tidak ada komentar: