On Oct 7, 2005, at 11:28 AM, Nick Brutyn wrote:
> hey
>
> i want to have a for statement in rails
> that can count the size of an array and use that number to get it
> values
>
>
> for( $j = 1; $j < count($beschrijving); $j++)
> {
> $beschrijvingTekst = $beschrijving[$j];
> }
>
> i have somehting like this for creating tables in fpdf
>
> #Kolom koppen
> @header =
[''Employee'',''Location'',''Duration'',''Start'',''Stop'']
> #Kolom breedtes
> @w=[50,50,40,40,40]
> #Kolomkoppen afprinten
>
>
> for head in @header
> pdf.Cell(@w[head],h, @head, 1,0,''C'')
> end
>
> i need the have the position of array header (head) to get the values
> out of array w
>
Try one of the following (assuming I''m understanding what you want):
# In the block head will be an element of @header, idx will be its index
@header.each_with_index { |head, idx| pdf.Cell(@w[idx], h, head, 1, 0,
''C'') }
Or
# In the block head will be, e.g., [50, ''Employee'']
@w.zip(@header).each { |head| pdf.Cell(head[0], h, head[1], 1, 0,
''C'') }
--
Scott Barron
Lunchbox Software
http://lunchboxsoftware.com
http://lunchroom.lunchboxsoftware.com
http://rubyi.st