.net – Boolean variables and three-state CheckBoxes: How best to do type conversion

vb.netvb6

This is in VB6 (may also apply to VB.net)

CheckBoxes can have three states (Checked, Unchecked, Greyed).

But I'm using them to set boolean variables (MuteSound, etc.) This is definitely a value that has only two states. Unfortunately, the Checked and Unchecked don't correspond to a True/False value.

So, I can't have:

bMuteSound=ChkMute.value
……….
If bMuteSound then blah blah

Two options:
1. Force the value when setting/reading the Checkbox.value to be boolean:

bMuteSound=Checkbox.value=Checked
…..

Checkbox.value=ConvertBooleanToCheckBox

Best Solution

bMuteSound = abs(chkMute.Value)  
chkMute.Value = abs(bMuteSound)
Related Question