473,394 Members | 2,020 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,394 software developers and data experts.

Problem with ArrayList

I have defined a Class called EntSor (see code ) with a procedure Sub
Définit which assign the values of this class.

Then I have defined an Arraylist with
Dim colEntSor As New ArrayList()

The following code assign the values of the last lign to all elements of the
collection:

EntSor.Définit("PAAE", "bar", 0, True) : colEntSor.Add(EntSor)

EntSor.Définit("TAAE", "°C", 0, True) : colEntSor.Add(EntSor)

EntSor.Définit("QAAE", "kg/s", 0, True) : colEntSor.Add(EntSor)

EntSor.Définit("XVAE", "%", 0, True) : colEntSor.Add(EntSor)

What is wrong ?

Thanks

Bernard

==============================================

Public Class EntSor

Private mNomVal As String

Private mNomUnit As String

Private mDonnées As Boolean

Private mValeur As Decimal

Public Property NomVal() As String

Get

Return mNomVal

End Get

Set(ByVal Value As String)

mNomVal = Value

End Set

End Property

Public Property NomUnit() As String

Get

Return mNomUnit

End Get

Set(ByVal Value As String)

mNomUnit = Value

End Set

End Property

Public Property Données() As Boolean

Get

Return mDonnées

End Get

Set(ByVal Value As Boolean)

mDonnées = Value

End Set

End Property

Public Property Valeur() As Decimal

Get

Return mValeur

End Get

Set(ByVal Value As Decimal)

mValeur = Value

End Set

End Property

Public Sub Définit(ByVal sNomVal As String, _

ByVal sNomunité As String, _

ByVal dVal As Decimal, _

ByVal bDonnées As Boolean)

With Me

..NomVal = sNomVal

..NomUnit = sNomunité

..Valeur = dVal

..Données = bDonnées

End With

End Sub

End Class
--
Bernard Bourée
be*****@bouree.net
Nov 21 '05 #1
2 1224

"Bernard Bourée" <be*****@bouree.net> wrote
I have defined a Class called EntSor (see code ) with a procedure Sub
Difinit which assign the values of this class.

Then I have defined an Arraylist with
Dim colEntSor As New ArrayList()

The following code assign the values of the last lign to all elements of the
collection:

EntSor.Difinit("PAAE", "bar", 0, True) : colEntSor.Add(EntSor)
EntSor.Difinit("TAAE", "0C", 0, True) : colEntSor.Add(EntSor)
EntSor.Difinit("QAAE", "kg/s", 0, True) : colEntSor.Add(EntSor)
EntSor.Difinit("XVAE", "%", 0, True) : colEntSor.Add(EntSor)

What is wrong ?


You are adding the exact same object to the list. When you want
different objects (or when you want to create an object) you have
to use the New keyword. Your code does not use New at all
so you are adding the same object 4 times.

Add a public sub called New to your class that accepts all the
same parameters as Difinit, then use it like:

colEntSor.Add(New EntSor("PAAE", "bar", 0, True))
colEntSor.Add(New EntSor("TAAE", "0C", 0, True))
colEntSor.Add(New EntSor("QAAE", "kg/s", 0, True))
colEntSor.Add(New EntSor("XVAE", "%", 0, True))

To support the syntax:

Dim EntSorA As New EntSor

You would have to also add a sub called New that accepts no
parameters (This one is added by default, if you do not declare
a New sub yourself VB adds a parameter-less constructor for you).

When you define a New sub that uses parameters, VB skips adding
the parameter-less one, so you have to add that back yourself.

HTH
LFS

Nov 21 '05 #2
Not sure what you are trying to do exactly. If you are trying to instantiate
the Entsor class, you should put your initialization variables in the class
using a Public New sub such as

Public Class Entsor

public New (mystring1 as string, mystring2 as string, myinteger as
integer, _
myBool as boolean)

'Do you Initialization here

end sub

End Class

Dim colEntSor As New ArrayList()

colEntsor.Add (New Entsor("PAAE", "bar", 0, True))
colEntsor.Add (New Entsor("TAAE", "°C", 0, True))
colEntsor.Add (New Entsor("QAAE", "kg/s", 0, True))
colEntsor.Add (New Entsor("XVAE", "%", 0, True))

Bottom line is that you have to create an instance of the class to add it to
an Arraylist or actually, to do anyting with it.

Hope this helps.

"Bernard Bourée" wrote:
I have defined a Class called EntSor (see code ) with a procedure Sub
Définit which assign the values of this class.

Then I have defined an Arraylist with
Dim colEntSor As New ArrayList()

The following code assign the values of the last lign to all elements of the
collection:

EntSor.Définit("PAAE", "bar", 0, True) : colEntSor.Add(EntSor)

EntSor.Définit("TAAE", "°C", 0, True) : colEntSor.Add(EntSor)

EntSor.Définit("QAAE", "kg/s", 0, True) : colEntSor.Add(EntSor)

EntSor.Définit("XVAE", "%", 0, True) : colEntSor.Add(EntSor)

What is wrong ?

Thanks

Bernard

==============================================

Public Class EntSor

Private mNomVal As String

Private mNomUnit As String

Private mDonnées As Boolean

Private mValeur As Decimal

Public Property NomVal() As String

Get

Return mNomVal

End Get

Set(ByVal Value As String)

mNomVal = Value

End Set

End Property

Public Property NomUnit() As String

Get

Return mNomUnit

End Get

Set(ByVal Value As String)

mNomUnit = Value

End Set

End Property

Public Property Données() As Boolean

Get

Return mDonnées

End Get

Set(ByVal Value As Boolean)

mDonnées = Value

End Set

End Property

Public Property Valeur() As Decimal

Get

Return mValeur

End Get

Set(ByVal Value As Decimal)

mValeur = Value

End Set

End Property

Public Sub Définit(ByVal sNomVal As String, _

ByVal sNomunité As String, _

ByVal dVal As Decimal, _

ByVal bDonnées As Boolean)

With Me

..NomVal = sNomVal

..NomUnit = sNomunité

..Valeur = dVal

..Données = bDonnées

End With

End Sub

End Class
--
Bernard Bourée
be*****@bouree.net

Nov 21 '05 #3

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

Similar topics

2
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell...
2
by: xmail123 | last post by:
In a web service I am using a SqlDataReader to retrieve the information to populate an ArrayList. public ArrayList ReadHistory(int ItemPK) { SDrdr = SDcmd.ExecuteReader(); ArrayList AL = new...
14
by: Sharon | last post by:
Hi all. I have an ArrayList and sometimes while enumerating through, i get an exception because another thread has added to the ArrayList. To solve this problem, i lock the enumeration, passing...
4
by: Stephen | last post by:
I have the following code working in order to create an array list and populate a datagrid however everytime i click my button the first item in the array and the first row in the datagrid are...
0
by: Marcus Kwok | last post by:
I am having a weird problem with my DataGrid that is bound to an ArrayList. My situation is as follows: I have two DataGrids on a modal form. The top grid populates an ArrayList from a file,...
2
by: Jarod | last post by:
Hey I change backColor of linkButton in my Page_Load: lbDoSth.BackColor = Color.Red; But I have multiView on this page. On one of the views I have detailsView. When I add a new row a set...
3
by: Arjen | last post by:
Hi, I have a public class 'settings' with a public static void 'loadsettings'. Inside 'loadsettings' I go to public static 'loadpagesettings'. Inside this function I have a problem. 1. I...
12
by: garyusenet | last post by:
I have had no replies to my previous post so perhaps I didn't write it good enough. Please excuse new thread but i wanted to break from the last thread hopefully this thread will be better. ...
6
by: thanigaimani83 | last post by:
Hi guys. i can explain for my doubt with example.see.my table have multiple type of employee details like as Mangemment,Programmer,Designers,Accountants,ContractEmployees.Each type of department...
2
by: Johan Öhrn | last post by:
Hi, I'm working with an asp.net 2.0 application. The application I'm working with come with it's own assemblies which calls out to code in my assembly. It may call out to my code during a...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
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.