Hosting Unlimited Indonesia

Cara Membuat Stastik Angka Pada Visual Basic 6.0

Buat Form Kaya Gini Dulu teman!!



Komponen yang dibutuhkan untuk program tersebut adalah :
- Label (sebagai pengenal komponen lainnya, sesuai kebutuhan)
- List1 (sebagai daftar data hasil input)
- Text1 (sebagai input data)
- Text2 (menampilkan data terkecil)
- Text3 (menampilkan data terbesar)
- Text4 (menampilkan total data)
- Text5 (menampilkan nilai rata-rata data)
- Text6 (menampilkan nilai yang sering muncul/ modus)
- Command1 (tombol reset)

Adapun source xode dari program tersebut adalah sebagai berikut :

Dim max, min As Integer
Dim rata, total As Single
Dim freq() As Single
Dim hitung As Single
Dim nilai() As Integer
Private Sub Command1_GotFocus()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
List1.Clear
Text1.SetFocus
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Not IsNumeric(Text1.Text) Then
MsgBox "masukan angka bukan huruf"
Else
List1.AddItem (Text1.Text)
total = total + Val(Text1.Text)
rata = total / List1.ListCount
If List1.ListCount = 1 Then
max = Text1.Text
min = Text1.Text
End If
If max < Val(Text1.Text) Then
max = Text1.Text
End If
If min > Val(Text1.Text) Then
min = Text1.Text
End If
Text2.Text = min
Text3.Text = max
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) = Text1.Text
freq(i) = 1
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
End If
Text1.Text = ""
Text1.SetFocus
End If
End If
End Sub


ok . Semoga berhasil teman !

Subscribe to receive free email updates:

0 Response to "Cara Membuat Stastik Angka Pada Visual Basic 6.0"

Posting Komentar