This document contains code for a form with buttons that call various functions:
1) A swap function that swaps two numbers passed by value, and a swapref function that swaps two numbers passed by reference.
2) A Fibonacci function that calculates Fibonacci numbers up to a limit.
3) A Reverse function that reverses an integer.
4) A factorial function that calculates the factorial of a number recursively.
This document contains code for a form with buttons that call various functions:
1) A swap function that swaps two numbers passed by value, and a swapref function that swaps two numbers passed by reference.
2) A Fibonacci function that calculates Fibonacci numbers up to a limit.
3) A Reverse function that reverses an integer.
4) A factorial function that calculates the factorial of a number recursively.
This document contains code for a form with buttons that call various functions:
1) A swap function that swaps two numbers passed by value, and a swapref function that swaps two numbers passed by reference.
2) A Fibonacci function that calculates Fibonacci numbers up to a limit.
3) A Reverse function that reverses an integer.
4) A factorial function that calculates the factorial of a number recursively.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click no1 = TextBox1.Text no2 = TextBox2.Text swap(no1, no2) MsgBox(" After swap call by value no1=" & no1 & " No2=" & no2) swapref(no1, no2) MsgBox(" After swap by call by reference no1=" & no1 & " No2=" & no2) End Sub Sub swap(ByVal x As Integer, ByVal y As Integer) Dim temp As Integer temp = x ' save the value of x x = y ' put y into x y = temp 'put temp into y End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
no1 = TextBox1.Text Fibonacci(no1) End Sub
Sub swapref(ByRef x As Integer, ByRef y As Integer)
Dim temp As Integer temp = x ' save the value of x x = y ' put y into x y = temp 'put temp into y End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim r As Integer TextBox2.Text = Reverse(r) End Sub
Sub Fibonacci(ByVal limit As Integer)
Dim n1 As Integer Dim n2 As Integer Dim result As String = "" n1 = 1 n2 = 1 result = n1 While n2 < limit result = result & " " & n2 n2 = n2 + n1 n1 = n2 - n1 End While MsgBox("Fibonacci =" & result) End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
no1 = TextBox1.Text TextBox2.Text = factorial(no1) End Sub
Public Function Reverse(rn As Integer)
Dim numbers = Val(TextBox1.Text) Dim result As Integer While numbers > 0 rn = numbers Mod 10 result = result * 10 + rn numbers = numbers \ 10 End While Reverse = result End Function
Function factorial(ByVal m As Integer) As Integer
If m = 0 Then Return 1 Else Return m * factorial(m - 1) End If End Function End Class