473,511 Members | 15,156 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can I make a Common Array Class and create a instance of the Common Array Class with Type of a new class

Dear All,

I have written a common array class which has insert, search and other
functions.

For Example (Code in VB.NET):

' Client Class
Public Class Client
Public ClientCode As String 'Key Field
Public ClientName As String
...
End Class

'Client Array Class - Similar to a Vector Class
Public Class ClientArray

Private _ArrayIn() As Client

'Inserts the value into the _ArrayIn()
Public Function Insert(ByVal value As Client) As Long
....
End Function

'Searches the array
Public Function Search(ByVal value As Client) As Long
' GetSearchKey - Use this function to get the value in the "_ArrayIn()"
and "value" and compare
....
End Function

' Gets the search key.
Private Function GetSearchKey(ByVal value As Client) As String
Return value.ClientCode
End Function

End Class

Similary I have many classes like the Client Class, Say
' Scrip Class
Public Class Scrip
Public ScripCode As Integer 'Key Field
Public ScripName As String
Public Exchange As Short
Public Symbol As String
Public Market As String
...
End Class

Instead of creating a ScripArray Class with the same functionality as the
ClientArray Class, Can I make a Common Array Class and create a instance of
the Common Array Class with Type as Client or Scrip?

Please help me out

--
Thanks and Regards,

Peri
Oct 16 '07 #1
9 1405
List<Clientand List<Scrip>
or
Collection<Clientand Collection<Script>

job done
(don't ask me what the VB.NET syntax is; you cross-posted to a C#
ng...)

Marc
Oct 16 '07 #2
Dear Marc,

If I use a list of a collection then I cannot write my own insert, search,
resize funtionalities. I would like to create my own insert/search and also
need to implement similar to a list or a collection.

"Marc Gravell" <ma**********@gmail.comwrote in message
news:%2******************@TK2MSFTNGP05.phx.gbl...
List<Clientand List<Scrip>
or
Collection<Clientand Collection<Script>

job done
(don't ask me what the VB.NET syntax is; you cross-posted to a C# ng...)

Marc


Oct 16 '07 #3
Dear Marc,

If I use a list of a collection then I cannot write my own insert, search,
resize funtionalities. I would like to create my own insert/search and also
need to implement similar to a list or a collection.

"Marc Gravell" <ma**********@gmail.comwrote in message
news:%2******************@TK2MSFTNGP05.phx.gbl...
List<Clientand List<Scrip>
or
Collection<Clientand Collection<Script>

job done
(don't ask me what the VB.NET syntax is; you cross-posted to a C# ng...)

Marc



Oct 16 '07 #4
Peri wrote:
If I use a list of a collection then I cannot write my own insert, search,
resize funtionalities. I would like to create my own insert/search and also
need to implement similar to a list or a collection.
Why not?

What about List<T>/Collection<Tdoesn't do what you're looking for?

Chris.
Oct 16 '07 #5
Dear Chris,

In My code, if you see in the common array which I have written I have
declared a variable called "Private _ArrayIn() As Client" and methods like
"Public Function Search(ByVal value As Client) As Long" which has "Client"
has a type. Instead of "Client", If I need to have it as "Scrip" then how do
I do this?

I hope what you are telling me is: In another class where we are
implementing this client/scrip array, you are asking me to put
"Dim clientArrayList As New List(Of Client)"

The Code:
----------
'Client Array Class - Similar to a Vector Class
Public Class ClientArray

Private _ArrayIn() As CLIENT

'Inserts the value into the _ArrayIn()
Public Function Insert(ByVal value As Client) As Long
....
End Function

'Searches the array
Public Function Search(ByVal value As CLIENT) As Long
' GetSearchKey - Use this function to get the value in the "_ArrayIn()"
and "value" and compare
....
End Function

' Gets the search key.
Private Function GetSearchKey(ByVal value As CLIENT) As STRING
Return value.CLIENTCODE
End Function

End Class

Thanks and Regards,

Peri

"Chris Shepherd" <ch**@nospam.chsh.cawrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Peri wrote:
>If I use a list of a collection then I cannot write my own insert,
search,
resize funtionalities. I would like to create my own insert/search and
also
need to implement similar to a list or a collection.

Why not?

What about List<T>/Collection<Tdoesn't do what you're looking for?

Chris.

Oct 16 '07 #6
Public Function Search(ByVal value As Client) As Long
What does that return? The index of the item? In which case
..IndexOf(T) is already implemented in both List<Tand Collection<T>.

In the more general sense with generics, you simply have (using C#
syntax, but same is possible in VB.NET):

public class SomeClass<T{
public int SomeMethod(T someArgument) {...}
}

Marc
Oct 16 '07 #7
On Oct 16, 1:58 pm, "Peri" <P...@discussions.microsoft.comwrote:
In My code, if you see in the common array which I have written I have
declared a variable called "Private _ArrayIn() As Client" and methods like
"Public Function Search(ByVal value As Client) As Long" which has "Client"
has a type. Instead of "Client", If I need to have it as "Scrip" then how do
I do this?
You need to use generics. However, if you're writing VB.NET code you'd
be a lot better asking in a VB group than a C# one.

Jon

Oct 16 '07 #8
On Oct 16, 7:58 am, "Peri" <P...@discussions.microsoft.comwrote:
>
I hope what you are telling me is: In another class where we are
implementing this client/scrip array, you are asking me to put
"Dim clientArrayList As New List(Of Client)"
If a List(Of Client) does not suit your needs, you can try to make
your own class generic. Something like this:

'Client Array Class - Similar to a Vector Class
Public Class Array(Of T)

Private _ArrayIn() As T

'Inserts the value into the _ArrayIn()
Public Function Insert(ByVal value As T) As Long
....
End Function

'Searches the array
Public Function Search(ByVal value As T) As Long
' GetSearchKey - Use this function to get the value in the
"_ArrayIn()"
and "value" and compare
....
End Function

' Gets the search key.
Private Function GetSearchKey(ByVal value As T) As String
Return value.ClientCode
End Function

End Class

Then you can declare and instance of this class like this:

Dim MyClientArray as New Array(Of Client)

or

Dim MyScripArray As new Array(Of Scrip)

or whatever.

You see if this can suit your needs.

Chris

Oct 16 '07 #9
Thanks Chris,

But the GetSearchKey is not working since it returns Return value.ClientCode
(This is only for Client), If scrip then it should be Return
value.ScripCode.

Is there a way to implement this?

Thanks and Regards,

Peri

"Chris Dunaway" <du******@gmail.comwrote in message
news:11**********************@z24g2000prh.googlegr oups.com...
On Oct 16, 7:58 am, "Peri" <P...@discussions.microsoft.comwrote:
>>
I hope what you are telling me is: In another class where we are
implementing this client/scrip array, you are asking me to put
"Dim clientArrayList As New List(Of Client)"

If a List(Of Client) does not suit your needs, you can try to make
your own class generic. Something like this:

'Client Array Class - Similar to a Vector Class
Public Class Array(Of T)

Private _ArrayIn() As T

'Inserts the value into the _ArrayIn()
Public Function Insert(ByVal value As T) As Long
....
End Function

'Searches the array
Public Function Search(ByVal value As T) As Long
' GetSearchKey - Use this function to get the value in the
"_ArrayIn()"
and "value" and compare
....
End Function

' Gets the search key.
Private Function GetSearchKey(ByVal value As T) As String
Return value.ClientCode
End Function

End Class

Then you can declare and instance of this class like this:

Dim MyClientArray as New Array(Of Client)

or

Dim MyScripArray As new Array(Of Scrip)

or whatever.

You see if this can suit your needs.

Chris

Oct 17 '07 #10

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

Similar topics

2
10841
by: Phil... | last post by:
I am trying to figure out how to create an array that contains objects and not references to objects. I know how to do the latter, but not the former. Any help is appreciated. I have the...
12
3273
by: Steven T. Hatton | last post by:
This is something I've been looking at because it is central to a currently broken part of the KDevelop new application wizard. I'm not complaining about it being broken, It's a CVS images. ...
1
6588
by: Taiwo | last post by:
I generated a Typed Dataset class including a base64Binary column. This column was specified as a .NET type of Byte() in the class that was auto-generated. I set the value of this property to New...
6
4843
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
3
2483
by: john | last post by:
I am VERY new to C++ (1st semester) put not so new to coding and programming (SQL, VB, etc). We are learning about classes. I have a program that needs to call many instances (i think this is...
19
2411
by: zzw8206262001 | last post by:
Hi,I find a way to make javescript more like c++ or pyhon There is the sample code: function Father(self) //every contructor may have "self" argument { self=self?self:this; ...
0
941
by: jeff.sharkfinn | last post by:
I'm trying to create a pointer to a class in form1.h button1 event handler. It should be simple... but no. This example is as simple as I can make: Form1.h (produced with the designer containing...
9
1494
by: Peri | last post by:
Dear All, I have written a common array class which has insert, search and other functions. For Example (Code in VB.NET): ' Client Class Public Class Client Public ClientCode As String ...
3
6105
by: raylopez99 | last post by:
I suspect the answer to this question is that it's impossible, but how do I make the below code work, at the point where it breaks (marked below). See error CS0411 This is the complete code. ...
1
1169
by: nuffnough | last post by:
I have defined two classes with one common field (called code) and several different fields. In class A there is only one instance of any given code as all items are individual. In class B, there...
0
7251
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
7430
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7089
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
5673
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
5072
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
4743
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
3217
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1581
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
790
muto222
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.