Hi,

I have to create two forms. In the mainFrm the user enters all his personal data (name, phone, email, address), and a label to display amount due. One of the buttons takes the user to a second form. In the secondFrm , I have two CheckBoxes, one is for the registration fee, and I have a list with the workshop's name and fee.

The secondFrm has to be displayed in a modal form. I have done all of the above and I got no errors. However, I do not know how to do the Input Validation. The user cannot register for the optional workshop without selecting the conference registration.

I know it has to be and IF statement with the And logical operator.

If IsNumeric(Me.chkConfReg.Text) And (Me.lstWorkshops)???

Also, does the input validation has to go in the Public class?

Thank you

Ok first, what numeric value are you attempting to check for and what value in lstWorkships (listbox?) are you trying to get? I thought you mentioned this was a checkbox but your checking for a text value and seeing if it has a numeric value within it, so im a bit confused.

Also there are many ways of passing values between forms (public properties, public/global variables etc), I dont want to suggest something not specific to where your at in class. Can you provide your two forms?

I was rereading your original post, again its a bit confusing since you mention two checkboxes but them mention something about a list (listbox?) also your checking for text and numeric values that have nothing to do with checkboxes.

But going by the assumption that your only checking to see if two check boxes were checked on a second form, here is an example.

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim frm As New Form2
        frm.ShowDialog()

        If frm.CheckBox1.Checked = True And frm.CheckBox2.Checked = True Then
            MessageBox.Show("Both checkboxes were checked")
        Else
            MessageBox.Show("Both checkboxes were not checked")
        End If

        frm.Dispose()

    End Sub

End Class

Hi Tom: The user cannot register for the optional workshops w/o first selecting the conference registration of $895.00. In the Frmmain the user only enters personal data and has three buttons: Reset and Exit (done that), and a third button 'Select Conference Options'.

Once the user clicks this button , it takes the user to the second form which I named 'Conference options'. In this form I have two checkboxes: chkConf.Reg ( conference registration), and chk.OpeningNight.Dinner, plus the lstWorkshops. In addition, I have the Reset and Close button.

Public Class frmMain

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

        Me.Close()

    End Sub

    Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click

        'Reset the fields in the form.
        txtName.Clear()
        txtPhone.Clear()
        txtCompany.Clear()
        txtEmail.Clear()
        txtAddress.Clear()
        txtCity.Clear()
        txtState.Clear()
        txtZip.Clear()

    End Sub

    Private Sub btnConference_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConference.Click
        Dim optionForm As New frmConference_Options

        'Show the other form in modal style.
        frmConference_Options.ShowDialog()

    End Sub
End Class

Now, the amount due has to be displayed on a label in the main form. Since the user has to register for the Conference Registration
the validation should go into the this ckeckbox, isn't?
Since I am a newbie and this is my first program with two forms, I am at lost.

Thank you

My above example should show you how to determine if the two checkboxes were selected; just replace the checkbox names with the names of your checkboxes. What information do you need returned from the listbox (the selected item text, selected index, a hidden value member value)? Also is the listbox set to allow more then one item to be selected at a time? Can you provide an example of the data/items filled in the listbox?

Validation should be done (when possibile) in a single location. Such as if a user is still clicking options (ie checkboxes) this may not be the best spot to do it rather then when he clicks an Ok/Save type button you can check all validation at once. This can be done on either form, frmMain or your options form. I would probably do it when they clicked the OK button that closes the options form this way if they do need to select something else that dont have to re-open the form. Two reasons that I can think of you may not want to do this though, first I dont know what else the form may used for; for example is selecting a different class neccesarily wrong in all cases of using this form and second is simply that you may be required to show that all this info can be passed back to the main form, in which case I would do as soon as the form is closed but before it is disposed, such as where I have the IF statement in the first example.

As my example points out, I would always suggest using the Form.Dispose method after calling a dialog/modal form. Forms do take up resources and it is best to free those resources when possible. The disposable method is not available when using the regular show method but is available when you use ShowDialog.

I dont know where your getting this value $895. I dont see it as something that is being cleared in your Reset sub. Do you need help with how to display this?

Tom,

Sorry for the late reply, but I am having problems with the first program I submitted. Could you please help me with this problem. I started a new tread named: Else statement. This program is due tomorrow.

Thank you

Okay. The second form it has only two buttons: Reset and Close. When the user clicks the Close button this form should be removed ( Modal mode); this part is working.

The workshop list has the following info:
Workshop Fee
Introduction to E-Commerce $295
The Future of the Web $295
Advanced Visual Basic $395
Network Security $395

The user cannot register for the optional workshop w/o selecting the conference registration. Maybe I am wrong, but since the total amount due has to be displayed in the label in the Mainform, the validation and the calculations has to be done in the Close button.

Thank you

Either way you need to pass the info back to the main form... I dont know where your getting the value of $895 from or how your calculating it but the below example shows how to pass the selected listbox item back to the main form.

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim frm As New Form2
        Dim strListItem As String = ""

        Me.Visible = False
        frm.ShowDialog()

        If frm.CheckBox1.Checked = True And frm.CheckBox2.Checked = True Then
            MessageBox.Show("Both checkboxes were checked")

            If frm.ListBox1.SelectedIndex > -1 Then
                strListItem = frm.ListBox1.SelectedItem.ToString
                Messagebox.Show(strListItem)
            End If
        Else
            MessageBox.Show("Both checkboxes were not checked")
        End If

        frm.Dispose()

    End Sub

End Class

Thank you. Please disregard the Else thread, I solved it.
FYI: the $895.00 is the cost of the registration.

This article has been dead for over six months. Start a new discussion instead.