V Basic or SldWorks API Error

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

Reply to
V.Tabakov
Loading thread data ...

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-

Reply to
Heikki Leivo

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

Reply to
V.Tabakov

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.

Reply to
Corey Scheich

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

Reply to
TheTick

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 .

Reply to
V.Tabakov

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.