type mismatch problem passing shape....

L

Lee Bassom

Hi all,
I'm hoping someone can help me out with a bit of VBA in Visio.

It looks ok, but I'm getting a type mismatch error
(It's just a simple bit of code I'm using to figure out how to do something)

Public Sub callDummy()
Dim shp As Visio.Shape
Set shp = Visio.ActiveWindow.Selection.Item(1)
Dummy (shp) ' <-- Get Type Mismatch here on compile
End Sub

Public Sub Dummy(shp As Visio.Shape)
If (shp.Master Is Nothing) Then
MsgBox ("It's Nothing")
ElseIf (IsEmpty(shp.Master)) Then
MsgBox ("It's Empty")
ElseIf (IsNull(shp.Master)) Then
MsgBox ("It's Null")
Else
MsgBox ("Bingo!")
End If
End Sub
 
M

Michael J. Hunter [MS]

Heh. You've been bitten by one of VBA's oddities.

When you call a Sub (i.e., does not return a value, as opposed to a
Function, which does return a value), you don't wrap the Sub's arguments in
parentheses. If you change your code to the following:

Public Sub callDummy()
Dim shp As Visio.Shape
Set shp = Visio.ActiveWindow.Selection.Item(1)
Dummy shp ' <-- No Type Mismatch here anymore
End Sub

it works as you expect. Or you call call Dummy using the Call keyword, in
which case you do need the parentheses:

Public Sub callDummy()
Dim shp As Visio.Shape
Set shp = Visio.ActiveWindow.Selection.Item(1)
Call Dummy(shp) ' <-- No Type Mismatch here anymore
End Sub

So why don't you get a syntax error? This is in fact valid VBA, and forces
the arguments to be passed by value rather than by reference.


Michael J. Hunter
Microsoft
michhu-at-online-dot-microsoft-dot-com

Developing Microsoft Visio Solutions:
http://msdn.microsoft.com/library/en-us/devref/HTML/DVS_Copyright_1270.asp
Developer Resources for Microsoft Visio:
http://msdn.microsoft.com/library/default.asp?url=/nhp/Default.asp?contentid=28000456

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 

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