Home All Groups Group Topic Archive Search About

Update Element in ArrayList Structure

Author
26 Jun 2005 12:43 AM
wg
I have worked on this for a while and have not been able to get it working.
I seem to be missing something. What I am attempting to do is get
information from a csv file such as: name (stirng), unit number (int),
address (int), value (int), etc. I created a structre to handle each
element. Since there is an unknown number of rows I have used an arraylist
to hold it. This works using the arraylist.add(structure).

The problem is that after loading I get information from an external device
tied to the serial port. As this information is recieved I would like to
update the value element in the arraylist. I did this in VB6 by using a UDT
the dynamic arrays. I have read that this should not be done in VB.NET, to
use the arraylist instead.


Any help would be greatly appriciated.

Thanks

wg

Author
26 Jun 2005 1:13 AM
Tom Shelton
On 2005-06-26, wg <w*@hotmail.com> wrote:
Show quoteHide quote
> I have worked on this for a while and have not been able to get it working.
> I seem to be missing something. What I am attempting to do is get
> information from a csv file such as: name (stirng), unit number (int),
> address (int), value (int), etc. I created a structre to handle each
> element. Since there is an unknown number of rows I have used an arraylist
> to hold it. This works using the arraylist.add(structure).
>
> The problem is that after loading I get information from an external device
> tied to the serial port. As this information is recieved I would like to
> update the value element in the arraylist. I did this in VB6 by using a UDT
> the dynamic arrays. I have read that this should not be done in VB.NET, to
> use the arraylist instead.
>
>
> Any help would be greatly appriciated.
>
> Thanks
>
> wg

wg... use a class in an arraylist.  Using a structure can be made to
work, but it is very inefficent.

--
Tom Shelton [MVP]
Author
26 Jun 2005 1:23 AM
Ken Tucker [MVP]
Hi,

Directcast(arraylist.item(number), YourStructureName).value = NewValue

Ken
-----------------
"wg" <w*@hotmail.com> wrote in message
news:oRmve.3267$wm.1578@bignews4.bellsouth.net...
I have worked on this for a while and have not been able to get it working.
I seem to be missing something. What I am attempting to do is get
information from a csv file such as: name (stirng), unit number (int),
address (int), value (int), etc. I created a structre to handle each
element. Since there is an unknown number of rows I have used an arraylist
to hold it. This works using the arraylist.add(structure).

The problem is that after loading I get information from an external device
tied to the serial port. As this information is recieved I would like to
update the value element in the arraylist. I did this in VB6 by using a UDT
the dynamic arrays. I have read that this should not be done in VB.NET, to
use the arraylist instead.


Any help would be greatly appriciated.

Thanks

wg
Author
26 Jun 2005 8:48 AM
Armin Zingler
"Ken Tucker [MVP]" <vb***@bellsouth.net> schrieb
> Directcast(arraylist.item(number), YourStructureName).value =
> NewValue

Doesn't work because the returned value is a value type.

Armin
Author
26 Jun 2005 10:38 AM
Herfried K. Wagner [MVP]
"Armin Zingler" <az.nospam@freenet.de> schrieb:
>> Directcast(arraylist.item(number), YourStructureName).value =
>> NewValue
>
> Doesn't work because the returned value is a value type.

You'll have to reassign the value to the item after changingt the copy, or
use a class instead of the structure ;-).

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
26 Jun 2005 6:45 AM
Cor Ligthert
WG,

You know that with OleDb you can in one time from a CSV make a dataset?

See this sample on our site
http://www.windowsformsdatagridhelp.info/default.aspx?ID=1b644f6b-aa01-49f6-bc1f-212f9e0de193

I hope this helps,

Cor
Author
26 Jun 2005 3:58 PM
Dennis
Thanks for the tip Cor.  I assume the row delimiter is a \ or can be anything
that the FMT=Delimited* is set to like the *.  Is this correct?
--
Dennis in Houston


Show quoteHide quote
"Cor Ligthert" wrote:

> WG,
>
> You know that with OleDb you can in one time from a CSV make a dataset?
>
> See this sample on our site
> http://www.windowsformsdatagridhelp.info/default.aspx?ID=1b644f6b-aa01-49f6-bc1f-212f9e0de193
>
> I hope this helps,
>
> Cor
>
>
>
Author
26 Jun 2005 8:48 AM
Armin Zingler
Show quote Hide quote
"wg" <w*@hotmail.com> schrieb
> I have worked on this for a while and have not been able to get it
> working. I seem to be missing something. What I am attempting to do
> is get information from a csv file such as: name (stirng), unit
> number (int), address (int), value (int), etc. I created a structre
> to handle each element. Since there is an unknown number of rows I
> have used an arraylist to hold it. This works using the
> arraylist.add(structure).
>
> The problem is that after loading I get information from an external
> device tied to the serial port. As this information is recieved I
> would like to update the value element in the arraylist. I did this
> in VB6 by using a UDT the dynamic arrays. I have read that this
> should not be done in VB.NET, to use the arraylist instead.


Value types added to an arraylist can not be changed. Retrieving the Item
always retruns a copy because it's a value type. As Tom wrote, use a class
instead.

Armin
Author
26 Jun 2005 10:39 AM
wg
I have attempted to use a class in the beginning but could never get it to
work right. Could someone give a quick example?


Thanks

wg


Show quoteHide quote
"wg" <w*@hotmail.com> wrote in message
news:oRmve.3267$wm.1578@bignews4.bellsouth.net...
>I have worked on this for a while and have not been able to get it working.
>I seem to be missing something. What I am attempting to do is get
>information from a csv file such as: name (stirng), unit number (int),
>address (int), value (int), etc. I created a structre to handle each
>element. Since there is an unknown number of rows I have used an arraylist
>to hold it. This works using the arraylist.add(structure).
>
> The problem is that after loading I get information from an external
> device tied to the serial port. As this information is recieved I would
> like to update the value element in the arraylist. I did this in VB6 by
> using a UDT the dynamic arrays. I have read that this should not be done
> in VB.NET, to use the arraylist instead.
>
>
> Any help would be greatly appriciated.
>
> Thanks
>
> wg
>