"If" "Then" conditions

M

mfgeng_iss

I want to add an "IF" "Then" condition to a system generated macro
(Visio 2003) that is set to activate via a double click on an object.
Currently when I double click on object A the following change
happens: object A = 1 (white), object B = 2 (red), lines A & B = 4
(blue). How can I add this condition: If object C = 3 (green) then
change line C = 4 (blue).

Thanks in advance
Dave
 
M

mfgeng_iss

Chris,
When I added the VBA code I received a debug run error. Here is the
code as recorded by the Visio macro recorder. This is what I need
added: If object 17 = 3 (green) then change line 5 = RGB(51,204,204
(aqua).

The objects and colors used in my first posting were hypothetical,
these are actual. Would it help if I emailed the .vsd to you?

Thanks again
Dave


___________________________________________________________________________________________________
Sub HV2open()

Dim UndoScopeID1 As Long
UndoScopeID1 = Application.BeginUndoScope("Fill Properties")

Application.ActiveWindow.Page.Shapes.ItemFromID(2).CellsSRC(visSectionObject,
visRowFill, visFillForegnd).FormulaU = "3"
Application.EndUndoScope UndoScopeID1, True

Dim UndoScopeID2 As Long
UndoScopeID2 = Application.BeginUndoScope("Fill Properties")

Application.ActiveWindow.Page.Shapes.ItemFromID(1).CellsSRC(visSectionObject,
visRowFill, visFillForegnd).FormulaU = "1"
Application.EndUndoScope UndoScopeID2, True

Dim UndoScopeID3 As Long
UndoScopeID3 = Application.BeginUndoScope("Line Properties")

Application.ActiveWindow.Page.Shapes.ItemFromID(18).CellsSRC(visSectionObject,
visRowLine, visLineColor).FormulaU = "RGB(51,204,204)"

Application.ActiveWindow.Page.Shapes.ItemFromID(18).Shapes.ItemFromID(20).CellsSRC(visSectionObject,
visRowLine, visLineColor).FormulaU = "RGB(51,204,204)"

Application.ActiveWindow.Page.Shapes.ItemFromID(18).Shapes.ItemFromID(19).CellsSRC(visSectionObject,
visRowLine, visLineColor).FormulaU = "RGB(51,204,204)"
Application.EndUndoScope UndoScopeID3, True


End Sub
_________________________________________________________________________________________________
 
C

Chris Roth [MVP]

Hi Dave,

My worm-protection was freaking out and I didn't get to the newsgroups for
awhile...

My guess is that your error is coming from the hard-coded ids inside of the
ItemFromID() properties. Every Visio shape has a different ID, so you'll
have to parameterize the ids that you get in the macro-generated code.

Anyway, try this code (in a blank drawing) - it might help you to better see
how to structure everything:

----------

Sub Dave()

Dim shp1 As Visio.Shape, shp2 As Visio.Shape

'// Draw shape 1:
Set shp1 = Visio.ActivePage.DrawRectangle(1, 1, 3, 3)
shp1.CellsU("LineWeight").ResultIU = 0.25
shp1.Text = "One"

'// Draw shape 2:
Set shp2 = Visio.ActivePage.DrawRectangle(4, 1, 6, 3)
shp2.CellsU("LineWeight").ResultIU = 0.25
shp2.Text = "Two"

Call MsgBox("Here's two shapes on the page. Let's try the conditional
formatting:")

Call m_conditionalFormat(shp1, shp2)

Call MsgBox("Now turn shp1 green:")
shp1.CellsU("FillForegnd").FormulaForceU = "RGB(0,255,0)"


Call MsgBox("Now, try the conditional formatting again:")
Call m_conditionalFormat(shp1, shp2)

Call MsgBox("Cool!")


End Sub

Private Sub m_conditionalFormat(shp1 As Visio.Shape, shp2 As Visio.Shape)

'// If shp1 has a green fill:
If (shp1.CellsU("FillForegnd").ResultIU = 2) Or _
(shp1.CellsU("FillForegnd").ResultStr(visNoCast) = "RGB(0, 255, 0)")
Then ' note the spaces after the commas!

'// Do if green:
shp2.Cells("LineColor").FormulaForceU = "RGB(51,204,204)"

Else
'// Do if not green:
shp2.Cells("LineColor").FormulaForceU = "2"

End If

End Sub

----------

-----

--
Hope this helps,

Chris Roth
Visio MVP

Free Visio shapes:
http://www.visguy.com/category/shapes
Visio programming info:
http://www.visguy.com/category/programming/
Other Visio resources:
http://www.visguy.com/visio-links/
 
M

mfgeng_iss

Hi Dave,

My worm-protection was freaking out and I didn't get to the newsgroups for
awhile...

My guess is that your error is coming from the hard-coded ids inside of the
ItemFromID() properties. Every Visio shape has a different ID, so you'll
have to parameterize the ids that you get in the macro-generated code.

Anyway, try this code (in a blank drawing) - it might help you to better see
how to structure everything:

----------

Sub Dave()

Dim shp1 As Visio.Shape, shp2 As Visio.Shape

'// Draw shape 1:
Set shp1 = Visio.ActivePage.DrawRectangle(1, 1, 3, 3)
shp1.CellsU("LineWeight").ResultIU = 0.25
shp1.Text = "One"

'// Draw shape 2:
Set shp2 = Visio.ActivePage.DrawRectangle(4, 1, 6, 3)
shp2.CellsU("LineWeight").ResultIU = 0.25
shp2.Text = "Two"

Call MsgBox("Here's two shapes on the page. Let's try the conditional
formatting:")

Call m_conditionalFormat(shp1, shp2)

Call MsgBox("Now turn shp1 green:")
shp1.CellsU("FillForegnd").FormulaForceU = "RGB(0,255,0)"

Call MsgBox("Now, try the conditional formatting again:")
Call m_conditionalFormat(shp1, shp2)

Call MsgBox("Cool!")

End Sub

Private Sub m_conditionalFormat(shp1 As Visio.Shape, shp2 As Visio.Shape)

'// If shp1 has a green fill:
If (shp1.CellsU("FillForegnd").ResultIU = 2) Or _
(shp1.CellsU("FillForegnd").ResultStr(visNoCast) = "RGB(0, 255, 0)")
Then ' note the spaces after the commas!

'// Do if green:
shp2.Cells("LineColor").FormulaForceU = "RGB(51,204,204)"

Else
'// Do if not green:
shp2.Cells("LineColor").FormulaForceU = "2"

End If

End Sub

----------

-----

--
Hope this helps,

Chris Roth
Visio MVP

Free Visio shapes:
http://www.visguy.com/category/shapes
Visio programming info:
http://www.visguy.com/category/programming/
Other Visio resources:
http://www.visguy.com/visio-links/


















- Show quoted text -

Chris
I think I understand how you structured everything. Your conditions
are based on shapes that you drew in the Sub, thus identifying the
variables.

My sub says:
Change item2 to "3"
Change item1 to "1"
Change items 20 & 19 to "RGB(51,204,204)

I believe this is where my problem begins.

If item 17 is "3" then
Change item5 to "RGB(51,204,204)

The variables for items 17 & 5 are not identified in the sub. How can
I identify these items in the same code used by the macro recorder to
keep from receiving a "variable mismatch" error?

Also, in the private sub you noted," note the spaces after the
commas".
1. What is the significance of the spaces? Because it fails to execute
properly without the commas.
2. Is RGB(0,255,0) = 3?

Thanks
Dave
 

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