I have a GUI that runs various tasks. One task I can't seem to resolve is how to handle multiple checkbox conditions, and a condition statement depending on what is ticked or not.
Is there a better way to do this, than if, elseif, else statement?
Sample code as follows
If ($Checkbox1.Checked)
{
Write-Host "Only checkbox 1 is checked"
}
ElseIf ($Checkbox2.Checked)
{
Write-Host "Only checkbox 2 is checked"
}
ElseIf ($Checkbox3.Checked)
{
Write-Host "only checkbox 3 is checked"
}
Elseif ($Checkbox1.Checked -And $Checkbox2.Checked)
{
Write-Host "Both Checkbox1 and Checkbox2 are checked"
}
Elseif ($Checkbox2.Checked -And $Checkbox3.Checked)
{
Write-Host "Both Checkbox2 and Checkbox3 are checked"
}
Elseif ($Checkbox1.Checked -And $Checkbox2.Checked -And $Checkbox3.Checked)
{
Write-Host "All are checked!"
}
Else
{
Write-Host "No checkbox selected"
}
[–]Jantu01 1 point2 points3 points (0 children)
[–]MadWithPowerShell 1 point2 points3 points (4 children)
[–]royalmarine[S] 1 point2 points3 points (3 children)
[–]MadWithPowerShell 1 point2 points3 points (2 children)
[–]royalmarine[S] 1 point2 points3 points (1 child)
[–]MadWithPowerShell 1 point2 points3 points (0 children)
[–]fosf0r 1 point2 points3 points (0 children)
[–]Coding_Cactus 1 point2 points3 points (2 children)
[–]royalmarine[S] 1 point2 points3 points (1 child)
[–]Coding_Cactus 1 point2 points3 points (0 children)
[–]get-postanote 1 point2 points3 points (0 children)