Hello
I'm new to this forum and quite new to visual basic. I started editing an existing code (basicaly to learn vb) without any real previou experience. Well let's get to the point; I have a form that gathers data from db ordering by user ID (on click count). I have one DataGridView with a list of user, some have data in db, some have not. I came so far that if I CLICK on a user that have data, all data is dissplayed in 6 dinamyc textboxes. If user has no data inly first (emty) row with 6 dinamyc textboxes is created.
Than I have a button that simultaneously adds a row of dinamyc textboxes bellow and multiplyies textbox04 (name is clickcount & 4) and textbox05 and displays the result in textbox06.
Now I got stucked; I want to add a messagebox that shows if textbox04 & 05 are empty and in that case exits sub. Here is my code so far:

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

        'Reset warnings
        lblNotifyPrint.Text = ""
        lblNotifySave.Text = ""
        lblNotifyStorno.Text = ""

        Dim yPosition As Integer
        Dim num As Integer

        If ClickCount = 0 Then

            yPosition = 480
            ReDim TextBoxes(5)
            Dim TextBoxWidth As Integer = 0
            Dim TextboxX As Integer = 0

            For TextBox = 0 To TextBoxes.Count() - 1

                num += 1
                TextBoxes(num - 1) = New MyTextBox()

                Select Case TextBox
                    'V.P
                    Case 0
                        TextBoxWidth = 89
                        TextboxX = 5

                        'Opis stroška
                    Case 1
                        TextBoxWidth = 177
                        TextboxX = 99

                        'Konto
                    Case 2
                        TextBoxWidth = 60
                        TextboxX = 281

                        'Količina
                    Case 3
                        TextBoxWidth = 60
                        TextboxX = 346

                        'Cena
                    Case 4
                        TextBoxWidth = 60
                        TextboxX = 411

                        'Znesek
                    Case 5
                        TextBoxWidth = 89
                        TextboxX = 476

                End Select
                With TextBoxes(num - 1)
                    .Name = "Textbox" & ClickCount & num
                    .Size = New Size(TextBoxWidth, 22)
                    .Text = "Textbox" & ClickCount & num
                    .Location = New System.Drawing.Point(TextboxX, yPosition)
                End With

                Me.Controls.AddRange(New System.Windows.Forms.Control() {TextBoxes(num - 1)})
            Next

        Else
            ReDim TextBoxes(5)
            Dim TextBoxWidth As Integer = 0
            Dim TextboxX As Integer = 0

            yPosition = 450 + (30 * ClickCount)

            For TextBox = 0 To TextBoxes.Count() - 1

                num += 1
                TextBoxes(num - 1) = New MyTextBox()

                Select Case TextBox
                    'V.P
                    Case 0
                        TextBoxWidth = 89
                        TextboxX = 5

                        'Opis stroška
                    Case 1
                        TextBoxWidth = 177
                        TextboxX = 99

                        'Konto
                    Case 2
                        TextBoxWidth = 60
                        TextboxX = 281

                        'Količina
                    Case 3
                        TextBoxWidth = 60
                        TextboxX = 346

                        'Cena
                    Case 4
                        TextBoxWidth = 60
                        TextboxX = 411

                        'Količina
                    Case 5
                        TextBoxWidth = 89
                        TextboxX = 476

                End Select

                With TextBoxes(num - 1)
                    .Name = "Textbox" & ClickCount & num
                    .Size = New Size(TextBoxWidth, 22)
                    .Location = New System.Drawing.Point(TextboxX, yPosition)
                End With

                Me.Controls.AddRange(New System.Windows.Forms.Control() {TextBoxes(num - 1)})
            Next

        End If

        Dim Kolicina As Decimal
        Dim Cena As Decimal

        If ClickCount = 0 Then

            For Each ctrl As Control In Me.Controls


                If TypeOf ctrl Is TextBox And ctrl.Name = "Textbox" & ClickCount & 4 Then
                    Kolicina = ctrl.Text
                End If

                If TypeOf ctrl Is TextBox And ctrl.Name = "Textbox" & ClickCount & 5 Then
                    Cena = ctrl.Text
                End If

                If TypeOf ctrl Is TextBox And ctrl.Name = "Textbox" & ClickCount & 6 Then
                    ctrl.Text = Kolicina * Cena
                End If

            Next
        Else

            For Each ctrl As Control In Me.Controls

                If TypeOf ctrl Is TextBox And ctrl.Name = "Textbox" & ClickCount - 1 & 4 Then
                    Kolicina = ctrl.Text
                End If

                If TypeOf ctrl Is TextBox And ctrl.Name = "Textbox" & ClickCount - 1 & 5 Then
                    Cena = ctrl.Text
                End If

                If TypeOf ctrl Is TextBox And ctrl.Name = "Textbox" & ClickCount - 1 & 6 Then
                    ctrl.Text = Kolicina * Cena
                End If

            Next

        End If

        For Each ctrl As Control In Me.Controls

            If TypeOf ctrl Is TextBox And ctrl.Name = "Textbox" & ClickCount - 1 & 6 Then
                ctrl.Enabled = False
                ctrl.BackColor = Color.White


            End If

        Next

        Button1.Location = New Point(571, yPosition)

        Me.Height = Me.Height + 30
        ButtonPregled.Location = New Point(ButtonPregled.Location.X, ButtonPregled.Location.Y + 30)
        PictureBox1.Location = New Point(PictureBox1.Location.X, PictureBox1.Location.Y + 30)
        ButtonIzhod.Location = New Point(ButtonIzhod.Location.X, ButtonIzhod.Location.Y + 30)
        ButtonTiskanje.Location = New Point(ButtonTiskanje.Location.X, ButtonTiskanje.Location.Y + 30)
        PictureBox3.Location = New Point(PictureBox3.Location.X, PictureBox3.Location.Y + 30)
        lblNotifySave.Location = New Point(lblNotifySave.Location.X, lblNotifySave.Location.Y + 30)
        lblNotifyPrint.Location = New Point(lblNotifyPrint.Location.X, lblNotifyPrint.Location.Y + 30)
        lblNotifyStorno.Location = New Point(lblNotifyStorno.Location.X, lblNotifyStorno.Location.Y + 30)

        ClickCount += 1

    End Sub

