MASTERJI DEGREE & P.
G COLLEGE
HUNTER ROAD
BCA III YEAR V SEM VISUAL PROGRAMMING LAB MANUAL
1. Print a table of numbers from 1 to 15 and their squares and cubes.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Clear()
TextBox1.AppendText("Value; of; Squares And Cubes" & Environment.NewLine)
Dim i As Integer = 1
While i <= 15
TextBox1.AppendText(i & "; " & i * i & "; " & i * i * i & Environment.NewLine)
i += 1
End While
End Sub
End Class
DEPARTMENT OF COMPUTERS MASTERJI DEGREE & P.G COLLEGE
2. Print the Largest of Three Numbers?
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim a As Integer
Dim b As Integer
Dim c As Integer
a = Val(TextBox1.Text)
b = Val(TextBox2.Text)
c = Val(TextBox3.Text)
If a > b AndAlso a > c Then
MessageBox.Show("A is largest")
ElseIf c > a AndAlso c > b Then
MessageBox.Show("C is largest")
Else
MessageBox.Show("B is largest")
End If
End Sub
End Class
DEPARTMENT OF COMPUTERS MASTERJI DEGREE & P.G COLLEGE
3.Find the Factorial of a Number “N”.
Public Class Form1
Private i As Integer
Private sum As Integer
Private Sub Form1_Click(sender As Object, e As EventArgs) Handles MyBase.Click
TextBox1.TabIndex = 1
sum = 1
End Sub
Public Sub Fact(i As Integer)
If i >= 1 Then
sum *= i
Fact(i - 1)
Else
TextBox2.Text = sum.ToString()
End If
End Sub
Private Sub TextBox1_LostFocus(sender As Object, e As EventArgs) Handles
TextBox1.LostFocus
If Integer.TryParse(TextBox1.Text, i) Then
sum = 1 ' Reset sum before starting the factorial calculation
Fact(i)
Else
DEPARTMENT OF COMPUTERS MASTERJI DEGREE & P.G COLLEGE
MessageBox.Show("Please enter a valid integer.")
End If
End Sub
End Class
4.Enter a list of positive numbers terminated by zero. Find the sum and average of
these numbers.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
TextBox1.Text = (Val(TextBox1.Text).ToString())
If (Val(TextBox1.Text)) > 0 Then
ListBox1.Items.Add(TextBox1.Text)
End If
TextBox2.Text = Val(TextBox1.Text) + Val( TextBox2.Text).ToString
TextBox1.Clear()
TextBox3.Text = ListBox1.Items.Count.ToString()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles
Button2.Click
If Val(TextBox3.Text) > 0 Then
TextBox4.Text = (Val(TextBox2.Text) /
Val(TextBox3.Text).ToString())
Else
MessageBox.Show("NO ITEM TO CALCULATETHE AVERAGE")
End If
DEPARTMENT OF COMPUTERS MASTERJI DEGREE & P.G COLLEGE
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles
Button3.Click
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
ListBox1.Items.Clear()
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles
Button4.Click
Me.Close()
End Sub
End Class
5. A Person Deposit Rs.1000 in a fixed account yielding 5% interest. Complete the
amount in the account at the end of each year for N years.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
DEPARTMENT OF COMPUTERS MASTERJI DEGREE & P.G COLLEGE
If RadioButton1.Checked Then
Form2.Show()
Else
MessageBox.Show("Only Fixed A/c are Available")
End If
End Sub
End Class
Public Class Form2
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim p As Double
Dim t As Double
Dim r As Double
p = Val(TextBox1.Text)
t = Val(TextBox2.Text)
r = Val(TextBox3.Text)
TextBox4.Text = ((p * t * r) / 100).ToString()
End Sub
End Class
6. Read N numbers. Count the number of negative numbers, positive
numbers and zeros in the list.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim a As Integer
a = Val(TextBox1.Text)
If a > 0 Then
DEPARTMENT OF COMPUTERS MASTERJI DEGREE & P.G COLLEGE
ListBox1.Items.Add(TextBox1.Text)
TextBox1.Clear()
ElseIf a < 0 Then
ListBox2.Items.Add(TextBox1.Text)
TextBox1.Clear()
Else
ListBox3.Items.Add(TextBox1.Text)
TextBox1.Clear()
End If
TextBox2.Text = ListBox1.Items.Count.ToString()
TextBox3.Text = ListBox2.Items.Count.ToString()
TextBox4.Text = ListBox3.Items.Count.ToString()
End Sub
End Class
7. Read n numbers. Count the number of negative numbers, positive numbers and
zeros in the list (use Arrays).
DEPARTMENT OF COMPUTERS MASTERJI DEGREE & P.G COLLEGE
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim a(9) As Integer
Dim i, pos, neg, zer As Integer
pos = 0
neg = 0
zer = 0
For i = 0 To 9
a(i) = Val(InputBox("Enter element no:" & i))
Next
For i = 0 To 9
If a(i) = 0 Then
zer += 1
ElseIf a(i) < 0 Then
neg += 1
ElseIf a(i) > 0 Then
pos += 1
End If
Next
Label1.Text = "Positive Numbers = " & pos
Label2.Text = "Negative Numbers = " & neg
Label3.Text = "Zeroes = " & zer
End Sub
End Class
DEPARTMENT OF COMPUTERS MASTERJI DEGREE & P.G COLLEGE
8. Read a single dimension array. Find the sum and average of these
numbers.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim a(9) As Integer
Dim i, sum As Integer
Dim avg As Double
sum = 0
For i = 0 To 9
a(i) = Val(InputBox("Enter array element no:" & i))
Next
TextBox1.AppendText("The Array Elements are:" & Environment.NewLine)
For i = 0 To 9
TextBox1.AppendText(a(i).ToString() & Environment.NewLine)
Next
For i = 0 To 9
sum += a(i)
Next
avg = sum / 10
TextBox1.AppendText("Sum of array elements: " & sum.ToString() &
Environment.NewLine)
DEPARTMENT OF COMPUTERS MASTERJI DEGREE & P.G COLLEGE
TextBox1.AppendText("Avg of array elements: " & avg.ToString() &
Environment.NewLine)
End Sub
End Class
9. Read a Two dimension array. Find the sum of the 2D Array.
Public Class Form1
Private Sub Form1_Click(sender As Object, e As EventArgs) Handles MyBase.Click
Dim i, j As Integer
Dim a(2, 2) As Integer
Dim b(2, 2) As Integer
Dim c(2, 2) As Integer
For i = 0 To 2
For j = 0 To 2
a(i, j) = Val(InputBox("Enter First Array Elements (" & i & "," & j & "):"))
Next
Next
For i = 0 To 2
For j = 0 To 2
DEPARTMENT OF COMPUTERS MASTERJI DEGREE & P.G COLLEGE
b(i, j) = Val(InputBox("Enter Second Array Elements (" & i & "," & j & "):"))
Next
Next
TextBox1.AppendText("First Matrix Values:" & Environment.NewLine)
For i = 0 To 2
For j = 0 To 2
TextBox1.AppendText(a(i, j).ToString() & vbTab)
Next
TextBox1.AppendText(Environment.NewLine)
Next
TextBox1.AppendText("Second Matrix Values:" & Environment.NewLine)
For i = 0 To 2
For j = 0 To 2
TextBox1.AppendText(b(i, j).ToString() & vbTab)
Next
TextBox1.AppendText(Environment.NewLine)
Next
For i = 0 To 2
For j = 0 To 2
c(i, j) = a(i, j) + b(i, j)
Next
Next
TextBox1.AppendText("Sum of 2D Arrays:" & Environment.NewLine)
For i = 0 To 2
For j = 0 To 2
TextBox1.AppendText(c(i, j).ToString() & vbTab)
Next
TextBox1.AppendText(Environment.NewLine)
Next
End Sub
End Class
DEPARTMENT OF COMPUTERS MASTERJI DEGREE & P.G COLLEGE