Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class NumericalStatistic
- 'Disable buttons if there is no/not enough input'
- Private Sub ValueTextBox_TextChanged(sender As Object, e As EventArgs) Handles ValueTextBox.TextChanged
- ConfirmButton.Enabled = True
- ClearButton.Enabled = True
- 'Confirm button disabled if less than 2 input'
- If ValueTextBox.Lines.Length < 2 Then
- ConfirmButton.Enabled = False
- End If
- 'Clear Button disabled if no input'
- If ValueTextBox.Text = "" Then
- ClearButton.Enabled = False
- End If
- End Sub
- Private Sub ClearButton_Click(sender As Object, e As EventArgs) Handles ClearButton.Click
- Dim userReply As Integer
- userReply = MsgBox("Are you sure you want to clear?", MsgBoxStyle.Exclamation + MsgBoxStyle.OkCancel, "CLEAR")
- 'Clears ValueTextBox if user selects Ok'
- If userReply = MsgBoxResult.Ok Then
- ValueTextBox.Text = ""
- End If
- End Sub
- Private Sub ConfirmButton_Click(sender As Object, e As EventArgs) Handles ConfirmButton.Click
- 'Check if input is numeric before moving to the next result form'
- If CheckMultilineTextIsNumeric(ValueTextBox) Then
- AnswerNumericalStatistic.Show()
- End If
- End Sub
- 'Function to check wether the input is numeric, remove error lines if user wishes'
- Function CheckMultilineTextIsNumeric(ByRef theTextBox As TextBox) As Boolean
- 'Checks user input for non numeric input'
- For i As Integer = 0 To theTextBox.Lines.Length - 1
- If Not IsNumeric(theTextBox.Lines(i).Trim) Then
- Dim userReply As Integer
- userReply = MsgBox("The value text box should contain only numbers!" & vbNewLine & "Do you want to delete the error lines?", MsgBoxStyle.Exclamation + MsgBoxStyle.OkCancel, "ERROR!")
- If userReply = MsgBoxResult.Ok Then
- Dim dummyTextBox(theTextBox.Lines.Length) As String
- Dim count As Integer = 0
- For j As Integer = 0 To theTextBox.Lines.Length - 1
- If IsNumeric(theTextBox.Lines(j).Trim) Then
- 'Creates an array of user input that doesn't include the input errors
- dummyTextBox(count) = theTextBox.Lines(j)
- count += 1
- End If
- Next
- Array.Resize(Of String)(dummyTextBox, count)
- 'resize to get rid of the (will be) empty lines
- Array.Resize(Of String)(theTextBox.Lines, count)
- theTextBox.Lines = dummyTextBox
- End If
- Return False
- End If
- Next
- 'If no input error'
- Return True
- End Function
- End Class
Add Comment
Please, Sign In to add comment