I was wondering what to do the coding is finished but i have a problem with exiting after I just open the program and when the text fields are empty without a number This is conflicting with the validating process that i have to enter a number in each textbox just to exit program. I have to make sure that a number can be the only value entered. If someone can help thanks.
CODE
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim total As Decimal
Dim average As Decimal
total = Val(txtDecember.Text) + Val(txtNovember.Text) + Val(txtOctober.Text) + Val(txtSeptember.Text) + Val(txtAugust.Text) + Val(txtJanuary.Text) + Val(txtFebruary.Text) + Val(txtMarch.Text) + Val(txtApril.Text) + Val(txtMay.Text) + Val(txtJune.Text) + Val(txtJuly.Text)
lblTotal.Text = FormatNumber(total)
average = total / 12
lblAverage.Text = FormatNumber(average)
End Sub
Private Sub txtApril_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtApril.Validating
'Validating input for April
If Not IsNumeric(txtApril.Text) Then
MessageBox.Show("Must enter a number!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtApril.SelectionStart = 0
txtApril.SelectionLength = txtApril.Text.Length
e.Cancel = True
ElseIf Val(txtApril.Text) < 0 Then
MessageBox.Show("Enter a postive number!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtApril.SelectionStart = 0
txtApril.SelectionLength = txtApril.Text.Length
e.Cancel = True
Else
e.Cancel = False
End If
End Sub
Private Sub txtAugust_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtAugust.Validating
'Validating input for August
If Not IsNumeric(txtAugust.Text) Then
MessageBox.Show("Must enter a number!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtAugust.SelectionStart = 0
txtAugust.SelectionLength = txtAugust.Text.Length
e.Cancel = True
ElseIf Val(txtAugust.Text) < 0 Then
MessageBox.Show("Enter a postive number!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtAugust.SelectionStart = 0
txtAugust.SelectionLength = txtAugust.Text.Length
e.Cancel = True
Else
e.Cancel = False
End If
End Sub
Private Sub txtDecember_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtDecember.Validating
'Validating input for December
If Not IsNumeric(txtDecember.Text) Then
MessageBox.Show("Must enter a number!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtDecember.SelectionStart = 0
txtDecember.SelectionLength = txtDecember.Text.Length
e.Cancel = True
ElseIf Val(txtDecember.Text) < 0 Then
MessageBox.Show("Enter a postive number!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtDecember.SelectionStart = 0
txtDecember.SelectionLength = txtDecember.Text.Length
e.Cancel = True
Else
e.Cancel = False
End If
End Sub
Private Sub txtFebruary_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtFebruary.Validating
'Validating input for February
If Not IsNumeric(txtFebruary.Text) Then
MessageBox.Show("Must enter a number!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtFebruary.SelectionStart = 0
txtFebruary.SelectionLength = txtFebruary.Text.Length
e.Cancel = True
ElseIf Val(txtFebruary.Text) < 0 Then
MessageBox.Show("Enter a postive number!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtFebruary.SelectionStart = 0
txtFebruary.SelectionLength = txtFebruary.Text.Length
e.Cancel = True
Else
e.Cancel = False
End If
End Sub
Private Sub txtJanuary_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtJanuary.Validating
'Validating input for January
If Not IsNumeric(txtJanuary.Text) Then
MessageBox.Show("Must enter a number!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtJanuary.SelectionStart = 0
txtJanuary.SelectionLength = txtJanuary.Text.Length
e.Cancel = True
ElseIf Val(txtJanuary.Text) < 0 Then
MessageBox.Show("Enter a postive number!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtJanuary.SelectionStart = 0
txtJanuary.SelectionLength = txtJanuary.Text.Length
e.Cancel = True
Else
e.Cancel = False
End If
End Sub
Private Sub txtJuly_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtJuly.Validating
'Validating input for July
If Not IsNumeric(txtJuly.Text) Then
MessageBox.Show("Must enter a number!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtJuly.SelectionStart = 0
txtJuly.SelectionLength = txtJuly.Text.Length
e.Cancel = True
ElseIf Val(txtJuly.Text) < 0 Then
MessageBox.Show("Enter a postive number!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtJuly.SelectionStart = 0
txtJuly.SelectionLength = txtJuly.Text.Length
e.Cancel = True
Else
e.Cancel = False
End If
End Sub
Private Sub txtJune_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtJune.Validating
'Validating input for June
If Not IsNumeric(txtJune.Text) Then
MessageBox.Show("Must enter a number!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtJune.SelectionStart = 0
txtJune.SelectionLength = txtJune.Text.Length
e.Cancel = True
ElseIf Val(txtJune.Text) < 0 Then
MessageBox.Show("Enter a postive number!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtJune.SelectionStart = 0
txtJune.SelectionLength = txtJune.Text.Length
e.Cancel = True
Else
e.Cancel = False
End If
End Sub
Private Sub txtMarch_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMarch.Validating
'Validating input for March
If Not IsNumeric(txtMarch.Text) Then
MessageBox.Show("Must enter a number!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtMarch.SelectionStart = 0
txtMarch.SelectionLength = txtMarch.Text.Length
e.Cancel = True
ElseIf Val(txtMarch.Text) < 0 Then
MessageBox.Show("Enter a postive number!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtMarch.SelectionStart = 0
txtMarch.SelectionLength = txtMarch.Text.Length
e.Cancel = True
Else
e.Cancel = False
End If
End Sub
Private Sub txtMay_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMay.Validating
'Validating input for May
If Not IsNumeric(txtMay.Text) Then
MessageBox.Show("Must enter a number!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtMay.SelectionStart = 0
txtMay.SelectionLength = txtMay.Text.Length
e.Cancel = True
ElseIf Val(txtMay.Text) < 0 Then
MessageBox.Show("Enter a postive number!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtMay.SelectionStart = 0
txtMay.SelectionLength = txtMay.Text.Length
e.Cancel = True
Else
e.Cancel = False
End If
End Sub
Private Sub txtNovember_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtNovember.Validating
'Validating input for November
If Not IsNumeric(txtNovember.Text) Then
MessageBox.Show("Must enter a number!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtNovember.SelectionStart = 0
txtNovember.SelectionLength = txtNovember.Text.Length
e.Cancel = True
ElseIf Val(txtNovember.Text) < 0 Then
MessageBox.Show("Enter a postive number!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtNovember.SelectionStart = 0
txtNovember.SelectionLength = txtNovember.Text.Length
e.Cancel = True
Else
e.Cancel = False
End If
End Sub
Private Sub txtOctober_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtOctober.Validating
'Validating input for October
If Not IsNumeric(txtOctober.Text) Then
MessageBox.Show("Must enter a number!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtOctober.SelectionStart = 0
txtOctober.SelectionLength = txtOctober.Text.Length
e.Cancel = True
ElseIf Val(txtOctober.Text) < 0 Then
MessageBox.Show("Enter a postive number!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtOctober.SelectionStart = 0
txtOctober.SelectionLength = txtOctober.Text.Length
e.Cancel = True
Else
e.Cancel = False
End If
End Sub
Private Sub txtSeptember_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtSeptember.Validating
'Validating input for September
If Not IsNumeric(txtSeptember.Text) Then
MessageBox.Show("Must enter a number!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtSeptember.SelectionStart = 0
txtSeptember.SelectionLength = txtSeptember.Text.Length
e.Cancel = True
ElseIf Val(txtSeptember.Text) < 0 Then
MessageBox.Show("Enter a postive number!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtSeptember.SelectionStart = 0
txtSeptember.SelectionLength = txtSeptember.Text.Length
e.Cancel = True
Else
e.Cancel = False
End If
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
'Clear all the text fields
txtJanuary.Clear()
txtFebruary.Clear()
txtMarch.Clear()
txtApril.Clear()
txtMay.Clear()
txtJune.Clear()
txtJuly.Clear()
txtAugust.Clear()
txtSeptember.Clear()
txtOctober.Clear()
txtNovember.Clear()
txtDecember.Clear()
'Clear total and average rainfall labels
lblTotal.Text = ""
lblAverage.Text = ""
'Reset the focus to january
txtJanuary.Focus()
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
'End the application
End
End Sub
End Class
This post has been edited by mustang50187: 24 Jan, 2008 - 07:34 AM