inline shape gettop method

W

William Hite

I have an inline shape right aligned. When I try to find the top using the
gettop method property it is nonsense - typical value -8247.829 points.

If I move the shape out of the text flow, i.e. not inline any longer, I get
the real value.

Is this by design or a bug? Is there any workround that does not involve
switching the shapes in and out of the textflow when I need to find their
"tops"? There are too many and it is too slow for my application.

Why do I need to do it - another bug/feature in the next posting to do with
overflow.
 
E

Ed Bennett

A small child turns to Ed, and exclaims: "Look! Look! A post from
William Hite said:
I have an inline shape right aligned. When I try to find the top
using the gettop method property it is nonsense - typical value
-8247.829 points.

Could you tell me how you get the reference to an inline shape?
In my copy of Publisher 2003, shapes no longer appear in the
Pages(x).Shapes() collection when they have been made inline through the UI.
 
W

William Hite

someOuterShape.TextFrame.TextRange.InlineShapes

gives you the collection of inline shapes in someOuterShape.
 
E

Ed Bennett

A small child turns to Ed, and exclaims: "Look! Look! A post from
William Hite said:
someOuterShape.TextFrame.TextRange.InlineShapes

Cool - I hadn't seen that before (shows how large the Publisher OM is
compared to the amount of Publisher dev I do)

I have now tested this and can't reproduce.

Steps I took:
- Create a new blank publication.
- Create a text box and insert some placeholder text
- Insert a random picture file from my machine, drag it over the text
- Set the layout to be inline, and right-aligned (not Move With Text)
- Switch to the VBA IDE (Alt-F11)
- Create a new module
- Create a new sub
- Insert the following line of code MsgBox
ActiveDocument.Pages(1).Shapes(1).TextFrame.TextRange.InlineShapes.Item(1).GetTop(pbUnitPoint)
- Execute the sub from the Immediate window.
- The MsgBox returns a value of about 286 points

What steps are you taking? Can you reproduce this for all new publications
on your machine?
Have you applied the SP1 patch to Publisher?
 
W

William Hite

Hi Ed - I too have been experimenting hard this afternoon. So far I cannot
reproduce the effect on documents created in the UI using Publisher VBA.

My application has 3 levels of "text boxes" the topmost one (level 1) is
chained over a number of pages. Level 2 is inline to that and starts as one
box but is duplicated many times by code. When the duplication is finished
the original is deleted.

Within level 2 is a level 3 box, this is duplicated many times by code
within each level 2 as the level 2 duplication continues. Again the original
is deleted once it has been duplicated. (Think property (house), with any
number of floors with any number of rooms within each floor).

Within each level there is fixed and variable text and an arbitrary number
of empty picture frames and tables. As the duplication of the original boxes
continues these are filled in appropriately by code. Once all the boxes are
populated I adjust the height of the level 2 and 3 boxes to accommodate the
text and other contained objects, starting from the inside out. I seem to be
getting this getheight error on the items within level 3 but maybe at other
levels too.

I will work on simplifying and extracting the code for doing all this so it
can be seen to fail in a simple document.

Oh, and perhaps importantly, it is all being driven through automation from
a standalone VB6 application. (Not possible to change that either)

Having written all the above, I have a sneaky suspicion, all of a sudden,
that it is to do with a text box that is not visible because it has
"overflowed" - into its own overflow area rather than a linked box. When this
happens it may be that the "top" of a contained object is truly undefined if
it itself is oveflowed off the invisible text box, IYSWIM.

But anyway - this whole "gettop" problem is a side issue to kludge around
the real problem. My real problem is that the overflow indicator is not set
properly if a textrame within a text box contains an inline shape,
right-aligned, deeper than the text in the box - see posting one after this
thread. You can prove that one all in the UI - no coding needed. If that
worked Ok I wouldn't have to be computing the maximum depth of these enclosed
objects...

Thansk anway

William
 
W

William Hite

