Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type mismatch when creating function (API)

Status
Not open for further replies.

razzendahcuben

Mechanical
Jan 10, 2009
79
0
0
US
I am confused as to why I am getting a type mismatch here. Any insight would be greatly appreciated.

-------

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2

Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc

MsgBox IsPartOpen(swApp)

End Sub

Function IsPartOpen(app As Application.SldWorks) As Boolean
If swModel.GetType = swPartDOC Then
IsPartOpen = True
Else
IsPartOpen = False
End If
End Function
 
Replies continue below

Recommended for you

Thanks for the response. To answer your question:

The first line of the function is the problem (Function IsPartOpen).

Yes, there is a part open.

The function tests whether a part is open.
 
I believe that you need to move the:
Set swModel = swApp.ActiveDoc

line down into the function. In general, a variable of a given name inside one function is not linked to variables of the same name in different functions / subs.

Eric
 
Found the problem. "app as Application.SldWorks" needs to be "app as SldWorks.SldWorks.", then the type mismatch error goes away.

I'll correct the other error you pointed out as well. Thanks.
 
Status
Not open for further replies.
Back
Top