Solved

Flip TRUE/FALSE

Posted on 2014-01-28
6
202 Views
Last Modified: 2014-02-01
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
Comment
Question by:DemonForce
  • 3
  • 2
6 Comments
 
LVL 10

Expert Comment

by:Korbus
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

by:
nick2253 earned 500 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

Open in new window

(flipping the bit, what you want to achieve)

vs
1 XOR 1 = 0
0 XOR 0 = 0

Open in new window

(always makes it 0, what you don't want)

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

Open in new window

0
 
LVL 10

Expert Comment

by:Korbus
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)


Sorry about that!
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 46

Expert Comment

by:Martin Liss
ID: 39815741
ActiveSheet.Shapes("graphblur").Visible = Not ActiveSheet.Shapes("graphblur").Visible
0
 
LVL 10

Expert Comment

by:Korbus
ID: 39821688
Face palm (again).
Martin's answer is the best.
0
 
LVL 46

Expert Comment

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question