Problem solved; this is my code if anyone finds it helpful...

Dim Kolicina As Decimal
        Dim Cena As Decimal

        If ClickCount >= 1 Then

            For Each ctrl As Control In Me.Controls

                For i = 1 To ClickCount
                    If TypeOf ctrl Is TextBox And ctrl.Name = "Textbox" & i - 1 & 4 Then
                        If ctrl.Text = Nothing Then
                            MessageBox.Show("Vnesi količino!")
                            Exit Sub
                        End If
                        Kolicina = ctrl.Text
                    End If

                    If TypeOf ctrl Is TextBox And ctrl.Name = "Textbox" & i - 1 & 5 Then
                        If ctrl.Text = Nothing Then
                            MessageBox.Show("Vnesi ceno!")
                            Exit Sub
                        End If
                        Cena = ctrl.Text
                    End If

                    If TypeOf ctrl Is TextBox And ctrl.Name = "Textbox" & i - 1 & 6 Then
                        ctrl.Text = Kolicina * Cena
                    End If



                    If TypeOf ctrl Is TextBox And ctrl.Name = "Textbox" & i - 1 & 1 Then
                        If ctrl.Text = Nothing Then
                            MessageBox.Show("Vnesi V.P!")
                            Exit Sub
                        End If
                    End If


                    If TypeOf ctrl Is TextBox And ctrl.Name = "Textbox" & i - 1 & 2 Then
                        If ctrl.Text = Nothing Then
                            MessageBox.Show("Vnesi opis stroška!")
                            Exit Sub
                        End If
                    End If

                    If TypeOf ctrl Is TextBox And ctrl.Name = "Textbox" & i - 1 & 3 Then
                        If ctrl.Text = Nothing Then
                            MessageBox.Show("Vnesi konto!")
                            Exit Sub
                        End If
                    End If


                Next
            Next
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.