Help: Can't use "Not"???

  • Thread starter Thread starter VB Programmer
  • Start date Start date
V

VB Programmer

I want to set the enabled property of a text box based on if a checkbox is
checked or not. This works....

txtPort.Enabled = ckDefaultPort.Checked;

But, I want the enabled property to be the opposite of the checked value.
Why doesn't this work?

txtPort.Enabled = Not ckDefaultPort.Checked;

It keeps telling my "; expected".

Thanks.
 
You're not using VB, so you can't use Visual Basic syntax.

try:
txtPort.Enabled = !ckDefaultPort.Checked;
or

txtPort.Enabled = (ckDefaultPort.Checked == false);
 
VB Programmer said:
txtPort.Enabled = Not ckDefaultPort.Checked;
It keeps telling my "; expected".

Well, you can't write VB code in C#.

txtPort.Enabled = !ckDefaultPort.Checked;

P.
 
In C# there is no Not, you have to use "!" operator:

txtPort.Enabled = !ckDefaultPort.Checked;
 
Back
Top