how can I store this in a variable named ptotal?

ptotal = Double.Parse(Me.txtt1.Text) + Double.Parse(Me.txtt2.Text) + Double.Parse(Me.txtt3.Text) + _
                         Double.Parse(Me.txtt4.Text) + Double.Parse(Me.txtt5.Text) + Double.Parse(Me.txtt6.Text) + _
                         Double.Parse(Me.txtt7.Text) + Double.Parse(Me.txtt8.Text) + Double.Parse(Me.txtt9.Text) + _
                         Double.Parse(Me.txtt10.Text) + Double.Parse(Me.txtt11.Text) + Double.Parse(Me.txtt12.Text) + _
                         Double.Parse(Me.txtt13.Text) + Double.Parse(Me.txtt14.Text) + Double.Parse(Me.txtt15.Text) + _
                         Double.Parse(Me.txtt16.Text) + Double.Parse(Me.txtt17.Text) + Double.Parse(Me.txtt18.Text) + _
                         Double.Parse(Me.txtt19.Text) + Double.Parse(Me.txtt20.Text) + Double.Parse(Me.txtt21.Text) + _
                         Double.Parse(Me.txtt22.Text) + Double.Parse(Me.txtt23.Text) + Double.Parse(Me.txtt24.Text) + _
                         Double.Parse(Me.txtt25.Text) + Double.Parse(Me.txtt26.Text) + Double.Parse(Me.txtt27.Text) + _
                         Double.Parse(Me.txtt28.Text) + Double.Parse(Me.txtt29.Text) + Double.Parse(Me.txtt30.Text) + _
                         Double.Parse(Me.txtt31.Text) + Double.Parse(Me.txtt32.Text) + Double.Parse(Me.txtt33.Text) + _
                         Double.Parse(Me.txtt34.Text) + Double.Parse(Me.txtt35.Text) + Double.Parse(Me.txtt36.Text) + _
                         Double.Parse(Me.txtt37.Text) + Double.Parse(Me.txtt38.Text) + Double.Parse(Me.txtt39.Text) + _
                         Double.Parse(Me.txtt40.Text) + Double.Parse(Me.txtt41.Text) + Double.Parse(Me.txtt42.Text) + _
                         Double.Parse(Me.txtt43.Text) + Double.Parse(Me.txtt44.Text) + Double.Parse(Me.txtt45.Text) + _
                         Double.Parse(Me.txtt46.Text) + Double.Parse(Me.txtt47.Text) + Double.Parse(Me.txtt48.Text) + _
                         Double.Parse(Me.txtt49.Text) + Double.Parse(Me.txtt50.Text)

If you put all of the textboxes inside a container such as a panel or GroupBox you could simplify like

Dim ptotal As Double = 0.0

For Each tbx As TextBox in GroupBox.Controls.OfType(Of TextBox)()
    ptotal += Double.Parse(tbx.Text)
Next

But you should ensure that the textboxes contain valid data first.

Good day Jim, is it possible if all of my textbox is not in the panel or groupbox?

Can I use:

Dim ptotal As Double = 0.0
For Each tbx As TextBox in Form1.Controls.OfType(Of TextBox)()
    ptotal += Double.Parse(tbx.Text)
Next

??

You can do that as long as there are no other textboxes in the same container. If there are then you have to have some way of determining which textboxes are the ones that you are interested in. One simple way to do this is to put a value in the TextBox.Tag property that you can test inside the loop.

Since the names are consistent you could use the contains methods, If tbx.Name.Contains("txtt") Then

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.