|
If you treat the $num as rows and the $letter as columns you can get a
table like:
A B C
_________
1 | 1 2 3
2 | 4 5 6
3 | 7 8 9
4 | 10 11 12
5 | 13 14 15
6 | 16 17 18
7 | 19 20 21
But because your letter ( or column ) count is not the same per row you
really need this:
A B C
_________
1 | 1 2 3
2 | 3 4 5
3 | 5 6 7
4 | 7 8 9
5 | 9 10 11
6 | 12 13 14
7 | 15 16 17
So the trick is for each row ( or num for you ) calculate the MAX number (
i.e. 6,C = 14 ) and offset based on the column ( i.e. column B is 1 less then C,
so subtract one giving 6,B = 13 ). Then one more thing is to treat a special
case for the row ( or num for you ) when row is 6 or higher.
here is pseudo code:
$maxLetter = "C"; # maximum number of columns
you need ideally
if ( $num > 5 ) {
$maxRowValue = $num * ( Asc( $maxLetter ) - 64 ) -
4;
} else {
$maxRowValue = $num * ( Asc( $maxLetter ) -
64 ) - ( num - 1 );
}
$result = $maxRowValue - ( Asc( $maxLetter ) - Asc( $maxLetter )
);
*Because I used 64, please make sure that your letter ( $maxLetter ) is
capital for the offest to work.
Is this cleaner, only 7 lines :-)
Hope this helps. Also it may be easier if you visualize how Excel turns "A"
into 1 and "AA" into 27. Thanks.
Donald Stephens
|
_______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
