GetExistingFacets VBA 7 and VB.NET showsdifferent and fails in VB.net

GetExistingFacets VBA 7 and VB.NET showsdifferent and fails in VB.net

Anonymous
Not applicable
2,057 Views
6 Replies
Message 1 of 7

GetExistingFacets VBA 7 and VB.NET showsdifferent and fails in VB.net

Anonymous
Not applicable
SurfaceBody.GetExistingFacets( ToleranceIndex As Double, VertexCount As Long, FacetCount As Long, VertexCoordinates() As Double, NormalVectors() As Double, VertexIndices() As Long )

 The above is from Inventor programing Help. This works fine in VBA (Inventor 2014). But when I start using the same in VB.NET (VS 2012) all declaration as long shows as integer and fails on compiling. If I change to integer compile passes but fail on executing in Inventor 2014.

 

Please find the below snap shots for detail.

0 Likes
Accepted solutions (1)
2,058 Views
6 Replies
Replies (6)
Message 2 of 7

jdkriek
Advisor
Advisor

Indeed,

Long Holds signed 64-bit (8-byte) integers (Int64)

Integer Holds signed 32-bit (4-byte) integers (Int32)

 

However,


msdn.microsoft.com
If you are interfacing with components not written for the .NET Framework, for example Automation or COM objects, keep in mind that Long has a different data width (32 bits) in other environments. If you are passing a 32-bit argument to such a component, declare it as Integer instead of Long in your new Visual Basic code.

Are you getting OverflowExceptions?

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


0 Likes
Message 3 of 7

Anonymous
Not applicable

Overflow exception is only in VBA 7 after declaring as long array and use an integer as array value. if use long value the function works fine.

Dim i As Integer

Dim lVertexCount As Long
            Dim lFacetCount As Long
            Dim adVertexCoords() As Double
            Dim adNormalVectors() As Double
            Dim alVertexIndices() As Long

            Call oBody.GetExistingFacets(dFacettol, lVertexCount, lFacetCount, adVertexCoords, adNormalVectors, alVertexIndices)

For i = 0 To lVertexCount - 1 'this gives overflow

For j = 0 To lVertexCount - 1 'this works fine (j as Long)

 

0 Likes
Message 4 of 7

Anonymous
Not applicable

Please find attached error detail

0 Likes
Message 5 of 7

Anonymous
Not applicable

Requesting a Solution from Autodesk to solve this issue !!!!!

0 Likes
Message 6 of 7

ekinsb
Alumni
Alumni
Accepted solution

Although they are very similar, VB.Net does have some big differences when compared to VBA.  There's nothing to be fixed in Inventor in this case, it's just a matter of knowing how to use VB.Net.  There are a few things to be aware of when converting VBA to VB.Net that could come into play in this case.

 

  1. Use Integer instead of Long.  This was already discussed.
  2. Be aware that the first index of an array is aways zero.  A lot of VBA code will have declared arrays like:

     Dim stuff(1 to 10) As Double

 

3. You need to initialize arrays before they can be passed to a method.  I think this is what's causing you problems now.  For example, instead of:

 

    Dim adVertexCoords() As Double

 

    you need to do this in VB.NET

 

    Dim adVertexCoords() As Double = {}

 

I took the ZHeightColors VBA sample from the API help and converted it to run in VB.Net.  The code for the function is attached.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 7 of 7

Anonymous
Not applicable

Thanks Brian. Thanks a lot to helping.

0 Likes