an array of records within an array of records 
Author Message
 an array of records within an array of records

I am trying to create a jukebox program, and part of it involves having
an array of records for the cd, and within
that cd array have an array of records for the cd track. Firstly
displaying each cd and having the user choose a
cd, then displaying all tracks for that particular cd. I have
encountered two problems so far

1. I cant supply an index to the record array of cd tracks only the
index to the cd's, I am using the syntax of

    put(new_cd_array(index).track(loop_index).title);

index, being the index passed to the procedure the code is in,
representing the cd selected, and loop-index
representing a loop, to loop round displaying all the fields in the
tracks record array. Which I thought would work,
however it refuses to operate correctly. And now I have removed it from
the program I cant tell you what errors it
was displaying. I have also tried every variation as well, but I still
cant make it work.

2. Also how do you pre initialise the tracks array of records, the only
way I could think of is:

new_cd_array(1):=("title1--------------","artist1-------------",("title1--------------","artist1-------------",12.34,1),1);

new_cd_array(1):=("title1--------------","artist1-------------",("title2--------------","artist2-------------",12.34,2),1);

new_cd_array(1):=("title1--------------","artist1-------------",("title3--------------","artist3-------------",12.34,3),1);

Surely this is a long-winded way, isn't there something easier?

I don't want to be spoon fed the answers, but some helpful advice would
be nice.

Thanks R Mullen

---------------------------------------------

I have also included the record initialisation in the declarations
section as well as some of the program code:

Declaration section:

          type cd_track is
          record
                  title:string(1..20);
                  artist:string(1..20);
                  playlength:float:=0.00;
                  id:integer;
          end record;

  type cd_track_array is array(positive range<>) of cd_track;
  new_cd_track:cd_track_array(1..3);

          type cd is
          record
                  title:string(1..20);
                  artist:string(1..20);
                  id:cd_track;
                  tracks:integer;
          end record;

  type cd_array is array(positive range<>) of cd;
  new_cd_array:cd_array(1..3);

main program:

  procedure individual_cd(index:in integer) is
          begin
            for loop_index in 1..3 loop
                    put(new_cd_array(index).title);

                    put(new_cd_array(index).track(loop_index).title);

                    put(new_cd_array(index).artist);
                    put(new_cd_array(index).playlength);
                    put(new_cd_array(index).id);
            end loop;
                    put_line("  ");
                    put_line("Select a track by choosing its ID.");
                    put_line("  ");

            end individual_cd;

  Text IO and Float IO are both in use, and I am using the latest
version of the GNAT compiler.



Sat, 30 Sep 2000 03:00:00 GMT  
 an array of records within an array of records

Yes, record initialization is a little long-winded, and is even
more so when you make it more readable by adding in the field names:

  x := (CD=> 190, title => to_20 ("White Album"), author => to_20("Beatles"));

Although it is long-winded, giving the field names can be very helpful
if you come back to the data years later and wonder what is being
filled in.

It also helps when you are trying to pick out which of hundreds of data
files is the input file for the juke box, as opposed to the financial
program, the business process model, or the satellite location program.



Sun, 01 Oct 2000 03:00:00 GMT  
 an array of records within an array of records


Quote:

>Yes, record initialization is a little long-winded, and is even
>more so when you make it more readable by adding in the field names:

>  x := (CD=> 190, title => to_20 ("White Album"), author => to_20("Beatles"));

>Although it is long-winded, giving the field names can be very helpful
>if you come back to the data years later and wonder what is being
>filled in.

Here's a case where using the identity operator as a constructor can
improve things:

x := (CD => 190, title => +"White Album", author => +"Beatles");

In general, when you have a subprogram (or record type) that has parameters
(components) of the same type (as you do here, with type String), then it's
safer to use named notation, so you don't accidently assign the wrong
value.



Sun, 01 Oct 2000 03:00:00 GMT  
 an array of records within an array of records

Quote:
> identity operator

What's that in this case?  The operator that maps type String to
whatever other type to_20 maps strings to?


Mon, 02 Oct 2000 03:00:00 GMT  
 an array of records within an array of records


Quote:

>> identity operator
>What's that in this case?  The operator that maps type String to
>whatever other type to_20 maps strings to?

Yes:

function "+" (R : String) return <some type>  renames To_20;



Mon, 02 Oct 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. An array of records within an array of records (Still a problem)

2. Add Child Record Within New Parent Record form.

3. Arrays within UDT Arrays - Uggh!

4. Inserting Arrays within an Array in Tcl...

5. Problems using an array within another array

6. Array Record Variables

7. Record Array

8. How to build an array of 700,000 records?

9. Adding records from an array

10. Get record in an array

11. Dynamic Array of Record

12. Arrays of Records and Sequential File Reading

 

 
Powered by phpBB® Forum Software