Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-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
Joined
Jan 10, 2009
Messages
79
Location
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
 
Which line?

What are you trying to do?

Is there actually a part open?

-handleman, CSWP (The new, easy test)
 
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.
 
You are using an object swPartDoc when you need an integer.
 
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
 
Thanks for your input, guys. I tried both suggestions but same error still. I'll keep playing around with it...
 
If swModel.GetType = swPartDOC

"swPartDoc" is an object class. It is a reserved word. You need to define a variable that is a number (long type) for GetType.
 
swDocPART, not swPartDoc.

-handleman, CSWP (The new, easy test)
 
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.

Part and Inventory Search

Sponsor

Back
Top