|
-
Feb 6th, 2000, 12:23 PM
#7
Clarification. In Visual Basic, True has a value of -1 and False has a value of 0. check your reference books if you don't want to believe me.
Remember that a checkbox has 3 states, none of them directly correlating to True or False. The Value property of the checkbox can be:
vbUnChecked - which is 0 (which happens to also be the value for False)
vbChecked - which is 1
vbGrayed - which is 2
if all you care about is finding out whether the checkbox has a check in it, meaning it's in either a checked or grayed state, then the following would work:
IIf(Check1, True, False)
if the checkbox(named Check1) value is 1(vbChecked which is not the value of True or vbGrayed which has a value of 2) then Check1(without the .Value) will return True. If Check1 has no check and is not in the grayed state then Check1 returns False.
This is kind of confusing to explain, my point is that don't confuse True/False(-1/0) values with the possible values for the state of a Checkbox.
You can set the .Value property of a checkbox to vbUnchecked which is equal to zero or False because the value of False is also zero. You cannot set the .Value property of a checkbox to True because there are two true possibilities, vbChecked and vbGrayed(both are checked) and VB won't pick one of them for you. VB returns True if there is any check in the checkbox because it knows that the value is not zero. If zero is False then not zero is True.
so in answer to the original post, this would work:
Private Sub Check1_Click()
If Check1 Then
txtbox1.Enabled = True
Else
txtbox1.Enabled = False
End If
End Sub
this is kind of a quirky vb thing, but you cannot test to see if check1 or check1.value is equal to true. that would be like testing to see if the value of check1 is equal to -1 which is not a possible value for the Value property of a checkbox. take out the assignment operator(=), now vb is not concerned with the actual possible values for the the value property, vb is concerned with 0(False) and not 0(True).
[This message has been edited by pvb (edited 02-06-2000).]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|