Hello,
I succeeded to pass an integer from c# to VBA from a C# .NET DLL.
just changing to code like this I expected to pass an array instead of an integer value but:
C#
namespace csharp
{
class inter
{
public int passArray ( int[] xx) ....
.........
and in VBA
Dim fromCS as csharp.inter
Set fromCS = new csharp,inter
Dim i as Integer
Dim a() as Integer
i = csharp.passArray ( a() )
of course it doesn't work, would be too simple!
Does anyone have experience with this problem?
thanks an regards from Linz/Austria
Siegfried
Loading
FroglegPosted May 13, 2011, 4:26 PM
namespace PassInts
{
public class changeInts
{
public int passInteger(int i)
{
return i + 11;
}
public int[] passArray(int[]i)
{
int[] k = new int [i.Length];
for (int ii = 0; ii < i.Length; ii++)
{
k[ii] =i[ii] + 11;
}
return k;
}
}
}
vb form code
Imports PassInts
Public Class Form1
Public passInts As New changeInts
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer = passInts.passInteger(5)
ListBox1.Items.Clear()
ListBox1.Items.Add(i)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim k() As Integer = {5, 4, 2, 3, 7}
Dim i() As Integer = passInts.passArray(k)
ListBox1.Items.Clear()
For Each j As Integer In i
ListBox1.Items.Add(j)
Next
End Sub
End Class
sigPosted May 13, 2011, 3:38 PM
this was my first ideas too,
but this doesn't work either, so I tried to pass it as a reference parameter.
Siegfried
FroglegPosted May 13, 2011, 3:29 PM
Dim a() as Integer
i = csharp.passArray ( a() )