Why does a =ThePage!ID() formula not give a Page ID() value?

Started by Visisthebest, March 27, 2022, 07:29:47 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Visisthebest

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?
Visio 2021 Professional

Paul Herber

The ID of the first page in a document is 0. Add another page and get the ID of that.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

Visisthebest

That's what I do Paul, if I try to get ThePage!ID() on the 10th page, I still get 0 as a result.
Visio 2021 Professional

Surrogate


wapperdude

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)

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
Visio 2019 Pro

Visisthebest

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.
Visio 2021 Professional

Surrogate

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) in post #10921 (translated via Google Translate service)if you write
=Pages[Page-1]!Sheet.0!Prop.Row_1, it will rename itself to ThePage. Because ThePage is also a shape

Visisthebest

#7
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!
Visio 2021 Professional

Surrogate


vojo

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

Surrogate

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...

wapperdude

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.  🤔😲
Visio 2019 Pro

Visisthebest

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.
Visio 2021 Professional

wapperdude

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.
Visio 2019 Pro

Surrogate

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.