List Info

Thread: C-Sharp (C#) Group: 2d dynamic arrays




C-Sharp (C#) Group: 2d dynamic arrays
country flaguser name
United States
2007-05-06 11:38:37
Hi,

I'm new here and to c# and have been looking for some help
for days.

Here's what I'm trying to do:

I have a process running on a remote computer that dumps
some report
information into a txt file. This computer is remote via
DUN, so I
have a poller that grabs that file and dumps it locally. I
am trying
to write a console app to read that file and make it fancy
in excel
(charts, etc.).

Here's the basic format of the file:

REPORT TYPE1
COL1  COL2
11       TYPEA
33       TYPEB
44       TYPEB

REPORT TYPE2
COL1  COL2
492      COMPLETE
300      INCOMPLETE

REPORT TYPE3
COL1   COL2
1          500
2          300
3          200
4          150
5          100
6          100
7          100
8          100
9          100
10         100


The problem I'm having is that the different report types
may have
more or less values. What I've done so far is this:

                    TextReader tr = new
StreamReader(report.FullName);

                    while (tr.Peek() > -1)
                    {


                        read = (tr.ReadLine());
                        Array Line = read.Split(new char[] {
't' });
                        foreach (string value in Line)
                        {
                            if (value != "")
                            {
                                report[row, col] = value;
                            }
                            else
                            {
                                //pass report array to
excel
                            }
                            col += 1;

                        }
                        row += 1;
                        col = 0;

                }

I'd like to be able to define a 2d dynamic array, fill it as
needed,
then pass it to my write to excel function. The only way I
can think
to do this is to fill a static array (there is a max
length(300) and
max width(4) of the text file), then write a separate
function to read
the static array and copy out the individual reports to
another static
array and pass the second array to the write to excel
function.

This sounds overly complicated as in vbscript I could just
ReDim the
array to a larger size as needed. I've looked at arraylist,
but
apparently it's only for one dimensional arrays. Any ideas
or
suggestions would be greatly appreciated!!

-scott


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharpgooglegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribegooglegroups.com
For more options, visit this group at http://g
roups.google.com/group/C_Sharp?hl=en
-~----------~----~----~----~------~----~------~--~---


C-Sharp (C#) Group: Re: 2d dynamic arrays
user name
2007-05-06 15:20:04
A list is probably the way to go here. You can use a class or struct to hold other types of data, add the class or struct objects to an array list. You can also use an ArrayList of ArrayLists that gives you the functionality you need. One ArrayList holds all of the ArrayLists that hold the values from each line of the file.... (does that make since?). Anyway, that keeps you from needing to redefine arrays. For dynamic fields, a list of lists that represent each row is probably the easiest approach.

----

ArrayLists rows = new ArrayList();

// read in a line
ArrayList row = new ArrayList()

row.Add(val1);
row.Add(val2);

rows.Add(row);





--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharpgooglegroups.com
To unsubscribe from this group, send email to C_Sharp-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/C_Sharp?hl=en
-~----------~----~----~----~------~----~------~--~---

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )