For Each????


Hi all

I've updated to .net  from vb6 today.

I'm just having trouble with a couple of macros to get the code working in the .net from vb6. 'For each' is being a bit sticky

Dim objFace As Face

Dim objEdge As Edge

objDocuments = objSE.Documents

'Open a file

Call objDocuments.Open(Filename:=ComponentsPath)

'Check that it is a sheet metal that is open

If objSE.ActiveDocumentType igSheetMetalDocument Then


       Exit Function

End If

objSheetDoc = objSE.ActiveDocument

'Select a faces that cross the XY plane

For Each objFace In objSheetDoc.Models(1).Body.FacesByRay(0, 0, 0, 0, 0, 1)        Err’s here

          For Each objEdge In objFace.Edges

         'Process linear edges in the found face.

                If objEdge.Geometry.Type = igLine Then

                      objVertex = objEdge.StartVertex

                       Exit For

              End If



     If Not objVertex Is Nothing Then Exit For


Object variable or With block variable not set.  objFace contains Nothing.What do you have to set it to before it is called in the 'For each' loop?

Cheers Snow


Posted by: Snow Mackenzie
Post date: 11/5/2008 11:27:17 AM


RE: For Each????


Hi All

Found the problem

I had to change the ...Models(1) to Models(0). I can't figure why as this code seeems simple enough as it worked fine in VB6.

I also found another one err in a 'For X =1 To TotalCount' loop. Where i had to change it to 'For  X=0 To TotalCount-1' to get it to work as well??? Any ideas???

When i used the Convert VB6 to .net Wiz The project worked ,but full of warnings.The code was about the same as the VB6 with all the 'For X stuff' the same.

Is there something in settings that i have to alter?






Posted by: Snow Mackenzie
Post date: 11/5/2008 9:19:22 PM