Rod Perdido

Rod Perdido

  • NA
  • 7
  • 0

Problem using a VB6 OCX with a C#

Oct 31 2008 11:59 AM

Hi! I just started learning C# and stucked with this problem I encountered while accessing a VB6 OCX function from C#.

VB6 OCX Code is:


Public Function AreaByCoords(ByRef X() As Double, ByRef Y() As Double) As Double
    Dim L As Long
    Dim H As Long
    Dim I As Long
    Dim A As Double
   
    L = LBound(X)
    H = UBound(X)
    '
    If (H - L) < 3 Then Exit Function
    '
    A = 0
    For I = L To H
         A = A + Y(I) * IIf(I = H, X(L), X(I + 1)) - X(I) * IIf(I = H, Y(L), Y(I + 1))
    Next I
    AreaByCoords = A / 2
End Function

Public Function IAdd(A As Double, B As Double) As Double
    IAdd = A + B
End Function

 

C# Code:

private void btnTest_Click(object sender, EventArgs e)

{

double A;

double B;

double V;

double[] C;

C = new double[4];

C[0] = 1.542;

C[1] = 2.285;

C[2] = -2.234;

C[3] = -2.521;

double[] D;

D = new double[4];

D[0] = 1.642;

D[1] = -2.585;

D[2] = -2.234;

D[3] = 2.826;

A = 2.345;

B = 4.321;

V = axP1029.IAdd(ref A, ref B);                  //This runs ok!

MessageBox.Show(Convert.ToString(V));   //This runs ok!

V = axP1029.AreaByCoords (ref C, ref D);   //Error!

MessageBox.Show(Convert.ToString(V));

}

 

Running the above code, the following errors are displayed:

Error 1 The best overloaded method match for 'AxPo1030.AxP1029.AreaByCoords(ref System.Array, ref System.Array)' has some invalid arguments
Error 2 Argument '1': cannot convert from 'ref double[]' to 'ref System.Array'
Error 3 Argument '2': cannot convert from 'ref double[]' to 'ref System.Array'

Any idea how to set this right? All suggestions are much appreciated. Thank you in anticipation.

 

 


Answers (5)