0

i've made a wimdowsform with checkboxes in powershell.

i use switch command to make check/uncheck. it works like i want. If we check a checkbox i add a variable but it's still empty.

...
$checkbox_un.Add_CheckStateChanged(
{
switch ($checkbox_un.Checked) {
    $false { $checkbox_deux.enabled=$true; $checkbox_deux.Checked=$False; break }
    $true { $checkbox_deux.Enabled=$False; $checkbox_deux.Checked=$False; $fs="FAT32"; break }
    }

})
$checkbox_deux.Add_CheckStateChanged(
{
switch ($checkbox_deux.Checked) {
    $false { $checkbox_un.Enabled=$true; $checkbox_un.Checked=$False; break }
    $true { $checkbox_un.Enabled=$false; $checkbox_un.Checked=$false; $fs="NTFS"; break }
    }

})
...

$fs returns always empty , i don't understand why ?

kramer
  • 177
  • 1
  • 4
  • 15
  • 1
    you only set the `$fs` variable in the `$True` branch of each of the two switches. you likely otta set and such $Var in all the possible code paths. – Lee_Dailey Mar 30 '19 at 18:53
  • Assigning to `$fs` in your event handlers creates a _local_ variable that goes out of scope with your event handlers - see the linked post for an explanation. – mklement0 Mar 30 '19 at 23:47
  • ok thanks . it'll work if i assign a global variable – kramer Mar 30 '19 at 23:53

0 Answers0