### Author Topic: How write a formula taking into account variables datas.  (Read 1977 times)

0 Members and 1 Guest are viewing this topic.

#### Miguel

• Jr. Member
• Posts: 49
##### How write a formula taking into account variables datas.
« on: April 10, 2017, 02: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 :

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

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

#### Surrogate

• Hero Member
• Posts: 1015
##### Re: How write a formula taking into account variables datas.
« Reply #1 on: April 11, 2017, 12:03:32 AM »
Hi, amigo !
How can I write with a little code the formulas in generally? That mean's write something like :

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

This little code change some shape's property. Correct syntax is
Code
``vsoShape.Cells("CellName").Formula = "xxxxx"' or SRC stylevsoShape.CellsSRC(s, r, c).Formula = "xxxx"' where S - section, R - Row, C - column``
Shape.CellsSRC Property (Visio)
Shape.Cells Property (Visio)
I would like in this line, write the formula taking into account the variables datas
which account ?
« Last Edit: April 11, 2017, 12:08:44 AM by Surrogate »

#### Miguel

• Jr. Member
• Posts: 49
##### Re: How write a formula taking into account variables datas.
« Reply #2 on: April 11, 2017, 12: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...

#### Yacine

• Hero Member
• Posts: 2703
##### Re: How write a formula taking into account variables datas.
« Reply #3 on: April 11, 2017, 01:35:24 AM »
Write the formula by means of SETF(Getref( target cell), Formula as string)
Yacine

#### Miguel

• Jr. Member
• Posts: 49
##### Re: How write a formula taking into account variables datas.
« Reply #4 on: April 11, 2017, 02:35:45 AM »
Write 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 :

Code
`` 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 ...
« Last Edit: April 11, 2017, 02:37:22 AM by Miguel »

#### Surrogate

• Hero Member
• Posts: 1015
##### Re: How write a formula taking into account variables datas.
« Reply #5 on: April 11, 2017, 02:41:29 AM »
Miguel, you posted question in ShapeSheet & Smart Shapes thread.
But your first question contain VBA code.
Please describe which environment you want use ?

#### Surrogate

• Hero Member
• Posts: 1015
##### Re: How write a formula taking into account variables datas.
« Reply #6 on: April 11, 2017, 02:48:59 AM »
I hope that you understand ...
Code
``Sub bq()Dim vsoShape As Shape, refShape As ShapeDim fml As StringSet refShape = ActivePage.Shapes(1)Set vsoShape = ActivePage.Shapes(2)fml = "ANGLETOPAR(270 deg," & refShape.Name & "!EventXFMod,EventXFMod)"vsoShape.CellsU("Angle").FormulaU = fmlEnd Sub``

#### Miguel

• Jr. Member
• Posts: 49
##### Re: How write a formula taking into account variables datas.
« Reply #7 on: April 11, 2017, 02:56:40 AM »
Miguel, you posted question in ShapeSheet & Smart Shapes 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.

#### Surrogate

• Hero Member
• Posts: 1015
##### Re: How write a formula taking into account variables datas.
« Reply #8 on: April 11, 2017, 03:17:37 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 !

#### Miguel

• Jr. Member
• Posts: 49
##### Re: How write a formula taking into account variables datas.
« Reply #9 on: April 11, 2017, 03:29:56 AM »
Yes of course but it is not dynamic. I want a generic formula amigo.

Code
``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

#### Surrogate

• Hero Member
• Posts: 1015
##### Re: How write a formula taking into account variables datas.
« Reply #10 on: April 11, 2017, 03:49:26 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 !

#### Surrogate

• Hero Member
• Posts: 1015
##### Re: How write a formula taking into account variables datas.
« Reply #11 on: April 11, 2017, 04:12:23 AM »
I don't understand what you mean as dynamic formula
Code
``Sub Amigo()Dim sh As ShapeSet sh = ActivePage.Shapes(1)Call Test(45, sh)End SubSub Test(refAngle As Single, refShape As Shape)Dim vsoShape As ShapeDim fml As StringSet vsoShape = ActivePage.Shapes(2)fml = "ANGLETOPAR(" & refAngle & " deg," & refShape.Name & "!EventXFMod,EventXFMod)"vsoShape.CellsU("Angle").FormulaU = fmlEnd 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
« Last Edit: April 11, 2017, 04:15:15 AM by Surrogate »

#### Miguel

• Jr. Member
• Posts: 49
##### Re: How write a formula taking into account variables datas.
« Reply #12 on: April 11, 2017, 04:40:03 AM »
Ok, I will try to work with your code. if I have difficulties I will post here