I have a question is there a way t write the following in a shorter way because i have to write this all about another 25 times. there is always one difference with one of all the textboxes.

  ' zonder roepnaam en zonder tussenvoegsel, wel vader maar vader geen tussenvoegsel, wel moeder maar moeder geen tussenvoegsel, en geen getuigen en geen loco , en geen opmerkingen
                    If TextBox32.Text = "" And TextBox3.Text = "" And TextBox11.Text = "" And TextBox12.Text = "" And TextBox13.Text = "" And TextBox14.Text = "" And TextBox15.Text = "" And TextBox16.Text = "" And TextBox18.Text = "" And TextBox19.Text = "" And TextBox20.Text = "" And TextBox18.Text = "" Then
                        Dim texta As String = Label3.Text + vbCrLf + Label5.Text + vbCrLf + Label11.Text + vbCrLf + Label6.Text + vbCrLf + Label7.Text + vbCrLf + Label8.Text + vbCrLf + Label9.Text + vbCrLf + Label10.Text
                        Dim texta1 As String = TextBox2.Text + vbCrLf + TextBox4.Text + vbCrLf + TextBox5.Text + vbCrLf + TextBox6.Text + vbCrLf + TextBox7.Text + vbCrLf + TextBox8.Text + vbCrLf + TextBox9.Text + vbCrLf + TextBox10.Text

                        e.Graphics.DrawString(texta, font, Brushes.Black, 100, CInt(newHeight) + 70)
                        e.Graphics.DrawString(texta1, font, Brushes.Black, 250, CInt(newHeight) + 70)
                    End If

                    'wel roepnaam, geen tussenvoegsel, geen vader geen moeder geen getuigen, geen opmerkingen.
                    If TextBox32.Text <> "" And TextBox3.Text = "" And TextBox11.Text = "" And TextBox12.Text = "" And TextBox13.Text = "" And TextBox14.Text = "" And TextBox15.Text = "" And TextBox16.Text = "" And TextBox18.Text = "" And TextBox19.Text = "" And TextBox20.Text = "" And TextBox18.Text = "" Then
                        Dim texta As String = Label3.Text + vbCrLf + Label31.Text + vbCrLf + Label5.Text + vbCrLf + Label11.Text + vbCrLf + Label6.Text + vbCrLf + Label7.Text + vbCrLf + Label8.Text + vbCrLf + Label9.Text + vbCrLf + Label10.Text
                        Dim texta1 As String = TextBox2.Text + vbCrLf + TextBox32.Text + vbCrLf + TextBox4.Text + vbCrLf + TextBox5.Text + vbCrLf + TextBox6.Text + vbCrLf + TextBox7.Text + vbCrLf + TextBox8.Text + vbCrLf + TextBox9.Text + vbCrLf + TextBox10.Text

                        e.Graphics.DrawString(texta, font, Brushes.Black, 100, CInt(newHeight) + 70)
                        e.Graphics.DrawString(texta1, font, Brushes.Black, 250, CInt(newHeight) + 70)
                    End If

                    'geen roepnaam, wel tussenvoegsel, geen vader geen moeder geen getuigen, geen opmerkingen.
                    If TextBox32.Text = "" And TextBox3.Text <> "" And TextBox11.Text = "" And TextBox12.Text = "" And TextBox13.Text = "" And TextBox14.Text = "" And TextBox15.Text = "" And TextBox16.Text = "" And TextBox18.Text = "" And TextBox19.Text = "" And TextBox20.Text = "" And TextBox18.Text = "" Then
                        Dim texta As String = "" + Label3.Text + vbCrLf + Label4.Text + vbCrLf + Label5.Text + vbCrLf + Label11.Text + vbCrLf + Label6.Text + vbCrLf + Label7.Text + vbCrLf + Label8.Text + vbCrLf + Label9.Text + vbCrLf + Label10.Text + ""
                        Dim texta1 As String = "" + TextBox2.Text + vbCrLf + TextBox3.Text + vbCrLf + TextBox4.Text + vbCrLf + TextBox5.Text + vbCrLf + TextBox6.Text + vbCrLf + TextBox7.Text + vbCrLf + TextBox8.Text + vbCrLf + TextBox9.Text + vbCrLf + TextBox10.Text + ""

                        e.Graphics.DrawString(texta, font, Brushes.Black, 100, CInt(newHeight) + 70)
                        e.Graphics.DrawString(texta1, font, Brushes.Black, 250, CInt(newHeight) + 70)
                    End If

                    'geen roepnaam, geen tussenvoegsel, vader geen voornaam en geen tussenvoegsel wel achternaam,  geen moeder geen getuigen, geen opmerkingen.
                    If TextBox32.Text = "" And TextBox3.Text = "" And TextBox11.Text = "" And TextBox12.Text = "" And TextBox13.Text <> "" And TextBox14.Text = "" And TextBox15.Text = "" And TextBox16.Text = "" And TextBox18.Text = "" And TextBox19.Text = "" And TextBox20.Text = "" And TextBox18.Text = "" Then
                        Dim texta As String = "" + Label3.Text + vbCrLf + Label5.Text + vbCrLf + Label11.Text + vbCrLf + Label6.Text + vbCrLf + Label7.Text + vbCrLf + Label8.Text + vbCrLf + Label9.Text + vbCrLf + Label10.Text + vbCrLf + Label14.Text + ""
                        Dim texta1 As String = "" + TextBox2.Text + vbCrLf + TextBox4.Text + vbCrLf + TextBox5.Text + vbCrLf + TextBox6.Text + vbCrLf + TextBox7.Text + vbCrLf + TextBox8.Text + vbCrLf + TextBox9.Text + vbCrLf + TextBox10.Text + vbCrLf + TextBox13.Text + ""

                        e.Graphics.DrawString(texta, font, Brushes.Black, 100, CInt(newHeight) + 70)
                        e.Graphics.DrawString(texta1, font, Brushes.Black, 250, CInt(newHeight) + 70)
                    End If

                    'geen roepnaam, wel tussenvoegsel, vader geen voornaam en wel tussenvoegsel wel achternaam,  geen moeder geen getuigen, geen opmerkingen.
                    If TextBox32.Text = "" And TextBox3.Text <> "" And TextBox11.Text = "" And TextBox12.Text <> "" And TextBox13.Text <> "" And TextBox14.Text = "" And TextBox15.Text = "" And TextBox16.Text = "" And TextBox18.Text = "" And TextBox19.Text = "" And TextBox20.Text = "" And TextBox18.Text = "" Then
                        Dim texta As String = "" + Label3.Text + vbCrLf + Label4.Text + vbCrLf + Label5.Text + vbCrLf + Label11.Text + vbCrLf + Label6.Text + vbCrLf + Label7.Text + vbCrLf + Label8.Text + vbCrLf + Label9.Text + vbCrLf + Label10.Text + vbCrLf + Label13.Text + vbCrLf + Label14.Text + ""
                        Dim texta1 As String = "" + TextBox2.Text + vbCrLf + TextBox3.Text + vbCrLf + TextBox4.Text + vbCrLf + TextBox5.Text + vbCrLf + TextBox6.Text + vbCrLf + TextBox7.Text + vbCrLf + TextBox8.Text + vbCrLf + TextBox9.Text + vbCrLf + TextBox10.Text + vbCrLf + TextBox12.Text + vbCrLf + TextBox13.Text + ""

                        e.Graphics.DrawString(texta, font, Brushes.Black, 100, CInt(newHeight) + 70)
                        e.Graphics.DrawString(texta1, font, Brushes.Black, 250, CInt(newHeight) + 70)
                    End If

                    'geen roepnaam, wel tussenvoegsel, vader wel voornaam en wel tussenvoegsel wel achternaam,  geen moeder geen getuigen, geen opmerkingen.
                    If TextBox32.Text = "" And TextBox3.Text <> "" And TextBox11.Text <> "" And TextBox12.Text <> "" And TextBox13.Text <> "" And TextBox14.Text = "" And TextBox15.Text = "" And TextBox16.Text = "" And TextBox18.Text = "" And TextBox19.Text = "" And TextBox20.Text = "" And TextBox18.Text = "" Then
                        Dim texta As String = "" + Label3.Text + vbCrLf + Label4.Text + vbCrLf + Label5.Text + vbCrLf + Label11.Text + vbCrLf + Label6.Text + vbCrLf + Label7.Text + vbCrLf + Label8.Text + vbCrLf + Label9.Text + vbCrLf + Label10.Text + vbCrLf + Label12.Text + vbCrLf + Label13.Text + vbCrLf + Label14.Text + ""
                        Dim texta1 As String = "" + TextBox2.Text + vbCrLf + TextBox3.Text + vbCrLf + TextBox4.Text + vbCrLf + TextBox5.Text + vbCrLf + TextBox6.Text + vbCrLf + TextBox7.Text + vbCrLf + TextBox8.Text + vbCrLf + TextBox9.Text + vbCrLf + TextBox10.Text + vbCrLf + TextBox11.Text + vbCrLf + TextBox12.Text + vbCrLf + TextBox13.Text + ""

                        e.Graphics.DrawString(texta, font, Brushes.Black, 100, CInt(newHeight) + 70)
                        e.Graphics.DrawString(texta1, font, Brushes.Black, 250, CInt(newHeight) + 70)
                    End If

                    'wel roepnaam, wel tussenvoegsel, vader wel voornaam en wel tussenvoegsel wel achternaam,  geen moeder geen getuigen, geen opmerkingen.
                    If TextBox32.Text <> "" And TextBox3.Text <> "" And TextBox11.Text <> "" And TextBox12.Text <> "" And TextBox13.Text <> "" And TextBox14.Text = "" And TextBox15.Text = "" And TextBox16.Text = "" And TextBox18.Text = "" And TextBox19.Text = "" And TextBox20.Text = "" And TextBox18.Text = "" Then
                        Dim texta As String = "" + Label3.Text + vbCrLf + Label31.Text + vbCrLf + Label4.Text + vbCrLf + Label5.Text + vbCrLf + Label11.Text + vbCrLf + Label6.Text + vbCrLf + Label7.Text + vbCrLf + Label8.Text + vbCrLf + Label9.Text + vbCrLf + Label10.Text + vbCrLf + Label12.Text + vbCrLf + Label13.Text + vbCrLf + Label14.Text + ""
                        Dim texta1 As String = "" + TextBox2.Text + vbCrLf + TextBox32.Text + vbCrLf + TextBox3.Text + vbCrLf + TextBox4.Text + vbCrLf + TextBox5.Text + vbCrLf + TextBox6.Text + vbCrLf + TextBox7.Text + vbCrLf + TextBox8.Text + vbCrLf + TextBox9.Text + vbCrLf + TextBox10.Text + vbCrLf + TextBox11.Text + vbCrLf + TextBox12.Text + vbCrLf + TextBox13.Text + ""

                        e.Graphics.DrawString(texta, font, Brushes.Black, 100, CInt(newHeight) + 70)
                        e.Graphics.DrawString(texta1, font, Brushes.Black, 250, CInt(newHeight) + 70)
                    End If
                    'wel roepnaam, wel tussenvoegsel, vader geen voornaam en wel tussenvoegsel wel achternaam,  geen moeder geen getuigen, geen opmerkingen.
                    If TextBox32.Text <> "" And TextBox3.Text <> "" And TextBox11.Text = "" And TextBox12.Text <> "" And TextBox13.Text <> "" And TextBox14.Text = "" And TextBox15.Text = "" And TextBox16.Text = "" And TextBox18.Text = "" And TextBox19.Text = "" And TextBox20.Text = "" And TextBox18.Text = "" Then
                        Dim texta As String = "" + Label3.Text + vbCrLf + Label31.Text + vbCrLf + Label4.Text + vbCrLf + Label5.Text + vbCrLf + Label11.Text + vbCrLf + Label6.Text + vbCrLf + Label7.Text + vbCrLf + Label8.Text + vbCrLf + Label9.Text + vbCrLf + Label10.Text + vbCrLf + Label13.Text + vbCrLf + Label14.Text + ""
                        Dim texta1 As String = "" + TextBox2.Text + vbCrLf + TextBox32.Text + vbCrLf + TextBox3.Text + vbCrLf + TextBox4.Text + vbCrLf + TextBox5.Text + vbCrLf + TextBox6.Text + vbCrLf + TextBox7.Text + vbCrLf + TextBox8.Text + vbCrLf + TextBox9.Text + vbCrLf + TextBox10.Text + vbCrLf + TextBox12.Text + vbCrLf + TextBox13.Text + ""

                        e.Graphics.DrawString(texta, font, Brushes.Black, 100, CInt(newHeight) + 70)
                        e.Graphics.DrawString(texta1, font, Brushes.Black, 250, CInt(newHeight) + 70)
                    End If

