×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Type mismatch when creating function (API)

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

RE: Type mismatch when creating function (API)

Which line?

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)

(OP)
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.

RE: Type mismatch when creating function (API)

You are using an object swPartDoc when you need an integer.

RE: Type mismatch when creating function (API)

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

RE: Type mismatch when creating function (API)

(OP)
Thanks for your input, guys. I tried both suggestions but same error still. I'll keep playing around with it...

RE: Type mismatch when creating function (API)

Quote:

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.

RE: Type mismatch when creating function (API)

swDocPART, not swPartDoc.

-handleman, CSWP (The new, easy test)

RE: Type mismatch when creating function (API)

(OP)
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources