Sei sulla pagina 1di 7

Practical List BCCA[SEM-V]

Execution Program

Q1. Calculate the reverse of a number.

Module Module1
Sub Main()
Dim n, r As Integer
Console.Write("Enter a number:")
n = CInt(Console.ReadLine())
Console.Write("Reverse number is...:")
While n <> 0
r = n Mod 10
Console.Write(r)
n = n \ 10
End While
Console.ReadKey()
End Sub

End Module

Q2 To Check a given number is prime or unprimed.

Module Module1
Sub Main()
Dim num As Integer, i As Integer, count As Integer
Console.WriteLine("Enter a number:")
num = Console.ReadLine()
For i = 1 To num Step 1
If (num Mod i = 0) Then
count = count + 1
End If
Next
If count = 2 Then
Console.WriteLine("Number is prime")
Else
Console.WriteLine("Number is not prime")
End If
Console.ReadKey()
End Sub
End Module

Q3 To check Number is Palindrome or not


Module Module2
Sub Main()
Dim n, r, num, rev As Integer
rev = 0
Console.Write("Enter a number:")
n = CInt(Console.ReadLine())
num = n
While n <> 0
r = n Mod 10
rev = rev * 10 + r
n \= 10
End While
Console.Write("Reverse number is " & rev)
If num = rev Then
Console.Write(" .It is palindrome number")
Else
Console.Write(" .It is Not a palindrome number")
End If
Console.ReadKey()
End Sub

End Module

Q4 To display the following triangle.

* *

* * * *

* * * * * *

Module Module1
Sub main()
Dim i, j, k, m, l As Integer
m = 5
l = 1
For i = 1 To 4 Step 1
If m <= 3 Then
m = m - 1
End If
For j = 1 To m Step 1
Console.Write(" ")
Next
For k = 1 To l Step 1
Console.Write("* ")
Next
l = i * 2
m = m - 1
Console.Write(vbNewLine)
Next
Console.ReadLine()
End Sub
End Module
Q5. To calculate the binary number from decimal number.

Module Module4
Sub main()
Dim dec, remainder, m, sum As Integer

m = 1

Console.Write("Enter a decimal Number : ")


dec = Console.ReadLine()
While (dec > 0)

remainder = dec Mod 2


sum += m * remainder
dec = dec \ 2
m = m * 10

End While

Console.WriteLine("Binary Numbers = {0} ", sum)


Console.ReadKey()
End Sub
End Module

Q6. To find largest number from the array.

Module Module1
Sub main()
Dim a(5) As Integer, i As Integer, max As Integer
Console.Write("Enter the 5 elements")
For i = 0 To 4 Step 1
a(i) = Console.ReadLine()
Next
Console.Write("Array Elements" & vbNewLine)
For i = 0 To 4 Step 1
Console.WriteLine(a(i))
Next
max = a(0)
For i = 0 To 4 Step 1
If a(i) > max Then
max = a(i)
End If
Next
Console.Write("Max No=" & max)
Console.ReadLine()
End Sub
End Module

Q7 Sorting using bubble sort method.

Module Module1

Sub Main()

Dim n As Integer, i As Integer, j As Integer, a(100) As Integer, temp As Integer


n = InputBox("Enter Nummber of elements")
For i = 1 To n Step 1
a(i) = (InputBox("enter element"))
Next
Console.Write("Elements in the List")
For i = 1 To n Step 1
Console.WriteLine(a(i))
Next i
'for sorting
For i = 1 To n Step 1
For j = 1 To n - 1 Step 1
If a(j) > a(j + 1) Then
temp = a(j)
a(j) = a(j + 1)
a(j + 1) = temp
End If
Next j
Next i
Console.Write("Sorted list of elements")
For i = 1 To n Step 1
Console.WriteLine(a(i))
Next
Console.ReadKey()
End Sub

End Module

Q8 Write an algorithm, draw a flowchart and develop a VB.NET windows application to check the user id
and password is valid or not.

Public Class frmlogin


Dim un, pw As String
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If txtun.Text = un And txtpw.Text = pw Then
lblmsg.Text = "Your Password is Correct "
MsgBox("Your password is Correct !")
Else
lblmsg.Text = "Your password is Wrong Try Again!"
MsgBox("Your password is Wrong Try Again!")
End If
End Sub
Private Sub frmlogin_Load(sender As Object, e As EventArgs) Handles MyBase.Load
un = "Daimsr" pw = "College"
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
txtun.Text = ""
txtpw.Text = ""
lblmsg.Text = ""
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Me.Close()
End Sub
End Class

Q9.To create popup menu

Public Class Form1

Private Sub ContextMenuStrip1_Opening(ByVal sender As System.Object, ByVal e As


System.ComponentModel.CancelEventArgs) Handles ContextMenuStrip1.Opening
Me.BackColor = Color.Red
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click
ContextMenuStrip1.Show(Button1, 0, 0)
End Sub
Private Sub GreenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles GreenToolStripMenuItem.Click
Me.BackColor = Color.Green
End Sub

Private Sub BlueToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles BlueToolStripMenuItem.Click
Me.BackColor = Color.Blue
End Sub
End Class

Q10. Write an algorithm, draw a flowchart and develop a VB.NET windows application to create
notepad.

Public Class Notepad


'Private Sub OpenFileDialog1_FileOk(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) handles OpenFileDialog1.FileOk()
'End Sub
Private Sub OpenToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles OpenToolStripMenuItem.Click
If TextBox1.Modified Then
Dim a As MsgBoxResult
a = MsgBox("Do you want to save Changes", MsgBoxStyle.YesNoCancel)
If a = MsgBoxResult.No Then
OpenFileDialog1.ShowDialog()
TextBox1.Text =
My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)
ElseIf a = MsgBoxResult.Cancel Then
ElseIf a = MsgBoxResult.Yes Then
SaveFileDialog1.ShowDialog()
My.Computer.FileSystem.WriteAllText(SaveFileDialog1.FileName,
TextBox1.Text, False)
OpenFileDialog1.ShowDialog()
TextBox1.Text =
My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)
End If
Else
OpenFileDialog1.ShowDialog()
TextBox1.Text = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)
End If
End Sub
Private Sub NewToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles NewToolStripMenuItem.Click
If TextBox1.Modified Then
Dim a As MsgBoxResult
a = MsgBox("Do you want to save Changes", MsgBoxStyle.YesNoCancel)
If a = MsgBoxResult.No Then
TextBox1.Clear()
ElseIf a = MsgBoxResult.Cancel Then
ElseIf a = MsgBoxResult.Yes Then
SaveFileDialog1.ShowDialog()
My.Computer.FileSystem.WriteAllText(SaveFileDialog1.FileName,
TextBox1.Text, False)
TextBox1.Clear()
End If
Else
TextBox1.Clear()
End If
End Sub
Private Sub SaveToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles SaveToolStripMenuItem.Click
If TextBox1.Modified Then
SaveFileDialog1.ShowDialog()
My.Computer.FileSystem.WriteAllText(SaveFileDialog1.FileName, TextBox1.Text,
False)
Else
MsgBox("Cannot Save The Blank ")
End If
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles ExitToolStripMenuItem.Click
If TextBox1.Modified Then
MsgBox("Save Before Exit !")
Else
Me.Close()
End If
End Sub

Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles PrintToolStripMenuItem.Click

End Sub
End Class

Potrebbero piacerti anche