Public Class Form1
    Dim a As Boolean = False
    Dim b As Boolean = True
    Public nume() As String
    Public prenume() As String
    Public telefon() As String
    Public email() As String
    Public index As Integer = 0

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        b = True
        If (TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "") And CheckedListBox1.GetItemChecked(0) = True And CheckedListBox1.GetItemChecked(1) = True Then
            MsgBox("Unul sau mai multe campuri nu sunt completate!", 48)
            b = False

            If (TextBox1.Text = "") Then
                TextBox1.BackColor = Color.Red
            End If

            If (TextBox2.Text = "") Then
                TextBox2.BackColor = Color.Red
            End If

            If (TextBox3.Text = "") Then
                TextBox3.BackColor = Color.Red
            End If

            If (TextBox4.Text = "") Then
                TextBox4.BackColor = Color.Red
            End If
        ElseIf (TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox4.Text = "") And CheckedListBox1.GetItemChecked(0) = False And CheckedListBox1.GetItemChecked(1) = True Then
            MsgBox("Unul sau mai multe campuri nu sunt completate!", 48)
            b = False

            If (TextBox1.Text = "") Then
                TextBox1.BackColor = Color.Red
            End If

            If (TextBox2.Text = "") Then
                TextBox2.BackColor = Color.Red
            End If

            If (TextBox4.Text = "") Then
                TextBox4.BackColor = Color.Red
            End If
        ElseIf (TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "") And CheckedListBox1.GetItemChecked(0) = True And CheckedListBox1.GetItemChecked(1) = False Then
            MsgBox("Unul sau mai multe campuri nu sunt completate!", 48)
            b = False

            If (TextBox1.Text = "") Then
                TextBox1.BackColor = Color.Red
            End If

            If (TextBox2.Text = "") Then
                TextBox2.BackColor = Color.Red
            End If

            If (TextBox3.Text = "") Then
                TextBox3.BackColor = Color.Red
            End If

        ElseIf (TextBox1.Text = "" Or TextBox2.Text = "") And CheckedListBox1.GetItemChecked(0) = False And CheckedListBox1.GetItemChecked(1) = False Then
            MsgBox("Unul sau mai multe campuri nu sunt completate!", 48)
            b = False

            If (TextBox1.Text = "") Then
                TextBox1.BackColor = Color.Red
            End If

            If (TextBox2.Text = "") Then
                TextBox2.BackColor = Color.Red
            End If

        Else

            For i = 0 To Len(TextBox1.Text) - 1
                If Not (Asc(UCase(TextBox1.Text.Chars(i))) >= 65 Or Asc(UCase(TextBox1.Text.Chars(i))) <= 90) Then
                    MsgBox("Campul nume trebuie sa contina doar caractere!", 48)
                    b = False
                    Exit For
                End If
            Next

            For i = 0 To Len(TextBox2.Text) - 1
                If Not (Asc(UCase(TextBox2.Text.Chars(i))) >= 65 And Asc(UCase(TextBox2.Text.Chars(i))) <= 90) Then
                    MsgBox("Campul prenume trebuie sa contina doar caractere!", 48)
                    b = False
                    Exit For
                End If
            Next

            For i = 0 To Len(TextBox3.Text) - 1
                If CheckedListBox1.GetItemChecked(0) = True And (Not IsNumeric(TextBox3.Text.Chars(i)) Or Len(TextBox3.Text) <> 10) Then

                    MsgBox("Campul telefon trebuie sa contina doar 10 cifre!", 48)
                    b = False

                    Exit For
                End If
            Next

            If CheckedListBox1.GetItemChecked(1) = True And (InStrRev(TextBox4.Text, ".") = 0 Or InStrRev(TextBox4.Text, "@") = 0) Then
                MsgBox("Campul e-mail trebuie sa contina caracterele . si @!", 48)
                b = False
            End If

            If b = True Then
                nume = New String() {TextBox1.Text}
                prenume = New String() {TextBox2.Text}
                telefon = New String() {TextBox3.Text}
                email = New String() {TextBox4.Text}
                index = nume.Length - 1

                Form2.ComboBox1.Items.Add(nume(index))
                Form2.ComboBox2.Items.Add(prenume(index))
                Form2.ComboBox3.Items.Add(telefon(index))
                Form2.ComboBox4.Items.Add(email(index))

                Form2.ComboBox1.Text = nume(index)
                Form2.ComboBox2.Text = prenume(index)
                Form2.ComboBox3.Text = telefon(index)
                Form2.ComboBox4.Text = email(index)

                Form2.ShowDialog()
            End If
        End If
    End Sub

    Private Sub textbox1_GotFocus(ByVal sender As Object, ByVal e As EventArgs) Handles TextBox1.GotFocus
        TextBox1.SelectionStart = 0
        TextBox1.SelectionLength = Len(TextBox1.Text)
        Label1.ForeColor = Color.Blue
        Label2.ForeColor = Color.Black
        Label3.ForeColor = Color.Black
        Label4.ForeColor = Color.Black
    End Sub

    Private Sub textbox2_GotFocus(ByVal sender As Object, ByVal e As EventArgs) Handles TextBox2.GotFocus
        TextBox2.SelectionStart = 0
        TextBox2.SelectionLength = Len(TextBox2.Text)
        Label2.ForeColor = Color.Blue
        Label1.ForeColor = Color.Black
        Label3.ForeColor = Color.Black
        Label4.ForeColor = Color.Black
    End Sub

    Private Sub textbox3_GotFocus(ByVal sender As Object, ByVal e As EventArgs) Handles TextBox3.GotFocus
        TextBox3.SelectionStart = 0
        TextBox3.SelectionLength = Len(TextBox3.Text)
        Label3.ForeColor = Color.Blue
        Label1.ForeColor = Color.Black
        Label2.ForeColor = Color.Black
        Label4.ForeColor = Color.Black
    End Sub

    Private Sub textbox4_GotFocus(ByVal sender As Object, ByVal e As EventArgs) Handles TextBox4.GotFocus
        TextBox4.SelectionStart = 0
        TextBox4.SelectionLength = Len(TextBox4.Text)
        Label4.ForeColor = Color.Blue
        Label1.ForeColor = Color.Black
        Label2.ForeColor = Color.Black
        Label3.ForeColor = Color.Black
    End Sub

    Private Sub textbox4_LostFocus(ByVal sender As Object, ByVal e As EventArgs) Handles TextBox4.LostFocus
        Label1.ForeColor = Color.Black
        Label2.ForeColor = Color.Black
        Label3.ForeColor = Color.Black
        Label4.ForeColor = Color.Black
    End Sub

    Private Sub Form1_Keydown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyCode = Keys.Return Then
            Button1.PerformClick()
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label1.ForeColor = Color.Blue
        KeyPreview = True
        Label3.Enabled = False
        Label4.Enabled = False
        TextBox3.Enabled = False
        TextBox4.Enabled = False
    End Sub

    Private Sub CheckedListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckedListBox1.SelectedIndexChanged

        If CheckedListBox1.GetItemChecked(0) = True Then
            Label3.Enabled = True
            TextBox3.Enabled = True
        End If

        If CheckedListBox1.GetItemChecked(1) = True Then
            Label4.Enabled = True
            TextBox4.Enabled = True
        End If
        If CheckedListBox1.GetItemChecked(0) = False Then
            Label3.Enabled = False
            TextBox3.Enabled = False
        End If

        If CheckedListBox1.GetItemChecked(1) = False Then
            Label4.Enabled = False
            TextBox4.Enabled = False
        End If
    End Sub

End Class