I went through all the documentation, but this formula is still breaking my mind
=SETATREF(User.PIDTagInputText,SETATREFEVAL(SETATREFEXPR("Default Tag")))
Can you explain what is happening here?
The SETATREF function assumes that there are two cells:
Cell1 - the one where the function itself is placed
Cell2 - the one where you need to pass the value
The function not only transfers the value to the Cell2 cell, but also returns this value to the Cell1 cell. Moreover, the formula is not destroyed.
Let's take an example. Let the shape have a ShapeData labeled "a".
The Value cell contains the formula
In this case, Cell1 is Prop.a.Value. It contains formula =SETATREF(Prop.a.Prompt,SETATREFEVAL(SUBSTITUTE(SETATREFEXPR("hh"),"11","2")),FALSE)
Cell2 is Prop.a.Prompt. But Cell2 is not important. Only Cell1 is interesting. It contains a formula and we need to return the changed value to it.
The above formula should replace two adjacent "1" characters with a single "2" character.
SUBSTITUTE(SETATREFEXPR(),"11","2")
See the animated gif for how it works.
-----------
When the user changes the value of Prop.a through the UI or programmatically, Visio does the following in sequence:
- Detects that a formula contains the SETATREFEVAL function
- Finds among its arguments the SETATREFEXPR function
- Executes SETATREFEXPR - remembers the value that the user is trying to enter in Cell1.
- Performs a SETATREFEVAL function on this value - in this example, SUBSTITUTE.
- Passes the computed result to Cell2.
- Replaces the value of Cell1 with the value of Cell2 (returns the result).