And I should have said in my other reply that the reason I can get at these
invisible(because overflowed) frames and other objects is that I am creating
them in ocde and hanging on to the objects as I do so. It seems problematic
getting at them when you resize a frame in the UI and overflow the innermost
boxes out of sight.
 
W

William Hite

Ok - I am now able to reproduce this bug:

1 create a Single A4 page blank pub
2 insert an empty text box 24.7cm(h) by 16 cm(w) centred on the page (B1)
3 insert text box 15h x 13w (B2)
4 make B2 inline and place inside B1.
5 type text "This is several words of some demonstration text for Box 2"
into B2, set to 24 point
6 insert an empty text box 7h x 11w (B3)
7 make B3 inline and place inside B2 at end of the text
8 type text "This is several words of some demonstration text for Box 3"
into B3, set to 24 point
9 insert an empty picture frame 5 x 5 (P1)
10 make inline, place inside B3 before the first word
11 make P1 right aligned and set fill colour to grey

[11A Note here the other bug - drag the bottom edge of box B3 up so it half
obscures P1. the overflow indicator is not set, nor would you find it set in
code]

12 open the VB editor and insert the following code

Sub testboxtop()
Dim loThisShape(3) As Publisher.Shape
Dim loDupedShape As Publisher.Shape
With Pages(1)
Set loThisShape(1) = .Shapes(1)
With loThisShape(1)
.Name = "B1"
'.Select
Set loThisShape(2) = .TextFrame.TextRange.InlineShapes(1)
With loThisShape(2)
.Name = "B2"
'.Select
Set loThisShape(3) = .TextFrame.TextRange.InlineShapes(1)

.Height = .Height / 2

With loThisShape(3)
.Name = "B3"
.TextFrame.TextRange.InlineShapes(1).Name = "P1"
Set loDupedShape = .Duplicate
'loDupedShape.Select
.Delete
End With

With loDupedShape
'.Select
Debug.Print "after duplication before resizing B2"

Debug.Print "REF0: box B3 position", .GetTop(pbUnitCM),
..GetHeight(pbUnitCM), .GetLeft(pbUnitCM), .GetWidth(pbUnitCM)
With .TextFrame.TextRange.InlineShapes(1)
'.Select

Debug.Print "REF1: shape P1 position",
..GetTop(pbUnitCM), .GetHeight(pbUnitCM), .GetLeft(pbUnitCM),
..GetWidth(pbUnitCM)
End With
End With

.Height = .Height * 2

With loDupedShape
'.Select
Debug.Print "after duplication after resizing B2 up"

Debug.Print "REF2: box B3 position", .GetTop(pbUnitCM),
..GetHeight(pbUnitCM), .GetLeft(pbUnitCM), .GetWidth(pbUnitCM)
With .TextFrame.TextRange.InlineShapes(1)
'.Select

Debug.Print "REF3: shape P1 position",
..GetTop(pbUnitCM), .GetHeight(pbUnitCM), .GetLeft(pbUnitCM),
..GetWidth(pbUnitCM)
End With
End With

.Height = .Height / 2

With loDupedShape
'.Select
Debug.Print "after duplication after resizing B2 back down -
should be same as REF0,1"

Debug.Print "REF4: box B3 position ", .GetTop(pbUnitCM),
..GetHeight(pbUnitCM), .GetLeft(pbUnitCM), .GetWidth(pbUnitCM)
With .TextFrame.TextRange.InlineShapes(1)
'.Select

Debug.Print "REF5: shape P1 position ",
..GetTop(pbUnitCM), .GetHeight(pbUnitCM), .GetLeft(pbUnitCM),
..GetWidth(pbUnitCM)
End With
End With

.Height = .Height * 2

With loDupedShape
'.Select
Debug.Print "after duplication after resizing B2 back up
again - should be same as REF2,3"

Debug.Print "REF6: B3 position ", .GetTop(pbUnitCM),
..GetHeight(pbUnitCM), .GetLeft(pbUnitCM), .GetWidth(pbUnitCM)
With .TextFrame.TextRange.InlineShapes(1)
'.Select

Debug.Print "REF7: shape P1 position ",
..GetTop(pbUnitCM), .GetHeight(pbUnitCM), .GetLeft(pbUnitCM),
..GetWidth(pbUnitCM)
End With
End With

End With
End With
End With

End Sub

13 open the immediate window to view the debug output
14 save the publication to allow rework this at leisure!
15 adjust windows to see both the code and the publication
16 run the code and view the debug output

Results

Note the spurious image of the duplicated text box (B3) that remains half
into the scratch area.

The Top and Left positions of B3 immediately after it is duplicated as in
the immediate window under REF0 are wrong. Not only are they wrong but are
totally inconsistent with the position and left of shape P1 as in REF1. All
these should be the same as those found in REFs 2 and 3.

Note also how the shape P1 positions do remain correct despite the B£
positions being spasmodically wrong.

It is not enough to say "resize the outer box first..." because what I am
trying to do is overcome the bug noted in point 11A and to do that I need to
know the true bottom extent of B2...

What do you think I should do next to make sure MS is aware of these bugs?

William Hite
 
E

Ed Bennett

A small child turns to Ed, and exclaims: "Look! Look! A post from
William Hite said:
Ok - I am now able to reproduce this bug:

Interesting - I get values in the -291cm range, which seems typical compared
to your previous posts.

One thing I noticed was that B3 refused to go into B2 and remain visible -
it "hid" under the text. This also happened inserting B2 into B1, but I
overcame it by setting the align to Right rather than Move With Text.

This is very weird - I'll get back to you.
 
W

William Hite

Weird? Certainly a bug. It is an impossibility that the box B3 should have a
top of -291cm, be, as it is, 7 cm high and yet have a shape P1.top of 10 or
so whatever it is.

I have submitted it to MS via a support incident (as a bug report) and it
has been "handed to the developers".

Thanks for looking anyway.

What do you think of the fact that raising the lower edge of B2 does not set
the overflow flag? Bug? Feature?

Yours

William Hite
http://www.searchfavorites.com
Office Automation Consultant and Developer
 
W

William Hite

Hi Ed

When I run the listed code, having created the publication as specified, I
get:

after duplication before resizing B2
REF0: box B3 position -291.0984 6.798681 -295.4318
11.25192
REF1: shape P1 position 15.99998 5 16.74998 5
after duplication after resizing B2 up
REF2: box B3 position 4.851586 6.798681 2.968256
11.25192
REF3: shape P1 position 5.899997 5 9.06666 5
after duplication after resizing B2 back down - should be same as REF0,1
REF4: box B3 position -291.0984 6.798681 -295.4318
11.25192
REF5: shape P1 position 5.899997 5 9.06666 5
after duplication after resizing B2 back up again - should be same as REF2,3
REF6: B3 position 4.851586 6.798681 2.968256
11.25192
REF7: shape P1 position 5.899997 5 9.06666 5

Which contains several impossibilities.

As you had issues creating the test document from my instructions I have
emailed it to you.

Thanks for help so far. And remember - all I really need is a solution to
the problem of the overflow flag not being set! This is a side issue to
resolve a bug in a kludge for that problem...

William Hite
http://www.searchfavorites.com
Office Automation Consultant and Developer
 
E

Ed Bennett

A small child turns to Ed, and exclaims: "Look! Look! A post from
William Hite said:
When I run the listed code, having created the publication as
specified, I get:

I get the same.

Now, rereading your posts and doing some experimenting myself, it definitely
seems a problem with the shape going into the overflow area. As you say, it
does make sense that .GetTop would not return any sensible value if the
shape is in the overflow area. I would say that the thing should return an
error, but as there are no errors defined it just returns a nonsensical
value instead.

I'm now wondering (as you are) how Publisher can give a top value for a
shape that's not on screen. Especially when it's not the same as it would
be if the container shape were on screen. Could it be that it is the same
as the distance from the top of the container shape? Or is it some
arbitrary value that's returned regardless of the location of P1?

Out of interest, how often do you use three layers of in-line objects?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top