Visio Guy

Visio Discussions => Programming & Code => Topic started by: Yacine on May 05, 2022, 07:50:01 AM

Title: Modify by code a cell that has a BOUND formula
Post by: Yacine on May 05, 2022, 07:50:01 AM
Say you have a cell whose value is constrained by a BOUND formula and you want to overwrite its value - NOT the formula - by code.


Instead of shp.Cells(your_cell_name).Formula = ... ,
write shp.Cells(your_cell_name).ResultIU = ...


Interesting enough, if you write a value outside the allowed range, the value gets written into the value parameter of the BOUND formula, but the value of the cell itself is still correctly within the boundaries.
So if you want to know the limits of the cell, you could instead of parsing the formula, set its values to very high and very low values and read the according values.


PS: I haven't yet tried other assignments thant ResultIU.
Title: Re: Modify by code a cell that has a BOUND formula
Post by: Yacine on May 06, 2022, 07:30:44 AM
Yeah! I need to share this:
If you write a bound formula in a prop cell it won't get overwritten when you type in values and even better, the values are restrained as it should.
Great feature, I would have liked to know before.
Title: Re: Modify by code a cell that has a BOUND formula
Post by: Visisthebest on May 06, 2022, 10:48:38 AM
Thank you for sharing this insight Yacine!
Title: Re: Modify by code a cell that has a BOUND formula
Post by: wapperdude on May 06, 2022, 11:48:50 PM
I can confirm the ResultIU() method.
I also get the same behavior with Formula.  Also, using SETATREF in Prop Data produces same behavior. 

My target cell in all cases was Width.
Obviously, FormulaForce clobbers the formula in the width cell and replaces it with the specified value.

Title: Re: Modify by code a cell that has a BOUND formula
Post by: Yacine on May 07, 2022, 05:41:17 AM
SETATREF is certainly the better way to do it.
I just happen to struggle with all the SETATREF, SETATREFEXPR, ... functions.
Need to take the time to investigate on them, they are so useful.
Title: Re: Modify by code a cell that has a BOUND formula
Post by: wapperdude on May 07, 2022, 01:49:23 PM
SETATREF is definitely challenging.  It takes hands-on to really get to feeling comfortable with that group of functions.  Don't know if you've looked at my post, "What's with SETATREF?" in the User Submitted Stuff, http://visguy.com/vgforum/index.php?topic=6383.msg26308#msg26308 (http://visguy.com/vgforum/index.php?topic=6383.msg26308#msg26308).  It might be helpful.  I had intended it to be kinda like a tutorial, so if of interest, start at the 1st post and progressively work thru it?  Hopefully it will shed some light on the topic.