473,372 Members | 971 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

How to write a component in VB .NET?


We have program Visual Basic .NET 2003 for construction of 3D-Graphics as a
surface z=f (x, y). From VB .NET 2003 we want to transfer coordinates of
this surface as myArrayVB (2000, 1) in myArrayVó [2000, 1] of VC++ .NET
2003 on scheme of "component - client". But there are error 1 and error 2.

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:

Imports System.Drawing 'Error 1. Namespace Drawing is absent.

Public Function myFunction1() As Array

Dim myArrayVB As Array = _

Array.CreateInstance(GetType(Single), 2000, 2)

'We write in myArrayVB coordinates of a surface:

. . .

Return myArrayVB

End Function

To apply procedures ScaleTransform and TranslateTransform, we need namespace
Drawing, however this namespace Drawing is absent in this project Class
Library.

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 by means 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();

float myArrayVC __gc[,] = new float __gc[2000, 1];

for (int i = 0; i <= 2000; i++)

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

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

}

The second error consists, that we cannot transfer coordinates of a surface
from myArrayVB in myArrayVC.

Inform, please, how in project VB to import the namespace Drawing, and how
to transfer myArrayVB in myArrayVC?

Beforehand many thanks for the answer, Dr. Zharkov V.A., Moscow, Russia.
Nov 20 '05 #1
7 2607
Dr. Zharkov,
In addition to the Imports statement, you need to use 'Project - Add
Reference' to actually reference the assembly where the System.Drawing
namespace is. What may be confusing is the assembly is called
System.Drawing.dll.

Remember Imports deals with namespaces, while Project - References deals
with assemblies. In order to use a namespace you need a reference to the
assembly first.

Hope this helps
Jay

"Dr. Zharkov" <va************@mtu-net.ru> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...

We have program Visual Basic .NET 2003 for construction of 3D-Graphics as a surface z=f (x, y). From VB .NET 2003 we want to transfer coordinates of
this surface as myArrayVB (2000, 1) in myArrayVó [2000, 1] of VC++ .NET
2003 on scheme of "component - client". But there are error 1 and error 2.
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:

Imports System.Drawing 'Error 1. Namespace Drawing is absent.

Public Function myFunction1() As Array

Dim myArrayVB As Array = _

Array.CreateInstance(GetType(Single), 2000, 2)

'We write in myArrayVB coordinates of a surface:

. . .

Return myArrayVB

End Function

To apply procedures ScaleTransform and TranslateTransform, we need namespace Drawing, however this namespace Drawing is absent in this project Class
Library.

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 by means 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();

float myArrayVC __gc[,] = new float __gc[2000, 1];

for (int i = 0; i <= 2000; i++)

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

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

}

The second error consists, that we cannot transfer coordinates of a surface from myArrayVB in myArrayVC.

Inform, please, how in project VB to import the namespace Drawing, and how
to transfer myArrayVB in myArrayVC?

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

Nov 20 '05 #2
Dear Mr. Jay B. Harlow.

Many thanks for your very valuable consultation, which has helped us to
solve the first problem. But there was a unsolved second problem.


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);//Err

}

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

Beforehand many thanks for the answer, Dr. Zharkov V.A., Moscow, Russia.
Nov 20 '05 #3
Dr. Zharkov,
Public Function myFunction1(ByVal N_i As Integer, _
ByVal N_j As Integer) As Array
Dim myArrayVB As Array = _
Array.CreateInstance(GetType(Single), N_i, N_j)
Why are you creating an array object directly? I would simple define the
array as Single().

Something like: Public Function myFunction1(ByVal N_i As Integer, _
ByVal N_j As Integer) As Single()
Dim myArrayVB(n_i - 1, n_j -1) As Single
Not array bounds in VB.NET are upper bounds, not number of elements, hence
the -1 in defining the array.

Are you getting the error in C++?

I have not use Managed C++ enough to actually answer why you cannot accept
the array.

Hope this helps
Jay

"Dr. Zharkov" <va************@mtu-net.ru> wrote in message
news:e6**************@TK2MSFTNGP10.phx.gbl... Dear Mr. Jay B. Harlow.

