Controlling a radio button in PowerShell

I have three switches that I work with. No matter which one I choose, it seems to be the default first. It works in regards to the actual value assignment, but the second switch doesn't work.

if ($radDB1.Checked = $true){
    $database = 'EXDB01_005'
}
if($radDB2.Checked = $true){
    $database = 'EXDB02_005'
}
if ($radDB5.Checked = $true){
    $database = 'EXDB01_005'
}

      

They are placed inside the groupbox that I was trying to access:

switch ($grpEXDatabase)
{
    $radDB1.Checked { $database = 'EXDB01_005' }
    $radDB2.Checked { $database = 'EXDB02_005' }
    $radDB5.Checked { $database = 'EXDB01_005' }
}

      

It didn't work. Does anyone know what's going on with this?

+3


source to share


1 answer


if ($radDB1.Checked -eq $true){
    $database = 'EXDB01_005'
}
if($radDB2.Checked -eq $true){
    $database = 'EXDB02_005'
}
if ($radDB5.Checked -eq $true){
    $database = 'EXDB01_005'
}

      



The problem with your code is that you are using "=" instead of "-eq" in your if statement. The above should work for checking the value. Otherwise, using "=" assigns a value, it is not compared.

+4


source







All Articles