Click here to Skip to main content
13,828,588 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
How can I call next form after sucessfully check all textboxes? I have a problem with call next form after sucussfully check all textboxes all textboxes if they are in the tolerance. can you help me?

What I have tried:

Private Sub FINAL_KONTROLA(sender As Object, e As EventArgs)
    Dim EmptyTextBoxFound As Boolean = False 'Boolean flag for empty textbox 
    Dim EmptyTextBoxName As String = ""
    Dim max_x As Double = max_tolerance.Text
    Dim min_x As Double = min_tolerance.Text

    For Each ctl As Control In Panel1.Controls
        If TypeOf ctl Is TextBox AndAlso ctl.Visible Then
            Dim v1 As Double = ctl.Text
            If v1 >= max_x OrElse v1 <= min_x Then

                EmptyTextBoxName = ctl.Name
                EmptyTextBoxFound = True
                ctl.Select()
                ctl.Text = ""
                ctl.BackColor = Color.LightSalmon
                MsgBox("Vyznačený záznam neodpovída tolerančnímu poli",, "Chyba")
                Exit For
                If EmptyTextBoxFound = True Then
                    ctl.BackColor = Color.Red
                    '.. do whatever you have do
                End If
            End If
        End If
    Next
End Sub
Posted
Updated 4 days ago
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Replace your Exit For with Return when you find a "bad value".
After the For ... Next loop, open the new form:
Dim mnf As MyNewForm = New MyNewForm()
mnf.ShowDialog()
Or
Dim mnf As MyNewForm = New MyNewForm()
mnf.Show()
depending on what you need it to do.

BTW: It's a much better idea to check TextBoxes for Double values using TryParse:
Dim d As Double

If Not Double.TryParse(myTextBox.Text, d) Then
    MessageBox.Show("""{0}"" is not a valid number.", myTextBox.Text)
    Return
End If
   
Comments
Fiínek Cahů 4 days ago
   
Textboxes are double. I replace exit for with return but if all is ok then my code end on first if - If v1 > max_x OrElse v1 < min_x Then.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

I think you should remove the Exit For.
To call another Form:
If EmptyTextBoxFound = False Then
    Dim form2 As New Form2()
    form2.Show()
End If
   
v3
Comments
Fiínek Cahů 4 days ago
   
This is a problem, because if all is ok then my code end on first if - If v1 > max_x OrElse v1 < min_x Then
RickZeeland 4 days ago
   
Not when you remove the Exit For !

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web06 | 2.8.190114.1 | Last Updated 11 Jan 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100