Hello everyone. I'll try to get to the point as quick as possible. I have a form that has a textbox, an OpenFileDialog control and two command buttons. One command button, the "Next" button, takes you to the next form but only after you use the "Browse" to find the text file. The browse button, after finding the text file will use a StreamReader to get the data from the file. The text file contains text and numbers but the numbers will have to be converted before making the calculation (ROI). I was thinking that streaming the data into the "List" would be the best way to go and then I could access the data according to it's index number. Does this make sense so far If so, am I correct in my thinking With the assumption that I am correct how would I use StreamReader to read all data in the text file until it reaches the end of the text file, put it into an array and make it so that I can access the data in the List (collection ).
The help I am asking for will hopefully have some examples but not completely give away the answer because I need to learn as much as possible as fast as possible. My biggest problem is that I end up confusing myself as I work along on the project (not school related). Thank you for any help! :)
-Kimo

Stream data in and calculate
Alepodrakoulas
BenSisson
MikeMinsk
Company
Code Profit Invested
DHBO 153.69 25.89
FTHY 34.78 24.98
OPUI 45.90 12.67
I was planning on streaming them into the List as strings and after accessing the data by their index in the List I could then convert the decimals to actual decimals for calculation purposes and display company codes with the ROI percentage in a datagrid or something like that.
The full application will have to stream in text, dates, URLs, decimals and percentages from 3 Excel files and 1 tab delimited text file. A macro in an Access database then finishes the ROI reports but this application is supposed to replace that way of creating the ROI reports by running the calculations through a SQL database, then taking that data and creating a formatted Excel spreadsheet and writing the data into it and finally saving the report with the clients 4 letter code, report type and the date range of the report.
I hope that wasn't "too" much information! :) Thank you for you help!
-Kimo
Delusion7
LAE2
Exactly what list or collection to use depends a bit what the data looks like. Can you describe or give a short sample on how the data looks like and what you need to calculate.
An ArrayList, StringCollection or a generic List<> might all suite you. Depending on the "key"of the data a Hasttable or Dictionary<> might be better.
ArrayList list = new ArrayList();
//StringCollection list = new StringCollection();
//List<string> list = new List<string>(); //.NET 2.0 only
//Hashtable dict = new Hashtable();
//Dictionary<int, string> dict = new Dictionary<int, string>(); //.NET 2.0 only
while(false == stream.EndOfStream)
{
line = stream.ReadLine();
list.Add(line);
//split line into key and value
//dict.Add(key, value);
}
If you have some more details on what you want to achieve I should be able to be more precise.
dct-val
Thank you for your time. The methods you have provided I know and understand. What I am specifically having problems with is streaming the data into a "List" (Collection ) so that I may access the indexes within the "List" (Collection ) and run the calculations from the data that way. For the most part I understand the syntax for a "List" but I am having problems figuring out how to stream the data from the text file directly into the "List" if that is possible. Thank you once again. :)
-Kimo
Lampkin
To help clearify a bit more after using the OpenFileDialog to get the text file the data is read into the list immediately. The "Next" button opens the next form, if the calculations work correctly. If so then the next form displays the ROI results from the calculations either in a "Rich Text Box" or a Datagrid, etc. Do I have the right idea
private
void cmdYList_Click(object sender, EventArgs e) if (ofdList.ShowDialog() == DialogResult.OK) StreamReader textIn = new StreamReader(ofdList.FileName); string ylFileName = System.IO.Path.GetFileName(ofdList.FileName);txtList.Text = ylFileName;
List<string> list = new List<string>(); //.NET 2.0 only while (false == textIn.EndOfStream) list.Add(textIn.ReadLine());}