Quantcast
Channel: Manufacturing DevBlog
Viewing all articles
Browse latest Browse all 518

Type mismatch error with VBA code in .NET

$
0
0

By Adam Nagy

When migrating VBA code to .NET there are a couple of things to watch out for and I hope all of them are listed in this document from Brian Ekins: http://modthemachine.typepad.com/files/VBAtoAddIn.pdf

When passing in arrays of variable sizes you need to initialize the variable - this is discussed in the above mentioned document under 5. Arrays of variable size are handled differently in VB.Net. Otherwise you'll get an error: Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))

So e.g. this VBA code:

Dim MyLine As DrawingCurveSegment = invApp.ActiveDocument.SelectSet(1) 
Dim pts(1) As Double
Dim gp() As Double
Dim md() As Double 
Dim pm() As Double 
Dim st() As SolutionNatureEnum
pts(0) = MyLine.EndPoint.x 
pts(1) = MyLine.EndPoint.y
Call MyLine.Parent.Evaluator2D.GetParamAtPoint(pts, gp, md, pm, st)

... would need to be converted to this in .NET:

Dim MyLine As DrawingCurveSegment = invApp.ActiveDocument.SelectSet(1) 
Dim pts(1) As Double
Dim gp() As Double = {}  
Dim md() As Double = {} 
Dim pm() As Double = {} 
Dim st() As SolutionNatureEnum = {}
pts(0) = MyLine.EndPoint.x 
pts(1) = MyLine.EndPoint.y
Call MyLine.Parent.Evaluator2D.GetParamAtPoint(pts, gp, md, pm, st)

 


Viewing all articles
Browse latest Browse all 518

Trending Articles