Re: add numbers in file



Hi Glenn,

The OP is a student trying to get you to help him with homework.

We have an "unwritten convention" of providing assistance without actually
providing code.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"glenn" <ghan***@xxxxxxxxxxxxxxxxxx> wrote in message
news:emTqcM1RFHA.508@xxxxxxxxxxxxxxxxxxxxxxx
>I don't understand really what you are having trouble with. If you have a
> variable holding your cost field and I assume it would be a string
> variable
> you just call the Convert function like I said to convert it to a number.
>
> string myvar;
> myvar = fieldfromfile;
> double item;
> double total = 0;
>
> item = Convert.ToDouble( myvar );
> total += item;
>
> at the end you will have total that will contain the total amount of items
> in teh file...
>
> Your questions and examples are not really shedding much light on exactly
> what you are doing so if this doesn't answer you question then maybe
> someone
> else can help you better...
>
> good luck,
>
> glenn
>
>
> "microsoft.news.com" <CSharpCoder> wrote in message
> news:OBgmwi0RFHA.4028@xxxxxxxxxxxxxxxxxxxxxxx
>> Im reading the file fine, its the adding up the column I need help with.
>> I'm reading the file and inserting the data into a table. but now i need
> to
>> Total the sale price column and insert that into a new column
>> "glenn" <ghan***@xxxxxxxxxxxxxxxxxx> wrote in message
>> news:elDape0RFHA.1396@xxxxxxxxxxxxxxxxxxxxxxx
>> > Here are the very basics to get you started
>> > this will open a file with specified path and name of settings.txt
>> > StreamReader sr1 = File.OpenText( path + \\settings.txt);
>> > String input;
>> > //read through file and retreive info
>> > string st = "";
>> > while ((input=sr1.ReadLine())!=null)
>> > {
>> > st = input;
>> > from here you just need to parse the string value held in st to look
>> > for
>> > your field. I don't know what to tell you here, if its a space
> delimited
>> > field then its really easy as all you have to do is give it a start and
>> end
>> > location through the use of the st.substring function to grab what you
>> need.
>> > Then to do the cast to the double for the purposes of adding up your
>> values
>> > you can use the Convert function...
>> > }
>> >
>> > good luck,
>> >
>> > "microsoft.news.com" <CSharpCoder> wrote in message
>> > news:eCajtI0RFHA.580@xxxxxxxxxxxxxxxxxxxxxxx
>> > > since i never done this before, do you have a snippet or can you
>> > > point
>> me
>> > to
>> > > an example of this being done?
>> > >
>> > >
>> > > "glenn" <ghan***@xxxxxxxxxxxxxxxxxx> wrote in message
>> > > news:unD$NE0RFHA.248@xxxxxxxxxxxxxxxxxxxxxxx
>> > > > I'm not quite sure I follow the question here but I'll take a stab.
>> If
>> > I
>> > > > don't understand then I'm sorry.
>> > > >
>> > > > First of all there is no way to just ask the computer what the
>> > > > total
>> is
>> > > for
>> > > > column 2. However, you can write a function that will open the
>> > > > text
>> > file,
>> > > > read the file in one line at the time, grabbing the second column
> and
>> > > > converting it to a double or currency and then getting the next
> line.
>> > > >
>> > > > The text file is going to read in a string for each line that you
> will
>> > > have
>> > > > to parse to get to the 2nd column which looks quite easy if this is
>> the
>> > > > format of your file. But you still have a string when you parse it
> so
>> > you
>> > > > will need to cast it as a double or currency in order to add it up
> as
>> a
>> > > > number value.
>> > > >
>> > > > So from my point of view the problem is quite easily obtainable.
>> > > >
>> > > > Good luck,
>> > > >
>> > > > glenn
>> > > >
>> > > > "microsoft.news.com" <CSharpCoder> wrote in message
>> > > > news:uXICU0zRFHA.3052@xxxxxxxxxxxxxxxxxxxxxxx
>> > > > > I have a text file that has a column of numbers that i need to
>> > > > > add
>> to
>> > > get
>> > > > a
>> > > > > total of. Is there any way to add the number column in my text
> file?
>> > > > >
>> > > > > the text file looks like this:
>> > > > >
>> > > > > BMW 25,252.00 1/1/2005
>> > > > > BMW 19,000.00 3/15/2005
>> > > > >
>> > > > >
>> > > > > I need to add the money colum to get 44,252.00. is that even
>> possible
>> > > from
>> > > > a
>> > > > > text file?
>> > > > >
>> > > > >
>> > > >
>> > > >
>> > >
>> > >
>> >
>> >
>>
>>
>
>


.