What is TextBox5, texta1, Label31(see line 65) etc.? Give them meaningful names!!! Like naamVaderTxb or something.
I don't relly get why you have to test if your textboxes are not empty.

i the textboxes where they are not empty to print it on paper.
When a textbox is empty i don't want to ptint it.
I have a form with 29 textboxes and 28 labels before every textbox exept the last one
thats a text box with multiline
the text boxes wil be filled by selected a listview row and come from a datatable.
and some textboxes are empty but it can change on what row is selected in the listview.
so i want to print only the textboxes with text below the image. and the text from the labels on the left.
i added 2 images so you can see what i mean Picture0001.jpgPicture0002.jpg

Edited 6 Months Ago by johnnyd1963

That makes things a bit more clearer. Plus the fact that I understand Dutch very well. He! I'm a native speaker!
Whenever you see some form of repetition, start thinking LOOP.
Almost all programming languages have some form of loop construct just to handle this.
So my suggestion would be:
Turn your Labels and TextBoxes into arrays and loop through them with a for or while loop.
Like this(pseudocode):
Start loop
Test if textbox is not empty -->ok? --> add to texta string
etc.

Now I assume you made your textboxes etc through the designer?
Do you know where VS stores the init code for every TextBox? Usually this is somewhere under Form1.designer.vb in the Solution Explorer window.
VS wrote that code for you and you better leave it as is.
To construct an array of TextBoxes you have to write all this code yourself. So take a backup, copy the 'hidden' Textbox initialisation code, remove all your texboxes in the designer and construct your array. Maybe in the Form Load event. And don't forget to add every textbox to the Controls collection of the form with Me.Controls.Add(Me.TextBox(i))
If all this seems too heavy at first, test it out in a testproject to get a feel of it.
Success! :)

You could also create a List<TextBox> by filtering the Controls collection without any major changes to the code:

Dim textBoxes = New List(Of TextBox)(Me.Controls.OfType(Of TextBox))

If you only want certain textboxes in the collection it's relatively easy to filter the collection even further by giving the textbox names a unique prefix or suffix.

Edited 6 Months Ago by tinstaafl

Comments
Interesting path to follow!

thanks for the help. Hope i can creat it, for only textboxes is not the problem.

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