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.
This topic is 3 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
llopes
Posts: 2
Last visit: Mon Jul 06, 2020 5:49 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: 8488
Last visit: Tue Apr 16, 2024 8:42 am
Answers: 20
Been upvoted: 37 times

Re: Loop

Post by Alexander Riedel »

[Topic moved by moderator]
Alexander Riedel
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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.

viewtopic.php?f=21&t=14715
llopes
Posts: 2
Last visit: Mon Jul 06, 2020 5:49 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
This topic is 3 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked