How to export an array from VB .NET in VC++ .NET?

  • Thread starter Thread starter Cor
  • Start date Start date
C

Cor

Hi Dr, Zharkov,

You can have a look what remoting can do for you, but if it will go I do not
know, this is a very special application.

I think, that in this cases the array is first written to disk and than
readed again.

Cor
 
Hi Pan Zharkov,

The VB.net part
\\\
Dim sw As New StreamWriter("TestFile.txt")
sw.Write(myArrayVB(2000, 2).ToString)
sw.Close()
///

Cor
 
We want to export myArrayVB (2000, 2) of VB .NET 2003 in myArrayVó [2000, 2]
of VC++ .NET 2003 on scheme "component - client". But there is an error.

For development of a component in VB .NET 2003 we make: File, New, Project,
Visual Basic Projects, Class Library, name of project: ComponentVB. We write
the code:



Public Function myFunction1(ByVal N_i As Integer, _

ByVal N_j As Integer) As Array



N_i = 2000

N_j = 2

Dim myArrayVB As Array = _

Array.CreateInstance(GetType(Single), N_i, N_j)



For ii As Integer = 0 To N_i - 1

For jj As Integer = 0 To N_j - 1

myArrayVB(ii, jj) = 1

Next

Next



Return myArrayVB(, )

End Function



For development of the client in VC++ .NET 2003 we make: File, New, Project,
Visual C++ Projects, (.NET), Windows Forms Application (.NET), name of
project: ClientVC. On Form1 we place control Panel (on which we want to
build a surface myArrayVB with the help of method DrawLine), and we write
the code:



#using <mscorlib.dll>

#using "Debug\ComponentVB.dll"



private:

System::Void panel1_Paint(System::Object * sender,

System::Windows::Forms::PaintEventArgs * e)

{

ComponentVB::Class1* myObject =

new ComponentVB::Class1();



int N_i = 2000;

int N_j = 2;

float myArrayVC __gc[,] = new float __gc[N_i, N_j];



for (int i = 0; i <= N_i - 1; i++)

for (int j = 0; j <= N_j - 1; j++)

myArrayVC[i, j] =

myArrayVC->SetValue(myObject->myFunction1(2000, 2), i, j);//Error.

}



Inform, please, how to correct this code, to export myArrayVB in myArrayVC?



Beforehand many thanks for the answer, Dr. Zharkov V.A., Moscow, Russia.
 
Dear Mr. Cor.

Many thanks for your answer.

Inform, please, what code writes on disk the myArrayVB(2000, 2) from VB .NET
2003,

and then copies myArrayVB(2000, 2) from disk on myArrayVC[2000][2] in VC++
..NET 2003?



Beforehand many thanks for the answer, Dr. Zharkov V.A., Moscow, Russia.
 
Hi Pan Zharkov,

I think the big problem is that it is for me totally unclear what you want
to archieve.
(I told you how to write the datapart from the array you showed to disk, but
do absolutly not understand what you want to do with it).

Are there two programs working parallel or serial?

Do you want transport data to them?

And what data, a part of the table or the complete table?

Cor
 
Hi Dr. Zharkov,

It is not easy, but I am afraid this goes to nothing,

I made a piece of program, a XML dataset that write the complete table to
disk.
My earlier sample did give you only one item as I asumed that was needed
from the table.

How you can read such a xml dataset in C++ I really do not know, so that you
can maybe ask as Jay B earlier adviced, ask in the VB group.

I did not tested, but it should make a dataset I think, but because I cannot
test it, I am not sure of that so you have to try it. When it is written to
disk, it should read as an XML file with in this sample 2 rows and 2001
items.

Private Sub PictureBox1_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) _
Handles PictureBox1.Paint
Dim ds As New DataSet
Dim dt As New DataTable("Zharkov")
Dim i, j As Integer
Dim N_x As Integer = 2000
Dim N_y As Integer = 1
For i = 0 To N_x
Dim dc As New DataColumn(Chr(i-tostring))
dc.DataType = System.Type.GetType("System.Single")
dc.GetType()
dt.Columns.Add(dc)
Next
Dim myObject As New ComponentVB.Class1
For i = 0 To N_x
Dim dr As DataRow
For j = 0 To N_y
dr = dt.NewRow
dr(i, j) = myObject.myFunction1(i, j)
Next
Next
ds.WriteXml("mypath")
///
End Sub
 
Cor,
How you can read such a xml dataset in C++ I really do not know, so that you
can maybe ask as Jay B earlier adviced, ask in the VB group.
Did you mean ask in the C++ group?

As he is asking in the VB group, and seems to have an answer for his C++
questions...

Jay
 
Doh!
As he is asking in the VB group, and seems to have an answer for his C++
questions...
That should be "and no-one seems to ahve an answer for his C++ questions"...

Jay
 
Hi Dr Zharkov,

So much to type, and then I would write VC and type VB.

Luckily Jay B showed it to me, I mean of course VC newsgroup for the C++
Question.

Thanks Jay.

Cor
 
Dear Mr. Cor.
Many thanks for your very valuable consultation. Now we know, how to export
an array from project VB in the file ("D:\MyDocs\MyTest.txt") and to read
out this array from the file in project VC++. However is impossible to us
export of an array from VB in VC++ on scheme "component - client".

We want to export myArrayVB (2000, 2) of VB .NET 2003 in myArrayVó [2000, 2]
of VC++ .NET 2003 on scheme "component - client".

For development of a component in VB .NET 2003 we make: File, New, Project,
Visual Basic Projects, Class Library, name of project: ComponentVB. We write
the code:



Public Function myFunction1()

Dim i, j As Integer

Dim N_x As Integer = 2000

Dim N_y As Integer = 1

Dim myArrayVB(N_x, N_y) As Single

For i = 0 To N_x

For j = 0 To N_y

myArrayVB(i, j) = 1

Next

Next

Return myArrayVB

End Function



For development of the client in VB .NET 2003 we make: File, New, Project,
Visual Basic Projects, Windows Application, name of project: ClientVB. On
Form1 we place control PictureBox. We add: Project, Add Reference,
ComponentVB.dll. And we write the code:



Private Sub PictureBox1_Paint(ByVal sender As Object, _

ByVal e As System.Windows.Forms.PaintEventArgs) _

Handles PictureBox1.Paint

Dim i, j As Integer

Dim N_x As Integer = 2000

Dim N_y As Integer = 1

Dim myArrayVB_Client(N_x, N_y) As Single

Dim myObject As New ComponentVB.Class1

For i = 0 To N_x

For j = 0 To N_y

myArrayVB_Client(i, j) = myObject.myFunction1(i, j)

Next

Next

MsgBox("myArrayVB_Client(0,0 ) = " _

& myArrayVB_Client(0, 0)) ' = 1, ok.

End Sub



Export of an array from VB in VB we have fulfilled without errors.



For development of the client in VC++ .NET 2003 we make: File, New, Project,
Visual C++ Projects, (.NET), Windows Forms Application (.NET), name of
project: ClientVC. On Form1 we place control PictureBox, and we write the
code:



#using <mscorlib.dll>

#using "Debug\ComponentVB.dll"



private:

System::Void pictureBox1_Paint(System::Object * sender,

System::Windows::Forms::PaintEventArgs * e)

{

ComponentVB::Class1* myObject = new ComponentVB::Class1();



int i, j;

int N_x = 2001;

int N_y = 2;

float myArrayVC __gc[,] = new float __gc[N_x, N_y];

for (int i = 0 ; i <= N_x - 1; i++)

for (int j = 0 ; j <= N_y - 1; j++)

myArrayVC[i, j] = myObject->myFunction1(i, j); //Error.

}



Inform, please, how to correct this code C++, to export myArrayVB in
myArrayVC?



Beforehand many thanks for the answer, Dr. Zharkov V.A., Moscow, Russia.
 
Dear Mr. Cor.

Many thanks for your kind consent to help us. We have a program on Visual
Basic 2003 for construction and management (rotation) of a surface z=f (x,
y). I have tried to copy this program on Visual C++ 2003 by change of syntax
of language, but I do not have not enough qualification. Therefore I have
decided, that is necessary in the project on Visual Basic screen coordinates
of a surface to write down in an array myArrayVB (i, j) and to pass this
array in the project on Visual C++ 2003. The first variant of export of an
array through recording on a hard disk you to us have told, for what we are
once again very grateful to you.

Now we want to try the second variant of export of myArrayVB (2000, 2) of VB
..NET 2003 in myArrayVó [2000, 2] of VC++ .NET 2003 on scheme "component -
client". But there is an error.

For development of a component in VB .NET 2003 we make: File, New, Project,
Visual Basic Projects, Class Library, name of project: ComponentVB. We write
the code:



Public Function myFunction1()

Dim i, j As Integer

Dim N_x As Integer = 2000

Dim N_y As Integer = 1

Dim myArrayVB(N_x, N_y) As Single

For i = 0 To N_x

For j = 0 To N_y

myArrayVB(i, j) = 1

Next

Next

Return myArrayVB

End Function



For development of the client in VB .NET 2003 we make: File, New, Project,
Visual Basic Projects, Windows Application, name of project: ClientVB. On
Form1 we place control PictureBox. We add: Project, Add Reference,
ComponentVB.dll. And we write the code:



Private Sub PictureBox1_Paint(ByVal sender As Object, _

ByVal e As System.Windows.Forms.PaintEventArgs) _

Handles PictureBox1.Paint

Dim i, j As Integer

Dim N_x As Integer = 2000

Dim N_y As Integer = 1

Dim myArrayVB_Client(N_x, N_y) As Single

Dim myObject As New ComponentVB.Class1

For i = 0 To N_x

For j = 0 To N_y

myArrayVB_Client(i, j) = myObject.myFunction1(i, j)

Next

Next

MsgBox("myArrayVB_Client(0,0 ) = " _

& myArrayVB_Client(0, 0)) ' = 1, ok.

End Sub



Export of an array from VB in VB we have fulfilled without errors.



For development of the client in VC++ .NET 2003 we make: File, New, Project,
Visual C++ Projects, (.NET), Windows Forms Application (.NET), name of
project: ClientVC. On Form1 we place control PictureBox (on which we want to
build a surface z=f(x,y) as myArrayVB with the help of method DrawLine), and
we write the code:



#using <mscorlib.dll>

#using "Debug\ComponentVB.dll"



private:

System::Void pictureBox1_Paint(System::Object * sender,

System::Windows::Forms::PaintEventArgs * e)

{

ComponentVB::Class1* myObject = new ComponentVB::Class1();



int i, j;

int N_x = 2001;

int N_y = 2;

float myArrayVC __gc[,] = new float __gc[N_x, N_y];

for (int i = 0 ; i <= N_x - 1; i++)

for (int j = 0 ; j <= N_y - 1; j++)

myArrayVC[i, j] = myObject->myFunction1(i, j); //Error.

}



Inform, please, how to correct this code, to export myArrayVB in myArrayVC?



Beforehand many thanks for the answer, Dr. Zharkov V.A., Moscow, Russia.
 
Dear Mr. Jay B. Harlow.

Dear Mr. Cor.

Many thanks for your help in the decision of my problems on export of an
array from Visual Basic in Visual C++. Mr. Cor has very much helped me to
write an array on a disk in project of VB and to read an array in project of
VC++. Mr. Jay B. Harlow has very much helped me to write correctly an array
as component of VB. Mr. Emad Barsoum from group : vc.libraries for 15.2.04
has very much helped me to write correctly a code for reading an array for
client of VC++ in the following kind:

int i, j;

int N_x = 2001;

int N_y = 2;

Array* myArray = (Array*)myObject->myFunction1();

float myArrayVC __gc[,] = new float __gc[N_x, N_y];

for (i = 0 ; i <= N_x - 1; i++)

for (j = 0 ; j <= N_y - 1; j++)

myArrayVC[i, j] =

System::Convert::ToSingle(myArray->GetValue(i,j));



Big many thanks. Dr. Zharkov V.A., Moscow, Russia.
 
Back
Top