I need someone with more experience then me, a relative newcomer on the subject of scope. I needed a form box and saw one here at this Poweshell Link and the code says to do this:
$OKButton = New-Object System.Windows.Forms.Button $OKButton.Location = New-Object System.Drawing.Size(75,120) $OKButton.Size = New-Object System.Drawing.Size(75,23) $OKButton.Text = "OK" $OKButton.Add_Click({$Senior_Options_CSV = $objTextBox.Text;$Senior_Directory = $objTextBox1.Text;$objForm.Close()}) $objForm.Controls.Add($OKButton)
Well for some time I could not get this form to work. Finally someone at StackOverflow pointed me in the right direction. There was a scope issue. The $x variable(Changed in my code) had a local scope relative to the OKButton object creation. I had to do a kludge of:
#Kludge workaround because there is some sort of scope problem with the script.$Senior_Options_CSV = $objTextBox.Text
$Senior_Directory = $objTextBox1.Text
later down in the script to get the values input from the User assigned to $Senior_Options_CSV & $Senior_Directory variables so I could then use them in the script. I was hoping if someone can explain to me if this was an error in the post or how does one implement the click event handler so you can use variables in your program globally. Thanks...
- Edited by AlanK87 8 hours 56 minutes ago Formating