storing connector endpoints shape text

J

jeff

I am trying to store in each of two custom properties (beg_point_label and
end_point_label) of a connector, a string that is the text (not the name) of
the shape connected to the respective endpoint of the connector. This would
be dynamic so that the stored value would change depending on which shape the
user glued the end. All help is appreciated.

Thanks.
 
C

Chris Roth [ Visio MVP ]

The formulas have to be set by code, dynamicallly. The ShapeSheet isn't
smart enough to let you do this.

There is a shape text formula:

ShapeText(Sheet.19!TheText)

which will get you the text of the shape with ID 19. Your code will have to
determine which shapes the connector is glued to. You figure that out using
shpConnector.Connects(1).ToSheet.ID, for example.

--

Hope this helps,

Chris Roth
Visio MVP
 
J

jeff

I took a look at the ShapeText function in the Visio SDK and it appears I
should be able to reference the shape by name. However, when I tried this I
get a "Qualifier must be Collection" compile error after the "!"

Below is the macro code I am using - a slight variation on the ToSheet
example in the SDK. Please steer me in the right right direction. Thanks -
Jeff
************************
Public Sub ToSheet_Example()

Dim vsoShapes As Visio.Shapes
Dim vsoShape As Visio.Shape
Dim vsoConnectTo As Visio.Shape
Dim vsoConnects As Visio.Connects
Dim vsoConnect As Visio.Connect
Dim intCurrentShapeIndex As Integer
Dim intCounter As Integer

Dim endpoint_Shape(2) As Variant
Dim endpoint_Shape_Text(2) As Variant
Dim endpoint_Shape_ID(2) As Integer


Set vsoShapes = ActivePage.Shapes

'For each shape on the page, get its connections.
For intCurrentShapeIndex = 1 To vsoShapes.Count

Set vsoShape = vsoShapes(intCurrentShapeIndex)
Set vsoConnects = vsoShape.Connects

'For each connection, get the shape it connects to.
For intCounter = 1 To vsoConnects.Count

Set vsoConnect = vsoConnects(intCounter)
Set vsoConnectTo = vsoConnect.ToSheet

'Print the ShapeName, ID, and Text of the shape the
'Connect object connects to.
endpoint_Shape(intCounter) = vsoConnectTo.Name
endpoint_Shape_ID(intCounter) = vsoConnectTo.ID
endpoint_Shape_Text(intCounter) =
ShapeText(vsoConnectTo.Name!TheText)
Debug.Print endpoint_Shape(intCounter),
endpoint_Shape_ID(intCounter)

Next intCounter

Next intCurrentShapeIndex

End Sub
 
C

Chris Roth [ Visio MVP ]

You've gotta build a string:

dim frml as string
dim shp as Visio.shape
....
frml = "ShapeText([shape]!TheText)"
frml = replace( frml, "[shape]", shp.ID )
shp.Cells("Prop.Something").ResultStr(visNoCast) = frml

--

Hope this helps,

Chris Roth
Visio MVP
 
J

jeff

Hi Chris - I really appreciate the help and am successfully retrieving the
connect shape ID as a string. Unfortunately I receive a compile error "can't
assign to read-only property" on the following code line:

shp.Cells("Prop.BeginningShape").ResultStr(visNoCast) = frml

The connector has a custom property "Prop.BeginningShape" as a string.

Any ideas?

Jeff

Chris Roth said:
You've gotta build a string:

dim frml as string
dim shp as Visio.shape
....
frml = "ShapeText([shape]!TheText)"
frml = replace( frml, "[shape]", shp.ID )
shp.Cells("Prop.Something").ResultStr(visNoCast) = frml

--

Hope this helps,

Chris Roth
Visio MVP


jeff said:
I took a look at the ShapeText function in the Visio SDK and it appears I
should be able to reference the shape by name. However, when I tried this
I
get a "Qualifier must be Collection" compile error after the "!"

Below is the macro code I am using - a slight variation on the ToSheet
example in the SDK. Please steer me in the right right direction.
Thanks -
Jeff
************************
Public Sub ToSheet_Example()

Dim vsoShapes As Visio.Shapes
Dim vsoShape As Visio.Shape
Dim vsoConnectTo As Visio.Shape
Dim vsoConnects As Visio.Connects
Dim vsoConnect As Visio.Connect
Dim intCurrentShapeIndex As Integer
Dim intCounter As Integer

Dim endpoint_Shape(2) As Variant
Dim endpoint_Shape_Text(2) As Variant
Dim endpoint_Shape_ID(2) As Integer


Set vsoShapes = ActivePage.Shapes

'For each shape on the page, get its connections.
For intCurrentShapeIndex = 1 To vsoShapes.Count

Set vsoShape = vsoShapes(intCurrentShapeIndex)
Set vsoConnects = vsoShape.Connects

'For each connection, get the shape it connects to.
For intCounter = 1 To vsoConnects.Count

Set vsoConnect = vsoConnects(intCounter)
Set vsoConnectTo = vsoConnect.ToSheet

'Print the ShapeName, ID, and Text of the shape the
'Connect object connects to.
endpoint_Shape(intCounter) = vsoConnectTo.Name
endpoint_Shape_ID(intCounter) = vsoConnectTo.ID
endpoint_Shape_Text(intCounter) =
ShapeText(vsoConnectTo.Name!TheText)
Debug.Print endpoint_Shape(intCounter),
endpoint_Shape_ID(intCounter)

Next intCounter

Next intCurrentShapeIndex

End Sub
 
C

Chris Roth [ Visio MVP ]

Yup, Result/ResultStr are read-only. To set, you need .Formula or .Result or
..ResultIU.

If you're doing text, then use Formula or FormulaU for english. You'll have
to add extra quotes around your strings, ie:

shp.Cells("").FormulaU = chr(34) & "Bob was here" & chr(34)

I use chr(34) because it's easier to read and check than """"Bob"""""

--

Hope this helps,

Chris Roth
Visio MVP


jeff said:
Hi Chris - I really appreciate the help and am successfully retrieving the
connect shape ID as a string. Unfortunately I receive a compile error
"can't
assign to read-only property" on the following code line:

shp.Cells("Prop.BeginningShape").ResultStr(visNoCast) = frml

The connector has a custom property "Prop.BeginningShape" as a string.

Any ideas?

Jeff

Chris Roth said:
You've gotta build a string:

dim frml as string
dim shp as Visio.shape
....
frml = "ShapeText([shape]!TheText)"
frml = replace( frml, "[shape]", shp.ID )
shp.Cells("Prop.Something").ResultStr(visNoCast) = frml

--

Hope this helps,

Chris Roth
Visio MVP


jeff said:
I took a look at the ShapeText function in the Visio SDK and it appears
I
should be able to reference the shape by name. However, when I tried
this
I
get a "Qualifier must be Collection" compile error after the "!"

Below is the macro code I am using - a slight variation on the ToSheet
example in the SDK. Please steer me in the right right direction.
Thanks -
Jeff
************************
Public Sub ToSheet_Example()

Dim vsoShapes As Visio.Shapes
Dim vsoShape As Visio.Shape
Dim vsoConnectTo As Visio.Shape
Dim vsoConnects As Visio.Connects
Dim vsoConnect As Visio.Connect
Dim intCurrentShapeIndex As Integer
Dim intCounter As Integer

Dim endpoint_Shape(2) As Variant
Dim endpoint_Shape_Text(2) As Variant
Dim endpoint_Shape_ID(2) As Integer


Set vsoShapes = ActivePage.Shapes

'For each shape on the page, get its connections.
For intCurrentShapeIndex = 1 To vsoShapes.Count

Set vsoShape = vsoShapes(intCurrentShapeIndex)
Set vsoConnects = vsoShape.Connects

'For each connection, get the shape it connects to.
For intCounter = 1 To vsoConnects.Count

Set vsoConnect = vsoConnects(intCounter)
Set vsoConnectTo = vsoConnect.ToSheet

'Print the ShapeName, ID, and Text of the shape the
'Connect object connects to.
endpoint_Shape(intCounter) = vsoConnectTo.Name
endpoint_Shape_ID(intCounter) = vsoConnectTo.ID
endpoint_Shape_Text(intCounter) =
ShapeText(vsoConnectTo.Name!TheText)
Debug.Print endpoint_Shape(intCounter),
endpoint_Shape_ID(intCounter)

Next intCounter

Next intCurrentShapeIndex

End Sub

:

The formulas have to be set by code, dynamicallly. The ShapeSheet
isn't
smart enough to let you do this.

There is a shape text formula:

ShapeText(Sheet.19!TheText)

which will get you the text of the shape with ID 19. Your code will
have
to
determine which shapes the connector is glued to. You figure that out
using
shpConnector.Connects(1).ToSheet.ID, for example.

--

Hope this helps,

