Question Managing multiple conditions in IF...Then statement

patou316

New member
Joined
Aug 18, 2010
Messages
1
Location
Bromont, Quebec
Programming Experience
Beginner
Hi. I currently have an If...Then statement that checks if all fields of a form have been filled before saving the info in a file. I'd like to be able to tell which field has not been filled to give the user a dynamic message (at the moment, it only tells them that the checklist is not completed ) :

VB.NET:
If ([B][FONT="Arial Black"]txtNoDemande.TextLength = 8 _
    Or txtNoDemande.TextLength = 13 _
    And txtDateLoad.TextLength <> 0 _
    And txtNoDisplay.TextLength <> 0 _
    And chk1.Checked And chkBak.Checked And chkWip.Checked[/FONT][/B]) Then
                If rad1.Checked Then
                    valide = True
                ElseIf rad2.Checked And txtNoMembres.TextLength <> 0 Then
                    valide = True
                End If
End If

If valide Then
            btnSubmit.Enabled = True
            lblMessage.ForeColor = Color.DarkGreen
            lblMessage.Text = "checklist remplie correctement, svp cliquer soumettre"
Else
            btnSubmit.Enabled = False
            lblMessage.ForeColor = Color.DarkRed
            lblMessage.Text = "informations manquantes, svp remplir tous les champs"
End If

Is there a way to determine which of these conditions is false without having to do a seperate If statement for each ?
 
I don't know of any way to determine the status of the conditions without If statements but you can easily provide dynamic messages. Just remove the "valide" variable and place your message at that point.
 
Control.Validating Event (System.Windows.Forms)
See the code sample, you can use the same Validating event handler for multiple controls. With the forms ValidateChildren method all (or some) child controls can be forced to validate, and it also returns the combined result. If you, like in the code sample, use ErrorProvider all controls that doesn't validate will show the error icon and text giving the user the necessary feedback for all controls.
 
Back
Top