## News:

BB code in posts seems to be working again!
I haven't turned on every single tag, so please let me know if there are any that are used/needed but not activated.

## How write a formula taking into account variables datas.

Started by Miguel, April 10, 2017, 07:44:36 AM

0 Members and 1 Guest are viewing this topic.

#### Miguel

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.

#### Surrogate

#1
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 stylevsoShape.CellsSRC(s, r, c).Formula = "xxxx"' where S - section, R - Row, C - column`
Shape.CellsSRC Property (Visio)
Shape.Cells Property (Visio)
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 ?

#### Miguel

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

Write the formula by means of SETF(Getref( target cell), Formula as string)
Yacine

#### Miguel

#4
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 ...

#### Surrogate

Miguel, you posted question in ShapeSheet & Smart Shapes thread.
But your first question contain VBA code.
Please describe which environment you want use ?

#### Surrogate

Quote from: Miguel on April 11, 2017, 07:35:45 AMI hope that you understand ...
`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

Quote from: Surrogate on April 11, 2017, 07:41:29 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

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 !

#### Miguel

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

#### Surrogate

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 !

#### Surrogate

#11
I don't understand what you mean as dynamic formula
`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

#### Miguel

Ok, I will try to work with your code. if I have difficulties I will post here

Browser ID: smf (possibly_robot)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 445 (show)
Files included: 34 - 1306KB. (show)
Memory used: 1217KB.