Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.00/5 (1 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 10-Jan-19 23:01pm

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
 
Share this answer
 
Comments
[no name] 11-Jan-19 6:55am    
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.
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
 
Share this answer
 
v3
Comments
[no name] 11-Jan-19 6:37am    
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 11-Jan-19 8:12am    
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900