简体   繁体   中英

Debug.Print shows me a value, but 'If not' wouldn't work with this value

I am totally baffled. Can't find a solution. I ask for the value of a shape:

? ActiveWindow.Selection.ShapeRange.TextFrame.MarginBottom

Answer: 11.29354

I write a routine:

If Not oshp.TextFrame.MarginBottom = 11.29354 Then
    TellMe = "MarginBottom =" & oshp.TextFrame.MarginBottom & " but not 11.29354" 
End If

The routine won't work. I claims the shape's MarginBottom has not the value, but in the same moment it gives me the value as a result.

That would mean the value is not the value. Any experienced guy has background info on this?

It could be rounding, you can test in the immediate window thus:

First assign the value:

ActiveWindow.Selection.ShapeRange.TextFrame.MarginBottom = 11.23456789

Then retrieve it:

? ActiveWindow.Selection.ShapeRange.TextFrame.MarginBottom
 11.23457 

It's changed, test it against the new value and the assigned value:

? ActiveWindow.Selection.ShapeRange.TextFrame.MarginBottom = 11.23456789
False
? ActiveWindow.Selection.ShapeRange.TextFrame.MarginBottom = 11.23457
False

Neither works, convert to string and test:

? CStr(ActiveWindow.Selection.ShapeRange.TextFrame.MarginBottom) = "11.23457"
True

I don't know if you're able to test on a string value, but this comparison will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM