title: Pascal's Triangle with Gray's theory
body: <p>I am trying to create Pascal's Triangle with VB. </p>
  
  <p>Here's my code (It uses Gray's Theroy) :</p>
  
  <pre><code>Dim input As Integer = Val(TextBox1.Text)
  Dim rownumber As Integer = 0
  Dim columnumber As Integer = 1
  Dim x As Integer = 1
  
  Do Until rownumber = input
    Do Until rownumber = columnumber
      Label2.Text = 1
      If rownumber = 0 Then
        x = 1
        Label2.Text = x &amp; " "
      Else
        x = x * ((Math.Abs(rownumber - columnumber)) / (columnumber))
        columnumber = columnumber + 1
        Label2.Text = Label2.Text &amp; " " &amp; x &amp; " "
      End If
    Loop
    columnumber = 1
    rownumber = rownumber + 1
    Label2.Text = x &amp; vbNewLine
  Loop
  </code></pre>
  
  <p>Another Idea, here I am using factorials (through a function) then incrememnting the values of the row and column.. Here's the output: </p>
  
  <pre><code>1
  1 2
  0 1 3
  0 0 1 4
  0 0 0 1 5
  0 0 0 0 1 6
  </code></pre>
  
  <p>And the code:</p>
  
  <pre><code>Public Class Form1
  
  Function factorial(ByVal n As Long)
    If (n &lt;= 0) Then
      factorial = 1
    Else
      factorial = n * factorial(n - 1)
    End If
  End Function
  
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Label2.Text = Nothing
    Dim input As Integer = Val(TextBox1.Text)
  
    Dim n As Integer
    Dim r As Integer
    Dim c As Integer
    Dim rnum, cnum As Integer
  
    For rnum = 0 To input Step +1
      For cnum = 1 To (rnum + 1) Step +1
        c = factorial(cnum) / (factorial(rnum) * factorial(cnum - rnum))
        Label2.Text = Label2.Text &amp; " " &amp; c &amp; " "
      Next
      Label2.Text = Label2.Text &amp; vbCrLf
    Next
  End Sub
  </code></pre>
  
  <p>End Class</p>