ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
KCKyle Chamberlain16/07/2013

Hi all,

    Just trying to get this call working in an example before implementing in a larger program and I am up against a wall! I am getting an error ("for each control variable must be a variant or object")  with the blue line below highlighted when i try to run this which is odd to me becase brokenRef is set as an object in this code.

It is worth metioning that this was the example for VB.NET and I have done my best to tweak it for VB6

Also:

-yes i have my license key

-yes I have registered all dll's and added ref's to project etc...

-yes i have read the api help exhaustively concerning this.

Any thoughts?

Sub main()

        Const sLicenseKey As String = "your_license_code" 'Specify your license key

        Const sDocFileName As String = "drawing_document_with_external_references"

        Dim swClassFact As SwDMClassFactory

        Dim swDocMgr As SwDMApplication3

        Dim swDoc As SwDMDocument16

        Dim swSearchOpt As SwDMSearchOption

        Dim nDocType As Long

        Dim nRetVal As Long

        Dim vDependArr As Object

        Dim vDepend As Object

        Dim vBrokenRefs As Object

        Dim vIsVirtuals As Object

        Dim vTimeStamps As Object

        ' Determine if document is a drawing

        If InStr(LCase(sDocFileName), "slddrw") > 0 Then

            nDocType = SwDmDocumentType.swDmDocumentDrawing

        Else

            ' Not a drawings file,

            nDocType = SwDmDocumentType.swDmDocumentUnknown

            ' so do not open

            Exit Sub

        End If

        Set swClassFact = CreateObject("SwDocumentMgr.SwDMClassFactory")

        Set swDocMgr = swClassFact.GetApplication(sLicenseKey)

        Set swSearchOpt = swDocMgr.GetSearchOptionObject

        Set swDoc = swDocMgr.GetDocument(sDocFileName, nDocType, False, nRetVal)

        Debug.Assert (SwDmDocumentOpenError.swDmDocumentOpenErrorNone = nRetVal)

        Debug.Print ("File = " & swDoc.FullName)

        Set vBrokenRefs = Nothing

        Dim brokenRef As SwDmReferenceStatus

        Set vIsVirtuals = Nothing

        Dim isVirtual As Boolean

        vTimeStamps = Nothing

        Dim timeStamp As Double

        vDependArr = swDoc.GetAllExternalReferences4(swSearchOpt, vBrokenRefs, vIsVirtuals, vTimeStamps)

        If vDependArr Is Nothing Then

        Exit Sub

        Else

        End If

        Debug.Print ("External references")

        For Each vDepend In vDependArr

            Debug.Print ("  " & vDepend)

        Next vDepend

        Debug.Print ("Reference statuses as defined in swDmReferenceStatus")

        For Each brokenRef In vBrokenRefs

            Debug.Print ("  " & brokenRef)

        Next brokenRef

        Debug.Print ("Virtual component?")

        For Each isVirtual In vIsVirtuals

            Debug.Print ("  " & isVirtual)

        Next isVirtual

        Debug.Print ("Timestamps")

        For Each timeStamp In vTimeStamps

            Debug.Print ("  " & timeStamp)

        Next timeStamp

    End Sub