3

I have three radio buttons that I am working with. No matter which one I select it seems to default to the first one. It's working in regards to actually assigning a value, but the second radio button doesn't seem to be working.

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 a groupbox, which I tried to access here:

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

This did not work. Anyone know what's going on with this?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Matt
  • 379
  • 7
  • 18

1 Answers1

5
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're using "=" instead of "-eq" in your if statement. The above should work for checking the value. Otherwise using "=" assigns a value, it doesn't compare it.

Jason Snell
  • 1,425
  • 12
  • 22
  • 2
    Since $radDB5.Checked should be a bool, you shouldn't need to type `-eq $true` either. just `if ($radDB1.Checked){}` should work – Sambardo Aug 08 '17 at 21:29
  • @Sambardo true. I just wanted to make sure to point out -eq vs =. It's a really mistake to make. – Jason Snell Aug 08 '17 at 21:48
  • 1
    For sure, it got me a ton when I first started with PS. I just wanted to add that bit on for him, and I figured it fit better as a comment than a separate answer. – Sambardo Aug 09 '17 at 02:26
  • @Sambardo Ended up switching to that. Thanks for the answer! – Matt Aug 09 '17 at 14:27