help with file part 2 lol

Ok I have it saveing now! but I want to take all the total values from the file at the end and add them all together to give me the overall total for that day! be grate if you can help! i tryed looking at prvios codings for this but nothing that could help me!

Comments

  • : Ok I have it saveing now! but I want to take all the total values from the file at the end and add them all together to give me the overall total for that day! be grate if you can help! i tryed looking at prvios codings for this but nothing that could help me!
    :
    It looks like you're already writing the stuff you need to do that into the file. Just write a while not(eof(yourfile)) loop and read thru it, adding up the values. If this file is going to be continually added to, you're gonna have to add a date somewhere. You might want to consider redoing your data structure and using a record.

    I would further suggest that you take some time to develop a spec for what you're wanting to do. Nobody wants to do that, but it's really the best way to do a project. OK, off the soapbox.............
  • : : Ok I have it saveing now! but I want to take all the total values from the file at the end and add them all together to give me the overall total for that day! be grate if you can help! i tryed looking at prvios codings for this but nothing that could help me!
    : :
    : It looks like you're already writing the stuff you need to do that into the file. Just write a while not(eof(yourfile)) loop and read thru it, adding up the values. If this file is going to be continually added to, you're gonna have to add a date somewhere. You might want to consider redoing your data structure and using a record.
    :
    : I would further suggest that you take some time to develop a spec for what you're wanting to do. Nobody wants to do that, but it's really the best way to do a project. OK, off the soapbox.............
    :
    Ok am not to hot on records lol! ok will this work

    type
    totalofday =
    record
    price : integer;
    end;
    so when I call it up to add them together! every purchuse that has been ented the price of it will be atomaticly save it to memory??

  • : : : Ok I have it saveing now! but I want to take all the total values from the file at the end and add them all together to give me the overall total for that day! be grate if you can help! i tryed looking at prvios codings for this but nothing that could help me!
    : : :
    : : It looks like you're already writing the stuff you need to do that into the file. Just write a while not(eof(yourfile)) loop and read thru it, adding up the values. If this file is going to be continually added to, you're gonna have to add a date somewhere. You might want to consider redoing your data structure and using a record.
    : :
    : : I would further suggest that you take some time to develop a spec for what you're wanting to do. Nobody wants to do that, but it's really the best way to do a project. OK, off the soapbox.............
    : :
    : Ok am not to hot on records lol! ok will this work
    :
    : type
    : totalofday =
    : record
    : price : integer;
    : end;
    : so when I call it up to add them together! every purchuse that has been ented the price of it will be atomaticly save it to memory??

    It will. Try using a record like this:
    [code]
    TYPE
    ProductType = record
    Name : String[50]; { or whatever max size you will need }
    Price : Real;
    Amount : Integer;
    End;

    VAR
    Products : Array[0..99] Of ProductType;
    NumProducts : Byte; { To hold how many records are being used }
    F : File;

    [/code]

    then when you want to load/save your data, just use:
    [code]

    PROCEDURE LoadData;
    Begin
    Assign(F,'Products.Dat'); {$I-} Reset(F,1); {$I+}
    If IOResult <> 0 Then
    Begin
    WriteLn('File Does Not Exist!');
    Exit;
    End;
    BlockRead(NumProducts,SizeOf(NumProducts));
    For X := 0 to NumProducts Do
    BlockRead(Products[X],SizeOf(Products[X]));
    Close(F);
    End;

    PROCEDURE SaveData;
    Begin
    Assign(F,'Products.Dat'); Rewrite(F,1);
    BlockWrite(NumProducts,SizeOf(NumProducts));
    For X := 0 to NumProducts Do
    BlockWrite(Products[X],SizeOf(Products[X]));
    Close(F);
    End;
    [/code]
    The file will be stored with a BYTE at the start telling how many products are in the file and then all the records after that.
    The RECORD TYPE can be changed for whatever data you need and the code will still work. Just don't expect it to read an older file once you change it.

    Phat Nat
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories