I have a powershell winform that has a lot of text boxes, but for the sake of this post, lets say I have 5. I want to loop through the 5 text boxes to see if their text property is empty. If the textbox contains something, I want to add the text value to an array. Here's an example of what I'm trying to do.
textbox1.text = "Red"
textbox2.text = ""
textbox3.text = "Blue"
textbox4.text = ""
textbox5.text = ""
$MyArray = @()
for ($i = 1; $i -le 5; $i++) {
If ($textbox[$i].text -ne "") {
$MyArray += $textbox[$i].text
}
}I realize the textbox object is not an array so this code will not work. I guess the simple question is, How can I reference a set of static controls using a variable without having to do something like this
[object[]]$textboxes = New-Object System.Windows.Forms.TextBox
For ($i = 1; $i -lt 5; $i++) {
$textboxes += New-Object windows.forms.textbox
$textboxes[$i].DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
$textboxes[$i].Name = $textboxes[$i]
$BoxItems.Controls.Add($textboxes[$i])
}