The elements of Pascal's triangle are the statistical combination of the given row and column, if you consider Pascal's triangle as a right triangle.
1 2 1
1 3 3 1
1 4 6 4 1
Each element of Pascal's triangle is the result of nCr, where n is the row number, starting at 0, and r is the column number, also starting at 0. As far as I can tell, Combination is not a function in the Math library, but really it should be.
public static long Factorial(byte nValue)
long nFact = 1L;
// If nValue > 20, this will generate a numberic overflow, even using long.
if (nValue < 0)
else if (nValue < 2)
for (long i=nValue; i > 1; --i)
nFact *= i;
public static int Combination(int nSetSize, int nChosen)
int nCombo = 1;
if (nChosen > nSetSize-nChosen)
nLow = nChosen;
nLow = nSetSize - nChosen;
for (int i=nLow+1; i <= nSetSize; ++i)
nCombo *= i;
nCombo /= Factorial(nSetSize - nLow);
This code has not been tested, so there might be a bug or two in it.
There is also a good article on this stuff, including producing Pascal's triangle here.
Actually the sum of any row a Pascal's Triangle is 2^n, where n is the row number, starting at 0. The sum of all values above a certain row is (2^n)-1. So the sum of all values in row 5 is 2^5 = 32. The sum of all values above row 5 is 2^5 - 1 = 32-1 = 31.
For Each ctrl As Control In Me.Controls("pnlMainPanel").Controls
If ctrl.GetType Is GetType(System.Windows.Forms.Panel) Then
For Each subCtrl As Control In ctrl.Controls
If subCtrl.GetType Is GetType(System.Windows.Forms.TextBox) Then
If subCtrl.GetType Is ...