473,395 Members | 1,466 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,395 software developers and data experts.

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 1485
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
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
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
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
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
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
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
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
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
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. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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
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...

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.