Loop

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.
Locked
llopes
Posts: 2
Meble kuchenne na zamówienie - na wymiar - Wrocław
Joined: Fri Apr 24, 2020 3:19 am

Loop

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.

Example:

$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: 7343
Joined: Tue May 29, 2007 4:43 pm

Re: Loop

Post by Alexander Riedel »

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

jvierra
Posts: 14358
Joined: Tue May 22, 2007 9:57 am
Contact:

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.

viewtopic.php?f=21&t=14715

llopes
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

Locked