Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 149,466 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,051 people online right now. Registration is fast and FREE... Join Now!




When I press exit my validating wont allow me to

 
Reply to this topicStart new topic

When I press exit my validating wont allow me to

mustang50187
24 Jan, 2008 - 07:32 AM
Post #1

New D.I.C Head
*

Joined: 18 Jan, 2008
Posts: 21


My Contributions
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
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: When I Press Exit My Validating Wont Allow Me To
24 Jan, 2008 - 07:40 AM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,477



Thanked: 161 times
Dream Kudos: 9025
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
If this is a Windows Form Application put some code in the Closing Event of the form, you can call either of those validating methods like so txtApril_Validating(Nothing,Nothing).

By checking the textbox values in the closing event (this takes place as the form closes), once a single validation fails then display a message to the user.
User is online!Profile CardPM
+Quote Post

mustang50187
RE: When I Press Exit My Validating Wont Allow Me To
24 Jan, 2008 - 07:49 AM
Post #3

New D.I.C Head
*

Joined: 18 Jan, 2008
Posts: 21


My Contributions
QUOTE(PsychoCoder @ 24 Jan, 2008 - 08:40 AM) *

If this is a Windows Form Application put some code in the Closing Event of the form, you can call either of those validating methods like so txtApril_Validating(Nothing,Nothing).

By checking the textbox values in the closing event (this takes place as the form closes), once a single validation fails then display a message to the user.


Thanks ill give that a try.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 02:14PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month