I'm rather new to Powershell Studio, so I'm not sure if this is a case of me doing something wrong, or just a nuance of the program. The end goal of what I am trying to do is to create a simple "Wizard-Style" gui, with back and next buttons. Clicking either button will set a variable, and in a loop, the next form will open based on that variable set. The issue I'm running into, I believe is with scoping but am unsure.
I've declared the needed variables as script-scoped (Also tried Global-scoped as a test and it didn't work...) in the default Globals.ps1 file that comes with the form project. Then in the forms load and button click events, I'm attempting to set them. Using debug mode and breakpoints I'm seeing that the variables aren't actually being set. Code snippets are below, and I've also attached a simplified test project showing the issue. In this exmaple, TESTVAR is always set to "start" and never changes off of it.
If anyone has ideas on what to try, or point me in the right direction, I'd appreciate it!
Globals.ps1:
- #--------------------------------------------
- # Declare Global Variables and Functions here
- #--------------------------------------------
- $script:TESTVAR = $null
- $script:EXIT = $null
- $form1_Load={
- #TODO: Initialize Form Controls here
- $script:TESTVAR = "load"
- }
- $buttonOK_Click={
- #TODO: Place custom script here
- $script:TESTVAR = "button"
- }
- $TESTVAR = "start"
- while ($EXIT -ne $true) {
- Show-MainForm_psf
- Write-Output $TESTVAR
- If ($TESTVAR -eq "button") {
- $EXIT = $true
- }
- }