Visio Guy

Visio Discussions => ShapeSheet & Smart Shapes => Topic started by: Miguel on April 10, 2017, 07:44:36 AM

Title: How write a formula taking into account variables datas.
Post by: Miguel on April 10, 2017, 07:44:36 AM
Hello to all of you!

I have news questions to you! My questions are about fomulas in cells in sections of the ShapeSheet.
Indeed, after glued two shapes together, the formulas in the cells in the section Shape Transform change.
I glued my two shapes (A triange and a rectangle) by the way of connection points. It's my triangle which is glue on the rectangle.
The picture 1 below shows what I get after glued.

I've noticed that however where my triangle is glue in my rectangle, the fomulas in the cells change. For exemple, I have in my rectangle 2 connections point. As you can see in the picture 2, if I glue my triangle in the left of the rectangle so I have a formulas, if I glue my triangle in the right of my rectangle so I have the same fomulas but not with the same data. (It's normal).

Now, I have this question:

How can I write with a little code the formulas in generally? That mean's write something like :

vsoShape.Cells(x,x,x).formula=" xxxxxxxxxxxx"

I would like in this line, write the formula taking into account the variables datas.


Thank for your help.


Title: Re: How write a formula taking into account variables datas.
Post by: Surrogate on April 11, 2017, 05:03:32 AM
Hi, amigo !
Quote from: Miguel on April 10, 2017, 07:44:36 AM
How can I write with a little code the formulas in generally? That mean's write something like :

vsoShape.Cells(x,x,x).formula=" xxxxxxxxxxxx"
This little code change some shape's property. Correct syntax is
vsoShape.Cells("CellName").Formula = "xxxxx"
' or SRC style
vsoShape.CellsSRC(s, r, c).Formula = "xxxx"
' where S - section, R - Row, C - column

Shape.CellsSRC Property (Visio) (https://msdn.microsoft.com/en-us/library/office/ff767394.aspx)
Shape.Cells Property (Visio) (https://msdn.microsoft.com/en-us/library/office/ff765764.aspx)
Quote from: Miguel on April 10, 2017, 07:44:36 AM
I would like in this line, write the formula taking into account the variables datas
which account ?
Title: Re: How write a formula taking into account variables datas.
Post by: Miguel on April 11, 2017, 05:40:08 AM
Thank you amigo, but I'm talking about a dynamic formula, a formula which change against the data that I framed in red.
So I would like to know how write a dynamic formula which has dynamic variable... :-\
Title: Re: How write a formula taking into account variables datas.
Post by: Yacine on April 11, 2017, 06:35:24 AM
Write the formula by means of SETF(Getref( target cell), Formula as string)
Title: Re: How write a formula taking into account variables datas.
Post by: Miguel on April 11, 2017, 07:35:45 AM
Quote from: Yacine on April 11, 2017, 06:35:24 AMWrite the formula by means of SETF(Getref( target cell), Formula as string)

Hello Yacine,
I'm afraid to don't understand. 

Bellow it's a code which I write :

If vsoShape.CellsU("Angle").FormulaU = "ANGLETOPAR(270 deg,Function.4!EventXFMod,EventXFMod)" Then
                 Call Change_Frame_Color
             End If


vsoShape.CellsU("Angle").FormulaU = "ANGLETOPAR(270 deg,Function.4!EventXFMod,EventXFMod)"  works but I would like a formula dynamic where Function.4! change against the function which I choose.

I hope that you understand ...  :-\
Title: Re: How write a formula taking into account variables datas.
Post by: Surrogate on April 11, 2017, 07:41:29 AM
Miguel, you posted question in ShapeSheet & Smart Shapes (http://visguy.com/vgforum/index.php?board=3.0) thread.
But your first question contain VBA code.
Please describe which environment you want use ?
Title: Re: How write a formula taking into account variables datas.
Post by: Surrogate on April 11, 2017, 07:48:59 AM
Quote from: Miguel on April 11, 2017, 07:35:45 AMI hope that you understand ...  :-\
what about that code
Sub bq()
Dim vsoShape As Shape, refShape As Shape
Dim fml As String
Set refShape = ActivePage.Shapes(1)
Set vsoShape = ActivePage.Shapes(2)
fml = "ANGLETOPAR(270 deg," & refShape.Name & "!EventXFMod,EventXFMod)"
vsoShape.CellsU("Angle").FormulaU = fml
End Sub
Title: Re: How write a formula taking into account variables datas.
Post by: Miguel on April 11, 2017, 07:56:40 AM
Quote from: Surrogate on April 11, 2017, 07:41:29 AM
Miguel, you posted question in ShapeSheet & Smart Shapes (http://visguy.com/vgforum/index.php?board=3.0) thread.

Yeah surrogate; it's because I'm writing my code against the formulas on the shapesheet.
I want a little code in VBA like my last post. I would like to know how write a formula with variable data. Indeed, in my formula : vsoShape.CellsU("Angle").FormulaU = "ANGLETOPAR(270 deg,Function.4!EventXFMod,EventXFMod)"  , only 270 deg,Function.4! change but the structure it's the same..

I'm sorry if I don't understand, I try to learn visio, vba and his application. 

Title: Re: How write a formula taking into account variables datas.
Post by: Surrogate on April 11, 2017, 08:17:37 AM
Quote from: Miguel on April 11, 2017, 07:56:40 AM
only 270 deg,Function.4! change but the structure it's the same..
my last code create formula which can replace Function.4 to another shape name !
Title: Re: How write a formula taking into account variables datas.
Post by: Miguel on April 11, 2017, 08:29:56 AM
Yes of course but it is not dynamic. I want a generic formula amigo. 

If vsoShape.CellsU("Angle").FormulaU = "ANGLETOPAR(X deg,Function.Y!EventXFMod,EventXFMod)" Then
                 Call Change_Frame_Color
             End If


vsoShape.CellsU("Angle").FormulaU = "ANGLETOPAR(X deg,Function.Y!EventXFMod,EventXFMod)".
I need a written formula only once which understand when W and Y change
Title: Re: How write a formula taking into account variables datas.
Post by: Surrogate on April 11, 2017, 08:49:26 AM
Quote from: Miguel on April 11, 2017, 08:29:56 AM
Yes of course but it is not dynamic.
How you want change reference shape ?
in my code i use variable refShape, i don't want make this code so complex and for this variable use there fixed shape. But this code can be changed.
Programming requires a clear and clear formulation of the problem !
You must specify what parameters are input - such as angles and shape name !
Title: Re: How write a formula taking into account variables datas.
Post by: Surrogate on April 11, 2017, 09:12:23 AM
I don't understand what you mean as dynamic formula
Sub Amigo()
Dim sh As Shape
Set sh = ActivePage.Shapes(1)
Call Test(45, sh)
End Sub
Sub Test(refAngle As Single, refShape As Shape)
Dim vsoShape As Shape
Dim fml As String
Set vsoShape = ActivePage.Shapes(2)
fml = "ANGLETOPAR(" & refAngle & " deg," & refShape.Name & "!EventXFMod,EventXFMod)"
vsoShape.CellsU("Angle").FormulaU = fml
End Sub

You must describe reference angle, refrerence shape and target shape !
Untill you don't describe your task, we will make so many new non-dynamics solutions :)
Title: Re: How write a formula taking into account variables datas.
Post by: Miguel on April 11, 2017, 09:40:03 AM
Ok, I will try to work with your code. if I have difficulties I will post here ;)