tables

  • Thread starter Thread starter RobcPettit
  • Start date Start date
R

RobcPettit

Hi, Ive built an application that gets live data every 5 secs and
sends it to excel. In excel Ive got 4 small tables (9x9), which I use
vba to sort the data and allocate to the correct table. This works
well, infact Im chuffed Ive managed to do this. The next stage is to
bypass excel altogether and have the data within the application
itself. Only I cant figure the best way to do it. Any ideas
appreciated. So far Ive thought of maybe 4 datagrids, the data bieng
saved on closing. Its important that I retain prev data. Or save the
data in a file, read this file into 4 arrays, work and update data
during session, then save data back to file on closing, or
periodically. Finnally a database os some sort.
Regards Robert
 
[...] In excel Ive got 4 small tables (9x9), which I use
vba to sort the data and allocate to the correct table. [...]
The next stage is to
bypass excel altogether and have the data within the application
itself.

In code, it seems like a single-dimensional array of 4 2-dimensional
arrays would be fine. For example, assuming your data is floating point
doubles:

double[][,] tables = new double[][,] { new double[9,9], new
double[9,9], new double[9,9], new double[9,9] };

There are lots of other ways to store the data as well. Which is truly
best depends somewhat on how you actually want to use the data.

I wouldn't use a Datagrid unless there was some specific functionality
in the Datagrid that you specifically needed. Just because you were
using Excel before, that doesn't mean that the data needs to be in any
sort of Excel-like object when it's entirely contained within the
application.

As far as saving goes, you have a variety of options, but one of the
simplest is to put the data in your applications settings and use the
Properties.Settings.Default class to read and write them. That way your
code only has to deal with the in-memory representation, and all of the
serialization is handled for you.

The array of doubles won't automatically serialize, so probably the best
thing to do there is write some custom code that writes to a
StringWriter based on a StringBuilder, and then save the resulting
string in the application settings. Then you can reverse the process,
using a StringReader to parse data from the string retrieved from the
application settings.

If you use XML, you can use the XmlWriter and XmlReader classes to
format the data as XML when saving and parse the XML when reading it
back in.

All of the above can work using StreamWriter and StreamReader with a
file instead.

Basically, once you've figured out what format in which you want to
store the data, you should be able to store that to a file or to the
application settings, however you prefer. You have a small amount of
data and there may be some benefit in leaving it human-readable, so IMHO
converting the data to text and saving it that way would work well. But
there's no requirement that you do it that way if you feel a different
format would work better (though, storing it as text does make the
application settings method easier).

Pete
 
Thankyou for your reply Pete. Very informative. Plenty for me to read
and learn. Should keep me bussy for a while.
Regards Robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top