List vector

Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2007
Posts: 3
Reputation: spockenheit is an unknown quantity at this point 
Solved Threads: 0
spockenheit spockenheit is offline Offline
Newbie Poster

List vector

 
0
  #1
Dec 19th, 2007
How do I list the number of elements in a vector, i.e test : array[1..10] of string; ?
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 19
Reputation: Artmann is an unknown quantity at this point 
Solved Threads: 0
Artmann Artmann is offline Offline
Newbie Poster

Re: List vector

 
0
  #2
Dec 19th, 2007
I think it's something like this
  1.  
  2. program ??;
  3.  
  4. var test : array[0..4] of String;
  5. l : Integer;
  6.  
  7.  
  8. begin
  9.  
  10. a[0] := '1';
  11. a[1] := '2';
  12. a[2] := '3';
  13. a[3] := '4';
  14. a[4] := '5';
  15.  
  16.  
  17. writeLn('There are ',length(a),' elements in the array');
  18.  
  19. end.
-Signed Artmann
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: List vector

 
0
  #3
Dec 19th, 2007
length() returns the number of elements in an array.
low() returns the index of the first element.
high() returns the index of the last element.
setLength() changes the size of a dynamic array.
  1. var
  2. xs: array of integer;
  3. cntr: integer;
  4. begin
  5. setLength( xs, 5 );
  6. writeln( 'Please enter ', length( xs ), ' integers: ' );
  7. for cntr := low( xs ) to high( xs ) do read( xs[ cntr ] );
  8. end.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 913 | Replies: 2
Thread Tools Search this Thread



Tag cloud for Pascal and Delphi
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC