Changing True/False Values

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear All,

Firstly, I hope this is the correct place to post this question.

I have a form which will be used to print labels. There are only 2 labels
which are needed, and the second is a sub-set of the first. I have designed
the form for the first, with the idea of hiding/disabling the controls which
will not be used.

As the value of true = -1 I would have thought that I could have done
something like this:

TextBox1.Enabled *= -1

Therefore the everytime the combo changed from label 1 to label 2 the
controls would disable and re-enable.

However, this doesn't seem to be the case. I would appreciate if someone
could let me know why this isn't the case.

Thank you in advance,

Mike Swann
 
MikeSwann said:
Dear All,

Firstly, I hope this is the correct place to post this question.

I have a form which will be used to print labels. There are only 2 labels
which are needed, and the second is a sub-set of the first. I have
designed
the form for the first, with the idea of hiding/disabling the controls
which
will not be used.

As the value of true = -1 I would have thought that I could have done
something like this:

TextBox1.Enabled *= -1

Boolean is a distinct type and does not hold integers. You would need casts
to even compile that line.

Furthermore, I think (short)True is now 1 to be consistent with most other
languages.

Lastly, , you've assumed that of -1 and 1, one is the value True and the
other is not. However when casting an integer to Boolean zero translates to
False and all other values to True, i.e. by

bool = (int != 0);

What you want is just TextBox1.Enabled = !TextBox1.Enabled, or
TextBox1.Enabled ^= True. (since xor true is the same operation as unary
not)
 
Mike,
Ultimately, most computers test for true/false by testing for
non-zero/zero (there is usually a single machine instruction for this test).
So, false is normally zero, and true is anything else.
Bob
 
Because -1 is not false. .NET, unlike VB 6, forces explicit conversion (not
completely true, as some old school VBers forced MS's hands to allow some of
the implicit garbage to sneak in, but it is primarily true).

The alternative, although type heavy, is not that bad perf wise:

If someValue = -1 Then\
TextBox1.Enabled = False
Else
TextBox1.Enabled = True
End If

--
Gregory A. Beamer

*************************************************
Think Outside the Box!
*************************************************
 
Back
Top