• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

VBA value check not working for .Fill.Transparency in PowerPoint 2013

This is weird and driving me nuts.

If I open PowerPoint and add a rectangle to a slide, set its transparency to 10% via the PowerPoint UI (Format Shape pane) and then do this in the VBE immediate window while the shape is selected:

?ActiveWindow.Selection.ShapeRange(1).Fill.Transparency
 0.1 

Open in new window


I see the expected result of 0.1

But what is going on here?

?ActiveWindow.Selection.ShapeRange(1).Fill.Transparency=0.1
False

Open in new window


The transparency property returns a value of type Single so I tried these:

?ActiveWindow.Selection.ShapeRange(1).Fill.Transparency=0.1!
False
?ActiveWindow.Selection.ShapeRange(1).Fill.Transparency=CSng(0.1)
False

Open in new window


And weirdly this works:
?Val(ActiveWindow.Selection.ShapeRange(1).Fill.Transparency)=0.1
True

Open in new window


I then tried this:
?ActiveWindow.Selection.ShapeRange(1).Fill.Transparency*100000
 1000000.23841858 

Open in new window


So why is 10% not equal to 0.1?
0
Jamie Garroch
Asked:
Jamie Garroch
2 Solutions
 
Dale FyeCommented:
because that value is stored as double precision, which tends to contain rounding errors.

Keep in mind, that all number (including decimals) are represented as 0's and 1's.  I've never really understood how the decimals are handled but Access does not store the value of 0.1, it stores a binary representation of that number.  Whenever I need to compare two numbers, one of which is a decimal, I usually do something like:

?Abs(ActiveWindow.Selection.ShapeRange(1).Fill.Transparency - 0.1) < 0.0001
0
 
Rgonzo1971Commented:
Or
?ActiveWindow.Selection.ShapeRange(1).Fill.Transparency-cdec(.1)=0
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now