Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Public Class Form1

Dim no1, no2, result As Integer


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

You might also like