V Basic or SldWorks API Error

Dec 06, 2003 5 Replies

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


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-

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

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.

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

swfeat.GetTypeName

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 .

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required