Type mismatch when creating function (API)
Type mismatch when creating function (API)
(OP)
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
-------
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






RE: Type mismatch when creating function (API)
What are you trying to do?
Is there actually a part open?
-handleman, CSWP (The new, easy test)
RE: Type mismatch when creating function (API)
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.
RE: Type mismatch when creating function (API)
RE: Type mismatch when creating function (API)
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
RE: Type mismatch when creating function (API)
RE: Type mismatch when creating function (API)
"swPartDoc" is an object class. It is a reserved word. You need to define a variable that is a number (long type) for GetType.
RE: Type mismatch when creating function (API)
-handleman, CSWP (The new, easy test)
RE: Type mismatch when creating function (API)
I'll correct the other error you pointed out as well. Thanks.