Created
September 24, 2016 16:05
-
-
Save krysseltillada/b2c506963fa8bf571f8a85c5743d6fa6 to your computer and use it in GitHub Desktop.
Frequency distribution generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Class Form1 | |
Class Pair | |
Public first As String | |
Public second As String | |
End Class | |
Function generateFrequency() As ArrayList | |
If (dataList.Items.Count > 0 And txtbClassSize.Text.Length > 0) Then | |
Dim min As Integer = dataList.Items.Item(0) | |
Dim max As Integer = dataList.Items.Item(0) | |
For digitCount = 0 To dataList.Items.Count | |
Try | |
If (dataList.Items.Item(digitCount) < min) Then | |
min = dataList.Items.Item(digitCount) | |
End If | |
Catch e As ArgumentOutOfRangeException | |
End Try | |
Next | |
For digitCount = 0 To dataList.Items.Count | |
Try | |
If (dataList.Items.Item(digitCount) > max) Then | |
max = dataList.Items.Item(digitCount) | |
End If | |
Catch e As ArgumentOutOfRangeException | |
End Try | |
Next | |
MsgBox(min & " min") | |
MsgBox(max & " max") | |
Dim range As Integer = max - min | |
Dim noc As Integer = (range / CInt(txtbClassSize.Text)) + 1 | |
Dim currentInterval As Integer | |
Dim classInterval As New ArrayList | |
Dim frequency As New ArrayList | |
For interval = 0 To noc - 1 | |
currentInterval = max - CInt(txtbClassSize.Text) + 1 | |
Dim pair As New Pair | |
pair.first = currentInterval | |
pair.second = max | |
MsgBox(pair.first & " " & pair.second) | |
classInterval.Add(pair) | |
max = currentInterval - 1 | |
Next | |
Dim count As Integer = 0 | |
MsgBox("datalist " & dataList.Items.Count) | |
For pairCount = 0 To classInterval.Count - 1 | |
Dim pair As Pair = classInterval.Item(pairCount) | |
For digitCount = 0 To dataList.Items.Count | |
Try | |
If (CInt(dataList.Items.Item(digitCount)) >= pair.first And | |
CInt(dataList.Items.Item(digitCount)) <= pair.second) Then | |
count += 1 | |
End If | |
Catch e As ArgumentOutOfRangeException | |
End Try | |
Next | |
frequency.Add(count) | |
count = 0 | |
Next | |
For insertCount = 0 To frequency.Count - 1 | |
Dim getPair As Pair = classInterval.Item(insertCount) | |
dataTable.Rows.Add(New String() {getPair.first & " - " & getPair.second, frequency.Item(insertCount)}) | |
Next | |
Else | |
If (dataList.Items.Count <= 0 And txtbClassSize.Text.Length <= 0) Then | |
MsgBox("add some digits and class size") | |
ElseIf (dataList.Items.Count <= 0) Then | |
MsgBox("add some digits") | |
Else | |
MsgBox("need to have a class size") | |
End If | |
End If | |
End Function | |
Private Sub btnEnter_Click(sender As Object, e As EventArgs) Handles btnEnter.Click | |
If (IsNumeric(txtbDigit.Text)) Then | |
dataList.Items.Add(" " & txtbDigit.Text) | |
txtbDigit.Clear() | |
Else | |
If (txtbDigit.Text.Length <= 0) Then | |
MsgBox("empty", MsgBoxStyle.Exclamation, "cant enter") | |
Else | |
MsgBox("enter a digit", MsgBoxStyle.Exclamation, "enter some digits") | |
End If | |
End If | |
End Sub | |
Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click | |
txtbDigit.Text = "" | |
txtbClassSize.Text = "" | |
dataList.Items.Clear() | |
dataTable.Rows.Clear() | |
End Sub | |
Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click | |
dataTable.Rows.Clear() | |
txtbClassSize.Text = "" | |
generateFrequency() | |
End Sub | |
Private Sub txtbDigit_Enter(sender As Object, e As EventArgs) | |
If (IsNumeric(txtbDigit.Text)) Then | |
dataList.Items.Add(" " & txtbDigit.Text) | |
txtbDigit.Clear() | |
Else | |
If (txtbDigit.Text.Length <= 0) Then | |
MsgBox("empty", MsgBoxStyle.Exclamation, "cant enter") | |
Else | |
MsgBox("enter a digit", MsgBoxStyle.Exclamation, "enter some digits") | |
End If | |
End If | |
End Sub | |
Private Sub txtbDigit_KeyUp(sender As Object, e As KeyEventArgs) Handles txtbDigit.KeyUp | |
If (e.KeyValue = Keys.Enter) Then | |
If (IsNumeric(txtbDigit.Text)) Then | |
dataList.Items.Add(" " & txtbDigit.Text) | |
txtbDigit.Clear() | |
Else | |
If (txtbDigit.Text.Length <= 0) Then | |
MsgBox("empty", MsgBoxStyle.Exclamation, "cant enter") | |
Else | |
MsgBox("enter a digit", MsgBoxStyle.Exclamation, "enter some digits") | |
End If | |
End If | |
End If | |
End Sub | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment