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(E ntSor)
EntSor.Définit( "TAAE", "°C", 0, True) : colEntSor.Add(E ntSor)
EntSor.Définit( "QAAE", "kg/s", 0, True) : colEntSor.Add(E ntSor)
EntSor.Définit( "XVAE", "%", 0, True) : colEntSor.Add(E ntSor)
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 2 1243
"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(E ntSor) EntSor.Difinit( "TAAE", "0C", 0, True) : colEntSor.Add(E ntSor) EntSor.Difinit( "QAAE", "kg/s", 0, True) : colEntSor.Add(E ntSor) EntSor.Difinit( "XVAE", "%", 0, True) : colEntSor.Add(E ntSor)
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(N ew EntSor("PAAE", "bar", 0, True))
colEntSor.Add(N ew EntSor("TAAE", "0C", 0, True))
colEntSor.Add(N ew EntSor("QAAE", "kg/s", 0, True))
colEntSor.Add(N ew 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
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(E ntSor)
EntSor.Définit ("TAAE", "°C", 0, True) : colEntSor.Add(E ntSor)
EntSor.Définit ("QAAE", "kg/s", 0, True) : colEntSor.Add(E ntSor)
EntSor.Définit ("XVAE", "%", 0, True) : colEntSor.Add(E ntSor)
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 (multi-select without modifier keys). I
got that working fine, but I also wanted to keep rows selected after a sort,
which I do by storing the row's id in an arraylist. The idea was to do the
sort and then go back and re-select the rows with that...
|
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 ArrayList();
while(SDrdr.Read())
{
|
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 the ArrayList instance to the lock.
But i still get the same exception.
Thanks for your help.
Sharon.
|
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 overwritten. I think this is some
sort of post back problem but i can't seem to figure out how to solve it. Can
someone help me with this please.
private ArrayList addresses;
private void Page_Load(object sender, System.EventArgs e)
{
|
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, then the datagrid is bound to it, and it works
fine. The bottom DataGrid is bound to a different ArrayList that holds
the same type as the first ArrayList. Both DataGrids are set to
Read-Only.
The user selects a row from the top DataGrid, then...
| |
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 Visible = false on this detailsView. And rebound
appropriate gridView. Then I press the button and I have exception:
Failed to load viewstate. The control tree into which viewstate is being
loaded must match the control tree that was used to save...
|
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 create an arraylist
2. Load the arraylist with items from the cache
|
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.
Very simple. I would like to create listviewitem's for display in a
listview control.
The listview items need to contain properties from Internet Explorer
windows i've managed to collect into an arraylist.
|
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 having many employee details.Now my drop down list having types of department names like that above types of department names..if i select any one type of department data wil be display in gridview format .gridview data column as employee...
|
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 request, i.e. I click on a link in the
application or when the application does some background processing in a
different thread.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |