I am suppose to display 3 error messages,Premium Channels is a required field,Customer Type is a required field and If a business checkbox is checked an error message is suppose to display saying Business Customers must select 1 or more Connection." can anyone tell me why just the Business Customers must select 1 or more Connections does not display.(the other two does display)

' make a function so all data passed through is valid



    Private Function Data_Validated_ok() As Boolean



        Dim intErrCount As Integer
        Dim strErrMessage As String = String.Empty
        Dim ctrlError As New Collection




        ' make sure Premium channel is selected

        If Me.lstPremium.SelectedIndex < 0 Then
            intErrCount = intErrCount + 1
            strErrMessage &= intErrCount & ". Premium Channels is a required field." _
            & vbCrLf
            ctrlError.Add(lstPremium.SelectedIndex)
        End If
        ' make sure a customer type is selected in the Radioboxes

        If radBusiness.Checked = False And
                    radResidential.Checked = False Then
            intErrCount = intErrCount + 1
            strErrMessage &= intErrCount & ".Customer Type is a required field." _
             & vbCrLf
            ctrlError.Add(radBusiness.Checked, CStr(radResidential.Checked))
        End If

        ' make sure a business customer checks at least one option in the listbox

        If radBusiness.Checked = True And Me.lstConnections.SelectedIndex < 0 Then
            intErrCount = intErrCount + 1
            strErrMessage &= intErrCount & ". Business Customers must select 1 or more Connection." _
            & vbCrLf
            ctrlError.Add(lstConnections.SelectedIndex)
        End If

        'if any errors display a message box with the list of errors
        If intErrCount > 0 Then
            MessageBox.Show(strErrMessage, "Validation Rule(s)", MessageBoxButtons.OK, MessageBoxIcon.Information)



            Return False
        Else
            Return True
        End If

    End Function

vbv

Recommended Answers

All 11 Replies

Can't you just debug it and see. Do you know how to debug and step through code?

The last error message won't display the same time as the second one, because, the second relies on radbusiness.checked being false and the third relies on it being true.

commented: Why formal logic should be a required subject for software developers. +13

I will try to debug and see if that helps. but I know they wont display at the same time but when i check my business checkbox and select 0 from connections it should show up

I can't seem to duplicate the behavior. There must be something else somewhere in your code or property settings that's affecting this.

Thank you for trying

Which error message doesn't display?

mr. m the one that says Business Customers must select 1 or more Connection." _

This should be really easy and to repeat my first reply to this thread, just debug the code and see what is happening.

Have you done this or not? It should be the very first thing you should ever do when something like this doesn't work.

I think the problem is within your IF statement, will try this and hope I will manage to figure out the problem, because there is something I'm suspecting so just want to make sure of it.

Ok, this worked to me, what I think you need to do is that instead of creating lots of IF statements without the ELSE could be the course why you don't receive this error message. Try to add the Else to your code like this:

 If radBusiness.Checked = False And radResidential.Checked = False Then
 REM: Do what you need here
 Else
 If radBusiness.Checked = True And lstConnection.SelectedIndex < 0 Then
 REM: Your current error that you say you don't receive here
 Else
 REM: Continue with your If Statement here, and so on keep applying the Else to a so common items conditions to the end and close all you if statements with End If
 End If
 End If

Please try that and see.

Thank you mr. m that was the fix

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.