Many thanks for your very valuable consultation, which has helped us to
solve the first problem. But there was a unsolved second problem.


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);//Err

}

Inform, please, how to correct this code, to export myArrayVB in myArrayVC?
Beforehand many thanks for the answer, Dr. Zharkov V.A., Moscow, Russia.

Nov 20 '05 #4

Dear Mr. Jay B. Harlow.
Many thanks for your consultation. Following your guidelines, we have made:

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()

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.
Nov 20 '05 #5
Dr. Zharkov,
Inform, please, how to correct this code C++, to export myArrayVB in
myArrayVC?
I (still) have not use Managed C++ enough to actually answer why you cannot
use (accept) the array in C++.

Have you tried the microsoft.public.dotnet.languages.vc newsgroup? As that
is where all the Managed C++ developers hang out. Your VB.NET look fine.

Hope this helps
Jay

"Dr. Zharkov" <va************@mtu-net.ru> wrote in message
news:ea**************@TK2MSFTNGP11.phx.gbl...
Dear Mr. Jay B. Harlow.
Many thanks for your consultation. Following your guidelines, we have made:
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()

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.

Nov 20 '05 #6
"Dr. Zharkov" <va************@mtu-net.ru> wrote...

Well I'm reaching back more than a dozen years to my C/C++ work but here is
what I see...

No problems in the VB function.
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
No problem with the test in VB but... the way you have it written you are
having myFunction execute every time in the loop. It calls the method and
refills the value 1 into all the elements over and over again.
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

Your C++ test has two things which are "odd" the first is the same as with
your VB test that you call myFunction over and over which is just a waste of
time since the values never change. And you are declaring int i, j twice.
Once in the body of the procedure and again locally in the loop "int i = 0"
as far as I know CSharp complains about it with Option Strict on but I don't
know what C++ thinks about it.
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.

}


Other than that I don't see anything but then I didn't try writing it in
C++. It worked fine in CSharp. It would help to know what the error was.

I doubt that it will help much (if at all) but I often suggest that when one
is trying to solve a problem such as this that one eliminate all the
unnecessary code and reduce the problem to as small a package as possible.
That means moving some test code outside of the picturebox paint event. I
can pretty much guarantee that your problem is not related to the paint
event but my point is that you don't want to add "anything" that could
possibly be affecting it if you don't have to. Shrink the sample array to
something less than 2001 by 2... again it won't be the cause of the problem
but is doesn't help solve it either.

You can run simple tests using small functions, procedures and classes with
an array of 2 by 2 until you get it working. Once solved you resize the
array and move it back into the event handler.

I probably can't be of much help but what was the error message?

Tom Leylan


Nov 20 '05 #7
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.
Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Angelos Karantzalis | last post by:
Hi y'all, recently I've come across a situation where a web service needs to deal with an exception that might arise, originating from a COM+ component. It then returns an int value (please...
13
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
2
by: yaron | last post by:
Hi, I am writing a new networking component (dll). I have a few questions : 1. if i write it with .NET 2 , am i decreasing the number of potentials clients of my component ? 2. if the API to...
1
by: JohnSmith | last post by:
I suspect this is easy, but I have been stumped for a day trying to solve this.. I want to be able to have an unlimited number of aspx pages that all use the code in one class file. I want code...
2
by: Angie | last post by:
Hi, all, I’m newbie in .net, does any expert help me on the following questions? Thanks I have a DLL file wrote in Visual C++ 6.0 for sending message from one server to the other server, and...
10
by: kathy | last post by:
In VB.NET help file "Walkthrough: Creating COM Objects with Visual Basic .NET", It said: "Note The COM objects you generate with Visual Studio .NET cannot be used by other Visual Studio .NET...
0
by: Seth | last post by:
For some reason my service works fine except that it will create the file in my c drive, but will not write to the file. Sorry if this is a duplicate post, i have found some that ask the same...
88
by: Peter Olcott | last post by:
Cab you write code directly in the Common Intermediate language? I need to optimize a critical real-time function.
1
by: masterchike | last post by:
Hello All: I am really in a bind. I need to AJAXify a web page that contains a charting component (ILOG). Unfortunately, charting component uses document.write() to write some divs and tags so I...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.