Chris Roth
Visio MVP


I am trying to store in each of two custom properties
(beg_point_label
and
end_point_label) of a connector, a string that is the text (not the
name)
of
the shape connected to the respective endpoint of the connector.
This
would
be dynamic so that the stored value would change depending on which
shape
the
user glued the end. All help is appreciated.

Thanks.
 
J

jeff

Thanks for walking me thru this. I added the quotes around frml and used
chr(34) for the quotes around the quoted string (e.g. chr(34)
&"ShapeText(2!TheText)"&chr(34) ). Where frml now is "ShapeText(2!TheText)"

The line of code now reads:

'shp.Cells("Prop.BeginningShape").FormulaU = Chr(34) & frml & Chr(34)

Now I get a runtime error that says "Object variable or With block variable
not set"

What do you think?

Chris Roth said:
Yup, Result/ResultStr are read-only. To set, you need .Formula or .Result or
..ResultIU.

If you're doing text, then use Formula or FormulaU for english. You'll have
to add extra quotes around your strings, ie:

shp.Cells("").FormulaU = chr(34) & "Bob was here" & chr(34)

I use chr(34) because it's easier to read and check than """"Bob"""""

--

Hope this helps,

Chris Roth
Visio MVP


jeff said:
Hi Chris - I really appreciate the help and am successfully retrieving the
connect shape ID as a string. Unfortunately I receive a compile error
"can't
assign to read-only property" on the following code line:

shp.Cells("Prop.BeginningShape").ResultStr(visNoCast) = frml

The connector has a custom property "Prop.BeginningShape" as a string.

Any ideas?

Jeff

Chris Roth said:
You've gotta build a string:

dim frml as string
dim shp as Visio.shape
....
frml = "ShapeText([shape]!TheText)"
frml = replace( frml, "[shape]", shp.ID )
shp.Cells("Prop.Something").ResultStr(visNoCast) = frml

--

Hope this helps,

Chris Roth
Visio MVP


I took a look at the ShapeText function in the Visio SDK and it appears
I
should be able to reference the shape by name. However, when I tried
this
I
get a "Qualifier must be Collection" compile error after the "!"

Below is the macro code I am using - a slight variation on the ToSheet
example in the SDK. Please steer me in the right right direction.
Thanks -
Jeff
************************
Public Sub ToSheet_Example()

Dim vsoShapes As Visio.Shapes
Dim vsoShape As Visio.Shape
Dim vsoConnectTo As Visio.Shape
Dim vsoConnects As Visio.Connects
Dim vsoConnect As Visio.Connect
Dim intCurrentShapeIndex As Integer
Dim intCounter As Integer

Dim endpoint_Shape(2) As Variant
Dim endpoint_Shape_Text(2) As Variant
Dim endpoint_Shape_ID(2) As Integer


Set vsoShapes = ActivePage.Shapes

'For each shape on the page, get its connections.
For intCurrentShapeIndex = 1 To vsoShapes.Count

Set vsoShape = vsoShapes(intCurrentShapeIndex)
Set vsoConnects = vsoShape.Connects

'For each connection, get the shape it connects to.
For intCounter = 1 To vsoConnects.Count

Set vsoConnect = vsoConnects(intCounter)
Set vsoConnectTo = vsoConnect.ToSheet

'Print the ShapeName, ID, and Text of the shape the
'Connect object connects to.
endpoint_Shape(intCounter) = vsoConnectTo.Name
endpoint_Shape_ID(intCounter) = vsoConnectTo.ID
endpoint_Shape_Text(intCounter) =
ShapeText(vsoConnectTo.Name!TheText)
Debug.Print endpoint_Shape(intCounter),
endpoint_Shape_ID(intCounter)

Next intCounter

Next intCurrentShapeIndex

End Sub

:

The formulas have to be set by code, dynamicallly. The ShapeSheet
isn't
smart enough to let you do this.

There is a shape text formula:

ShapeText(Sheet.19!TheText)

which will get you the text of the shape with ID 19. Your code will
have
to
determine which shapes the connector is glued to. You figure that out
using
shpConnector.Connects(1).ToSheet.ID, for example.

--

Hope this helps,

Chris Roth
Visio MVP


I am trying to store in each of two custom properties
(beg_point_label
and
end_point_label) of a connector, a string that is the text (not the
name)
of
the shape connected to the respective endpoint of the connector.
This
would
be dynamic so that the stored value would change depending on which
shape
the
user glued the end. All help is appreciated.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top