Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Posts: 2
Joined: Fri Apr 24, 2020 3:19 am


Post by llopes »

Hello everybody,

I've a little problem with a loop and I can't find a solution. If someone can help me I appreciate.

I'm trying to do a loop with a "while" or a "foreach" to put values in text boxes.
My problem is, if I put (textbox1.Text = "Some text"), my textbox1 take the text "Some text". It's what I need. I have multiple textboxes and I want to use a variable to replace the number of my textbox like "$textbox$number" but this one doesn't work.


$index = 1
while($index -lt 5)
$textbox$index.Text = "this is textbox $index"
$index = $index + 1

Can someone help's me please.

Sorry for my english

User avatar
Alexander Riedel
Posts: 7558
Joined: Tue May 29, 2007 4:43 pm
Answers: 2
Been upvoted: 4 times

Re: Loop

Post by Alexander Riedel »

[Topic moved by moderator]
Alexander Riedel
SAPIEN Technologies, Inc.

Posts: 14668
Joined: Tue May 22, 2007 9:57 am
Answers: 5
Has voted: 1 time
Been upvoted: 5 times

Re: Loop

Post by jvierra »

First, textboxes do not have numbers. You have to assign each one by name.

Here is a thread that will help you understand ways to accommodate this.


Posts: 2
Joined: Fri Apr 24, 2020 3:19 am

Re: Loop

Post by llopes »

Hi jvierra,

I will try your solution.
Maybe I can do something based on the example you gave me.

Thank you