V Basic or SldWorks API Error

Discussion in 'SolidWorks' started by V.Tabakov, Dec 6, 2003.

  1. V.Tabakov

    V.Tabakov Guest

    Hi
    Am new in Sldworks API and VIsual Basic and i can't understand why
    this code dont Work Dim swApp As New SldWorks.SldWorks
    Dim swpartdoc As SldWorks.PartDoc
    Dim swmodel As SldWorks.ModelDoc2
    Dim swfeat As SldWorks.feature
    Dim swsubfeat As SldWorks.feature

    Sub main()
    Dim Clist As Variant
    Dim i, chcount As Integer
    Dim ok As Boolean


    Fmain.clear
    Set swmodel = swApp.ActiveDoc
    Set swpartdoc = swmodel
    Set swfeat = swmodel.FirstFeature
    While Not swfeat Is Nothing
    Fmain.addto " feature name " & swfeat.Name & " type : " & swfeat.GetTypeName
    ok = swfeat.Select2(False, 0)
    Clist = swfeat.GetChildren
    MsgBox " CHIld count " & UBound(Clist) ' TYpe mismatch error
    Set swfeat = swfeat.GetNextFeature
    Wend

    Fmain.Show



    End Sub
     
    V.Tabakov, Dec 6, 2003
    #1
  2. V.Tabakov

    Heikki Leivo Guest

    Hello V.,
    CList is defined as Variant. If a feature does not have children,
    GetChildren returns an empty variant, which doesn't have upper bound. You
    have to verify that Clist is not empty, like...

    If Not IsEmpty(CList) Then MsgBox ...etc.

    Hope this helps!

    -h-
     
    Heikki Leivo, Dec 6, 2003
    #2
  3. V.Tabakov

    V.Tabakov Guest

    Yes Yes it works
    I just can't say how thankful i'am


    but i still cant understand why dhe code blows up in before run ,
    if other program environment this code will blow in run time ?
    like in delphi

    when i put the check out code i got work properly


    thanks again
     
    V.Tabakov, Dec 8, 2003
    #3
  4. Are you sure it is blowing up before runtime. It should be running up to
    that point and then giving you an error. If you check you would see that
    variables before this point are already set.
     
    Corey Scheich, Dec 8, 2003
    #4
  5. V.Tabakov

    TheTick Guest

    try using this:

    Set swApp = CreateObject("SldWorks.Application")

    to set your SW object.

    I run into trouble using the "As New SldWorks.SldWorks" method to set
    the application object
     
    TheTick, Dec 8, 2003
    #5
  6. V.Tabakov

    V.Tabakov Guest

    When i put the "IsEmpty(variable)" it become working
    I think it's something from the V. Basic
    it Maybe is doing some checks of the code before running it .
     
    V.Tabakov, Dec 9, 2003
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.