Solved

Flip TRUE/FALSE

Posted on 2014-01-28
6
199 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 45

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 45

Expert Comment

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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now