Jump to content



Photo

Set Boolean to opposite in VB


  • Please log in to reply
5 replies to this topic

#1 t_r_nelson

t_r_nelson

    Neowinian Senior

  • Joined: 01-September 05
  • Location: Minneapolis, US

Posted 05 March 2007 - 03:21

I am fairly new to VB.Net so please bear with me.

I have a situation where a Sub turns things on or off depending on a boolean passed into it. I would like to pass the boolean and use it to set visible (and readonly) properties of controls.

Lets assume valueBoolean = True. Some I want turned on (*.visible = valueBoolean). But there are some in the same Sub that I want turned off (*.visible = THEOPPOSITEOFvalueBoolean). I wanted to use <> (*.visible <> valueBoolean), but that isn't allowed.

I created a simple function called switchBoolean that does this. It finds the value of valueBoolean and returns the opposite (*.visible = switchBoolean(valueBoolean)). This works fine, but is there another way to do this that doesn't need a function call?

Thanks for the help.


#2 xcopmanx

xcopmanx

    Crazy Animal

  • Joined: 16-September 04
  • Location: USA

Posted 05 March 2007 - 03:33

Okay, I don't know VB, but I know Java and C++. You could use it like this.. (*.visible != valueBoolean). So instead of "is equal to", it is "is not equal to".

#3 OP t_r_nelson

t_r_nelson

    Neowinian Senior

  • Joined: 01-September 05
  • Location: Minneapolis, US

Posted 05 March 2007 - 04:23

Thanks for the post, but in VB, <> is the closest to != in C++ that I can find. From what I can see, setting a boolean to <> does not set a TRUE to FALSE or vice-versa. Booleans must be True or False. It would make sense if it is TRUE, then != TRUE would be FALSE, but it doesn't work that way. Any other sugestions?

#4 GSDragoon

GSDragoon

    Neowinian

  • Joined: 15-July 03
  • Location: Ohio, USA
  • OS: Windows 8.1
  • Phone: Lumia 822

Posted 05 March 2007 - 04:35

Not(valueBoolean) should work, right?

#5 OP t_r_nelson

t_r_nelson

    Neowinian Senior

  • Joined: 01-September 05
  • Location: Minneapolis, US

Posted 05 March 2007 - 13:35

I'll give that a try.

#6 LRoling

LRoling

    .NET Developer

  • Joined: 06-August 03
  • Location: Bloomington, IL

Posted 06 March 2007 - 19:40

Dragoon was correct.

Try a simple test:

Dim test As Boolean
Dim tester As Boolean

test = True
tester = Not (test)

Works fine, good luck on your program.



Click here to login or here to register to remove this ad, it's free!