Visio Guy

Visio Discussions => ShapeSheet & Smart Shapes => Topic started by: Visisthebest on November 20, 2021, 03:26:58 PM

Title: Is this possible with SS formulas: append string every time cell changes
Post by: Visisthebest on November 20, 2021, 03:26:58 PM
I don't know enough about the shapesheet to know if this is possible:

In a shape data cell, there is a dropdown with several options.

Every time the user changes this cell, I want the string that is selected to be appended to a string in another cell with a semicolon ; before it.

So if a user first selects Coffee and then Bagel from the dropdown, the string in the other cell becomes:
;Coffee;Bagel

(I will remove the first ; in code before using the semicolon-separated string)

Is this possible with some shapesheet magic?
Title: Re: Is this possible with SS formulas: append string every time cell changes
Post by: Surrogate on November 20, 2021, 03:44:14 PM
 it is possible with SETF function (https://docs.microsoft.com/en-us/office/client-developer/visio/setf-function) magic
Title: Re: Is this possible with SS formulas: append string every time cell changes
Post by: Visisthebest on November 20, 2021, 04:03:24 PM
Thank you I don't know how to achieve that with SETF though.
Title: Re: Is this possible with SS formulas: append string every time cell changes
Post by: Visisthebest on November 20, 2021, 10:40:21 PM
How can I achieve this with SETF Surrogate?
Title: Re: Is this possible with SS formulas: append string every time cell changes
Post by: vojo on November 21, 2021, 09:00:15 PM


props.field1 = <coffee or tea or or or>

user cell = setf(getref(user.result), user.result & ":" & props.field1) 

                                       syntax = setf(getref(<cell you want to put value into>), <formula that creates the value>)

1st time

user.result = "coffee"

2nd time

user.result = "coffee:tea"

3rd time

user.result = "coffee:tea:beer"

over iterations, this will blow up to "blah:blah:blah:blah:blah:blah:blah:blah:blah:blah:blah:blah:blah:blah:blah:blah:blah:blah"
Title: Re: Is this possible with SS formulas: append string every time cell changes
Post by: Visisthebest on November 22, 2021, 08:36:54 AM
Thank you Vojo very clear how I can use SETF(GETREF()) to keep appending to a string.

This field is not often changed but it allows me to track the changes the user makes.

What I don't have a full picture on is when SETF(GETREF()) is triggered, from your example any change in a referenced cell (in this case prop.field1) triggers another evaluation of the SETF(GETREF()).

Microsoft writes about GETREF:
"References a cell and doesn't recalculate the formula when the referenced cell changes."

https://docs.microsoft.com/en-us/office/client-developer/visio/getref-function

That threw me off a bit but of course this is about SETF which DOES recalculate when a referenced cell changes (unless embedded in a GETREF)

So I assume that if a user does not use GETREF in a SETF, just a string referencing a cell (which I understand is possible but not recommended), then that reference, if the target cell is changed by something else than this SETF (or you'd get circular triggering), does trigger a recalculation of SETF.

Again thank you this is some great shapesheet magic!  :D
Title: Re: Is this possible with SS formulas: append string every time cell changes
Post by: vojo on November 22, 2021, 01:35:55 PM
use dependson

user.mycell = dependson(<trigger cell>) + setf(getref(<some other cell>), <calculate value>)