Storing info from textfiles into arrays... HELP! 
Author Message
 Storing info from textfiles into arrays... HELP!

Hi,
I'm doing some payroll system in delphi5 Pascal, so far i have sorted it
to store information on employee numbers, names, and hourly rates
(integer, string(25), and real variables) in a text file in the format
Number
Name
Hourly rate
for 20 employees.

The next file stores month, week number, employee number, and hours
worked (all integer values) for the 20 employees on one line
Month number    Week number     Employee number    Hours worked

From this i then have to store information from the first file and store
the details in a suitable data structure using one or more
arrays...      I haven't got a clue how can anyone point me in the right
direction?

if you would like a copy of the program to see please message me at

thanks!



Wed, 18 Jun 1902 08:00:00 GMT  
 Storing info from textfiles into arrays... HELP!
On Sun, 12 Nov 2000 13:35:41 +0000, "paul.cannon1"

Quote:

>Hi,
>I'm doing some payroll system in delphi5 pascal, so far i have sorted it
>to store information on employee numbers, names, and hourly rates
>(integer, string(25), and real variables) in a text file in the format
>Number
>Name
>Hourly rate
>for 20 employees.

>The next file stores month, week number, employee number, and hours
>worked (all integer values) for the 20 employees on one line
>Month number    Week number     Employee number    Hours worked

>From this i then have to store information from the first file and store
>the details in a suitable data structure using one or more
>arrays...      I haven't got a clue how can anyone point me in the right
>direction?

>if you would like a copy of the program to see please message me at

>thanks!

The way I would do this in Borland/Turbo Pascal is to assign ALL your
variables to a type of record. Store these on disk as a file of
reccords. When reading these records, remember the first record number
is 0. I would place these in an array of records [0..19].

You can do your sorting based on any field conveniently using another
array which stores the indexes of the previous array in sorted order.

If you need to make changes in any of the fields, the records can be
accessed (using SEEK) from disk (and stored again)in random order.

Skeleton Example:
TYPE
Employee = RECORD
    Number : Integer;
    Name : String[25];
    rate : Real;
    month : Integer;
........... and so on
End;

VAR
single:Employee;
all:Array[0..19] of single;
f:File of single;   {random access file}
indx, len:Integer;

.....................
Begin
     Assign(f, 'myfile.dat');
     Rewrite(f);
...................... making the file
     enter data for single--  single.Number :=  etc.
     Write(f, single); {stores whole records sequentially from 0}
     {keep up with len 0..}
....................... reading the file
     Reset(f);
     For indx := 0 to len Do Read(f, all[indx]);
     {all records are now in the array}

If you need to append the file, use SEEK to find the end because
APPEND does not work.



Wed, 18 Jun 1902 08:00:00 GMT  
 Storing info from textfiles into arrays... HELP!

airnews.net> of Sun, 12 Nov 2000 12:19:15 seen in

Quote:
>On Sun, 12 Nov 2000 13:35:41 +0000, "paul.cannon1"

>>I'm doing some payroll system in delphi5 pascal, so far i have sorted it
> ...

>The way I would do this in Borland/Turbo Pascal is to assign ALL your
>variables to a type of record. Store these on disk as a file of
> ...

Delphi text I/O handling is very much a superset of BP7, and this is a
Pascal newsgroup, not a Delphi one.  Pascal-based advice will be valid,
but may be far from optimum.

One thing is unnecessary within Borland's Pascal, bur is vital if the
data or code may be used in Delphi : records should be declared PACKED.

Omitting PACKED has no effect in Pascal; but if the code is moved to
Delphi the omission becomes serious, as Delphi does not by default pack
records - and the packing may vary between versions.

Also, the SizeOf some types differs between P & D - see my pas-types.htm

--

 <URL: http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
 <URL: http://www.merlyn.demon.co.uk/clpb-faq.txt> Pedt Scragg: c.l.p.b. mFAQ;
 <URL: ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Read an external TEXT files and store info in 2 Separate ARRAYS

2. Help In Putting Textfile in array for display

3. textfiles and arrays to procedures

4. Arrays & Textfiles

5. Arrays & Textfiles

6. How do I store info in exe-file

7. adding 2d array info to string grid on another form

8. Storing arrays in DBase IV

9. How to store dynamic array to memofield?

10. Storing in Arrays ASAP!

11. Q: storing large arrays

12. help with reading textfiles

 

 
Powered by phpBB® Forum Software