I am having a problem with the if statement that I created in my code. The condition should be:
- Select Both Comboboxes (1&2) to print out a text in TextBox1
- If only One Combobox or No Combobox was selected, an error message appears and Nothing is printed in TextBox1.
The code I wrote did not function as I wanted. It prints out a text after I select Combobox1 which isn't the way it should be.
Please advise and thanks in advance.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If ComboBox1.SelectedIndex = -1 Then MessageBox.Show("You Should Select A Name & Age", "Error") ElseIf ComboBox2.SelectedIndex = -1 Then MessageBox.Show("You Should Select A Name & Age", "Error") TextBox1.Text = "Your Age" TextBox1.Text = TextBox1.Text & vbNewLine & "Your Name: " + ComboBox2.Text End If End Sub