Visio Guy

Visio Discussions => ShapeSheet & Smart Shapes => Topic started by: Visisthebest on March 27, 2022, 07:29:47 AM

Title: Why does a =ThePage!ID() formula not give a Page ID() value?
Post by: Visisthebest on March 27, 2022, 07:29:47 AM
Using the shape's ID() function in a formula works well and I use it frequently, however if I create a =ThePage!ID() formula I always get the value 0 (no matter on which page I run it, could be on a 20-page document on the 10th page).

Why doesn't this seemingly simple function work as expected?
Title: Re: Why does a =ThePage!ID() formula not give a Page ID() value?
Post by: Paul Herber on March 27, 2022, 08:24:55 AM
The ID of the first page in a document is 0. Add another page and get the ID of that.
Title: Re: Why does a =ThePage!ID() formula not give a Page ID() value?
Post by: Visisthebest on March 27, 2022, 09:19:52 AM
That's what I do Paul, if I try to get ThePage!ID() on the 10th page, I still get 0 as a result.
Title: Re: Why does a =ThePage!ID() formula not give a Page ID() value?
Post by: Surrogate on March 27, 2022, 04:34:46 PM
Each page is root shape with shape name Sheet.0
Title: Re: Why does a =ThePage!ID() formula not give a Page ID() value?
Post by: wapperdude on March 27, 2022, 06:11:57 PM
There is no shapesheet fcn of that format.  There is VBA, but not as indicated.  To get shape ID, which is for fetching/documenting, see code example...
For shapesheet formula construction/syntax:  https://docs.microsoft.com/en-us/previous-versions/office/developer/office-xp/aa200961(v=office.10) (https://docs.microsoft.com/en-us/previous-versions/office/developer/office-xp/aa200961(v=office.10))

The debug.print lists three properties:  the name as displayed on tab, the order placement withing the pages, and the ID of the page.

Sub Macro1()

    ActiveWindow.Page = Application.ActiveDocument.Pages.ItemU("Page-2")
    Set vPg = ActiveWindow.Page
    Debug.Print vPg.Name; vPg.Index; vPg.ID

End Sub
Title: Re: Why does a =ThePage!ID() formula not give a Page ID() value?
Post by: Visisthebest on March 27, 2022, 07:28:09 PM
Thank you Wapperdude, yes with VBA it is no problem to get it.

The weird thing is that shapesheet autocomplete offers the ID() as an option when entering =TheDoc! or =ThePage! as a formula, but it just doesn't work.
Title: Re: Why does a =ThePage!ID() formula not give a Page ID() value?
Post by: Surrogate on March 27, 2022, 07:46:19 PM
Quote from: wapperdude on March 27, 2022, 06:11:57 PM
There is no shapesheet fcn of that format.
You are right, but you can try
Quote from: Tumanov (aka Croc (http://visguy.com/vgforum/index.php?action=profile;u=11866)) in post #10921 (https://visio-getbb-ru.translate.goog/viewtopic.php?p=10921&_x_tr_sl=ru&_x_tr_tl=en&_x_tr_hl=ru&_x_tr_pto=wapp#p10921) (translated via Google Translate service (https://translate.google.com/))if you write
=Pages[Page-1]!Sheet.0!Prop.Row_1, it will rename itself to ThePage. Because ThePage is also a shape
Title: Re: Why does a =ThePage!ID() formula not give a Page ID() value?
Post by: Visisthebest on March 28, 2022, 09:41:02 AM
Surrogate thank you but specifically I am trying to get the ID() function to work on the page, getting a User or Prop field works well. Though thinking about it, I could also put the Page ID() in a page User field then read that field! Same for the document. Doh!
Title: Re: Why does a =ThePage!ID() formula not give a Page ID() value?
Post by: Surrogate on March 28, 2022, 10:59:22 AM
huh ! what useful information Page.ID contains ?
Title: Re: Why does a =ThePage!ID() formula not give a Page ID() value?
Post by: vojo on March 28, 2022, 01:35:01 PM
which of N pages involved?
I may be an out layer, but typically have several drawing pages as well as several background pages.
So if I were trying to target some shape on some page, page ID might be helpful to me
Title: Re: Why does a =ThePage!ID() formula not give a Page ID() value?
Post by: Surrogate on March 28, 2022, 02:00:17 PM
Quote from: Paul Herber on March 27, 2022, 08:24:55 AM
The ID of the first page in a document is 0. Add another page and get the ID of that.
The second page ID = 4, and so on in order. If subsequently one of the pages will be deleted, its ID will be excluded from the list...
Title: Re: Why does a =ThePage!ID() formula not give a Page ID() value?
Post by: wapperdude on March 28, 2022, 02:39:48 PM
Well, outlayer#2 here.  Why ID and not Name or Index?  The index is a very hidden value, so, for user referencing not most useful.  Also, for debugging, there is no intuitive way to remember, at a much later date, what a formula is doing. 

As for page names & index numbers,  these are very obvious, but, present dilemma of being easily changed.  In the case of names, a most simple macro can be used to keep name and names synchronized.  An, already suggested alternative, is to create a User cell with a meaningful descriptive identifier.   Page ID is the most mutation resistant identifier, but also the least informative..  Guess that was 1.5 cents worth of comment.  🤔😲
Title: Re: Why does a =ThePage!ID() formula not give a Page ID() value?
Post by: Visisthebest on March 28, 2022, 03:14:29 PM
Using the Page ID because I need a reference to the page that is guaranteed to be unique, I assumed pages can have identical names and users can cause issues by renaming pages.
Title: Re: Why does a =ThePage!ID() formula not give a Page ID() value?
Post by: wapperdude on March 28, 2022, 03:37:21 PM
That seemed like the rationale.

Certainly, page name and indexing are easily manipulated.  But, if not mistaken, names requires very deliberate effort.  It is not something the casual user would change.  I believe it can only be changed by code.
Title: Re: Why does a =ThePage!ID() formula not give a Page ID() value?
Post by: Surrogate on March 28, 2022, 05:03:20 PM
Quote from: wapperdude on March 28, 2022, 02:39:48 PM
Page ID is the most mutation resistant identifier, but also the least informative..  Guess that was 1.5 cents worth of comment.  🤔😲
I agree with this! Hope my comment costs about 7.40 roubles  ;)
Quote from: wapperdude on March 28, 2022, 03:37:21 PM
That seemed like the rationale.

Certainly, page name and indexing are easily manipulated.  But, if not mistaken, names requires very deliberate effort.  It is not something the casual user would change.  I believe it can only be changed by code.
In this case you need create list for storage pagenames  and their indexes. I think it is possible with VBA.