0

I created 10 textboxes which are entitled Txtb_1, Txtb_2.... and a table with 10 values. For example Dim table() as integer = {0,1,2,3....}

The first 5 textbox will contain a value as an integer. The other 5, the value will be incremented by x.

I want to show on screen the comparison before and after.

All my variables are declared as string for Txtb_1.,Txtb_2 etc.

For the variable Txtb_6 to Txtb_10, is it possible to put them in a for loop and change only the number in the name of the variable?

What i want is to be able to simplify my task.

For example :

for i = 6 to 10

    Txtb_**i**.text = table(x)

next

So the loop will go from Txtb_6 to Txtb_10, reducing the coding.

braX
  • 11,506
  • 5
  • 20
  • 33
Axxell
  • 11
  • 3
    Put your textboxes in an array and then loop over them using the indexer – Steve Nov 22 '17 at 18:12
  • 1
    Please [edit] your question title to something descriptive. You've simply regurgitated information from tags (.net, and there is tag available for vb.net), which is meaningless. Your title should describe a problem or ask a question in a way that will be of use to future readers here who see it in a list of search results. (While you're making that [edit], you can add the vb.net tag and make an effort to format your code. Use the **?** button above the top right corner of the text area for formatting help.) – Ken White Nov 22 '17 at 18:12
  • Ok. I will do that. Its my first post here. So i don`t know how things work here. – Axxell Nov 22 '17 at 20:11

1 Answers1

1

For this you'll be able to use the Control.FindControl function.

Dim curControl As Control = Nothing

For i = 6 To 10
    curControl = FindControl($"Txtb_{i}") 'or string format or &
    If (Not curControl Is Nothing)
        ' your logic
        (curControl As TextBox).Text = table(x) 'prob want to exception handle
    End If
Next

More info here: https://msdn.microsoft.com/en-us/library/486wc64h(v=vs.110).aspx

Ways to cast: https://www.codeproject.com/Articles/5044/Cheat-Sheet-Casting-in-VB-NET-and-C

Poat
  • 327
  • 1
  • 11