Advertisement
Guest User

Untitled

a guest
May 29th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. Public Class Form1
  2. Private Sub Command1_Click()
  3. Dim n As Integer 'Number of rows
  4. Dim i, j As Integer 'Counters
  5. n = Val(TextBox1.Text)
  6. For i = 0 To n - 1
  7. 'Label1.Text += (Space(n - i)) add this if label is not centered
  8. For j = 0 To i
  9. Label1.Text += (Trim(Str(nCr(i, j))) + " ")
  10.  
  11. Next j
  12. Label1.Text += vbNewLine
  13. Next i
  14. End Sub
  15. Private Function nCr(ByVal n As Integer, ByVal r As Integer) As Long
  16. If (n = r) Then
  17. nCr = 1
  18. Else
  19. nCr = Factorial(n) / (Factorial(n - r) * Factorial(r))
  20. End If
  21. End Function
  22.  
  23. Private Function Factorial(ByVal n As Integer) As Long
  24. Dim i As Integer
  25. Factorial = 1
  26. If n <> 0 Then
  27. For i = 2 To n
  28. Factorial = Factorial * i
  29. Next i
  30. End If
  31. End Function
  32.  
  33. Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
  34. Label1.Text = Nothing
  35. If Val(TextBox1.Text) > 20 Then
  36. Label1.Text = "(Number between 1 and 20)"
  37. ElseIf Val(TextBox1.Text) < 1 Then
  38. Label1.Text = "(Number between 1 and 20)"
  39. Else
  40. Command1_Click()
  41. End If
  42.  
  43. End Sub
  44.  
  45. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  46.  
  47. End Sub
  48. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement