473,480 Members | 1,833 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2611
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
7926
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
9580
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
1134
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
337
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
1268
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
3153
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
1647
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
7949
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
1266
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
7049
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6912
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6744
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6981
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5348
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4488
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3000
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
565
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.