PowerShell - Form button click unsets variable outside the closing brackets -


i trying make blackjack game in powershell sole purpose learn language.

not i've started testing forms (to select hit/stand) , found following issue in form test file:

[system.reflection.assembly]::loadwithpartialname("system.windows.forms") | out-null  $form = new-object system.windows.forms.form $form.text = "debug." $form.autoscroll = $true $form.autosize = $true $form.autosizemode = "growandshrink" $form.backcolor = "red" # $form.icon = [system.drawing.icon]::extractassociatedicon("c:\scripts\private\svtserv.ico") ### commented out because other people don't have file. $form.minimizebox = $false $form.maximizebox = $false $form.windowstate = "normal" $form.sizegripstyle = "hide" $form.showintaskbar = $false $form.opacity = 0.7 $form.startposition = "centerscreen" $label = new-object system.windows.forms.label $label.text = "debug, trigger: @null." $label.autosize = $true $form.controls.add($label)   $hbutton = new-object system.windows.forms.button $hbutton.location = new-object system.drawing.size(75,120) $hbutton.size = new-object system.drawing.size(75,23) $hbutton.text = "debug1" $hbutton.add_click({ $x = "data.debug.1" write-host $x - test1. $form.close() write-host $x - test2. } ) write-host $x - test3. $form.controls.add($hbutton)  $sbutton = new-object system.windows.forms.button $sbutton.location = new-object system.drawing.size(150,120) $sbutton.size = new-object system.drawing.size(75,23) $sbutton.text = "debug2" $sbutton.add_click({ $x = "data.debug.2" write-host $x - test1. $form.close() write-host $x - test2. } ) $form.controls.add($sbutton)  $form.showdialog() | out-null write-host $x - test4.     

hitting debug1 button returns following output:

 - test3. data.debug.1 - test1. data.debug.1 - test2.  - test4. 

what trying here set variable $x , re-use later on, need use @ section writes output test4.

other usefull information might powershell version:

ps c:\windows\system32\windowspowershell\v1.0> write-host $psversiontable.psversion  major  minor  build  revision -----  -----  -----  -------- 4      0      -1     -1       

you can make $x global variable - replace instances of $x $global:x.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -