Display data field in container

Started by posix86749, February 25, 2014, 01:46:38 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

posix86749

Hi, Visio Guy :)
First of all i want to apologies for English:)
And now my question.
I have shape Container named "cont1" in document.
This container have data field "cont1data1".

And now i want to display this data field in the text of the container: i put formula: cont1!prop.cont1data1. But Visio tells me, that formula is wrong.
at the same time if i try to display this data in text of another shape thru the formula "cont1!prop.cont1data1" - that`s OK, formula is correct.
What wrong?

JohnGoldsmith

Hi,

A couple of questions for you:


       
  • How did you make / insert your container?
  • Where are you trying to use your formula?
Possible problems to look at:


       
  • The universal name for the contained is not "cont1", but something else.  (What you see in the Drawing Explorer is the local name)
  • The Shape Data row name might not be "cont1data1".  (What you see in the Shape Data window is the Shape Data 'Label', which may or may not be the same as the row name, which you need for the formula)
If you use the "Sheet.4!Pr...." syntax, where 4 is the ID of your target shape you can avoid names and seem if that works for you.  If you turn on Developer mode then you can use the 'Shape Name' dialog to see the ID of your shape.

Best regards

John
John Goldsmith - Visio MVP
http://visualsignals.typepad.co.uk/

posix86749

Quote from: JohnGoldsmith on February 25, 2014, 09:52:07 AM
Hi,

A couple of questions for you:


       
  • How did you make / insert your container?
  • Where are you trying to use your formula?
Possible problems to look at:


       
  • The universal name for the contained is not "cont1", but something else.  (What you see in the Drawing Explorer is the local name)
  • The Shape Data row name might not be "cont1data1".  (What you see in the Shape Data window is the Shape Data 'Label', which may or may not be the same as the row name, which you need for the formula)
If you use the "Sheet.4!Pr...." syntax, where 4 is the ID of your target shape you can avoid names and seem if that works for you.  If you turn on Developer mode then you can use the 'Shape Name' dialog to see the ID of your shape.

Best regards

John
Hi. John!.
Thera are the answers:
1. I go to the ''Instert" tab, then in "Scheme part" section i select "Container"

2. I try to insert field: dbl click on container to edit text, then go to "insert" tab, then in "text" section click "field" button:

In opened window I select "Customizable formula":


in the drawing explorer name of my container is "Cont1":

The shape data row name is "cont1data1":



JohnGoldsmith

So that's good.  You're using a standard container and the inserted field dialog correctly.

In that case you need to look at the formula syntax.  I think the problem here is where you can and cannot use shape names within formulae.  I've recreated the container below.  Basically the custom formula you're putting into the field will sit within 'Sheet.4', the header sub-shape (1) and you want to create a reference to the parent, which is named 'Plain' (2) in my case.  However you can only use named references to refer to peers (shapes at the same level in terms of structure), otherwise you have to use 'Sheet.n' syntax.

So, you need to find out what the ID is of your container shape (named 'Cont1').  In the screenshot below I've temporarily used the ID() function (3) in the container shape's ShapeSheet to find out what the ID actually is.  You can quickly switch views for the ShapeSheet from 'Formula' to 'Values' to see the returned number.  Once you know the ID number (1 in my case below)  you can then use it in the inserted field formula (4).

Let me know how you get on.

Best regards

John
John Goldsmith - Visio MVP
http://visualsignals.typepad.co.uk/

posix86749

#4
Ok, John, thank you
The way you offer is work fine.
But what shall we do, in case we have about 100 or more these containers? In ieach cintainer manualy adjust formula "=Sheet.6!Prop.cdata"?
So I suppose to use some variable in this formula, or sub formula. Some thing like this: Sheet.(ID()-3)!Prop.cdata. I use ID()-3 formula, because I`ve noticed, that heading sub container has ID= ID of parent container +3.
But formula Sheet.(ID()-3)!Prop.cdata doesn`t work, it`s causes a mistake.
What can you say about this?

JohnGoldsmith

Great.  Glad that's worked.

For your other containers, the best way would be to try and get the functionality into the container master shape and then Visio will automatically update the ID's in the instance shapes.  It sounds to me like you've already edited the instance shapes and so making changes to the master might not work (as some of the sections in the instances will be local).  You could have a go and see if they are updated.  Another option might be to write a little bit of code to loop through your container shapes and make the changes as required.  Or, a third option might be a combination - update the container master and then replace all of the container instances (so that you have properly inheriting shapes).

Using the ID function within parentheses is a good idea but unfortunately not valid syntax.  You could do it by pushing the formula in with a SETF function, but a) you relying on the id to be a consistent offset and b) this is really going against what Visio will do for you anyway if the functionality is placed correctly in the master.

The image below is not recommended - it's just an interesting problem.

Best regards

John
John Goldsmith - Visio MVP
http://visualsignals.typepad.co.uk/

posix86749

Ok,
Using SETF function within formula works fine. But I understand that if ID shift will change, this formula will be not working. But if we take in count that structure of container will not changes, this way is right for me.
And few questions about mastershape. Using master shape - is more correct way I supose. But I don`t understand, how can I solve my task using master shape. Could you help me or show start point?