[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
Solved

# Flip TRUE/FALSE

Posted on 2014-01-28
Medium Priority
207 Views
Hi,

Generally I use the following to test if something is true/false then flip it, surely there is a one line method which will flip true/false..

If Not ActiveSheet.Shapes("graphblur").Visible Then
ActiveSheet.Shapes("graphblur").Visible = True
Else
ActiveSheet.Shapes("graphblur").Visible = False
End If
0
Question by:DemonForce
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3
• 2

LVL 10

Expert Comment

ID: 39815608
The XOR logical operation can do this.
If you XOR a bit with itself, it will flip.  (if you XOR a BYTE with itself, it will flip all the bits.)

http://msdn.microsoft.com/en-us/library/wz3k228a.aspx

So...

ActiveSheet.Shapes("graphblur").Visible = ActiveSheet.Shapes("graphblur").Visible  Xor ActiveSheet.Shapes("graphblur").Visible
0

LVL 9

Accepted Solution

nick2253 earned 2000 total points
ID: 39815669
The XOR operation with itself will most definitely not flip a bit.

You have to XOR a bit with 1 to flip a bit using XOR.  You can clearly see it from the XOR truth table:
``````1 XOR 1 = 0
1 XOR 0 = 1
``````
(flipping the bit, what you want to achieve)

vs
``````1 XOR 1 = 0
0 XOR 0 = 0
``````
(always makes it 0, what you don't want)

So:
``````ActiveSheet.Shapes("graphblur").Visible = True Xor ActiveSheet.Shapes("graphblur").Visible
``````
0

LVL 10

Expert Comment

ID: 39815703
Gosh,  you are abosultely right nick, one must Xor with 1, rather than itself to flip a value!

(So, what was I thinking about!?   Perhaps the swapping of two variables in memory?
http://c4learn.com/c-programs/swap-two-numbers-without-using-third.html)

0

LVL 49

Expert Comment

ID: 39815741
ActiveSheet.Shapes("graphblur").Visible = Not ActiveSheet.Shapes("graphblur").Visible
0

LVL 10

Expert Comment

ID: 39821688
Face palm (again).
0

LVL 49

Expert Comment

ID: 39821708
Thanks Korbus, now hopefully DemonForce will agree:)
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabilâ€¦
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaacâ€¦
###### Suggested Courses
Course of the Month13 days, 7 hours left to enroll