Shubham Joshi PDF
Shubham Joshi PDF
BCA(III M)
Vb.net practicals
Practical 1
Description of Visual Basic:
VISUAL BASIC is a high-level programming language evolved from the earlier DOS
version called BASIC. BASIC means Beginners' All-purpose Symbolic Instruction
Code. It is a fairly easy programming language to learn. The codes look a bit like
English Language Visual Studio is capable enough to support more than 36+
Programming Languages that allows the code editor and compiler to execute
nearly any programming language. Some popular languages that are supported by
Visual Studio are Visual Basics, C-Programming Language, C++ Programming
Language, C# Programming Language, Python, JavaScript.
Features of Visual Studio
Visual Studio provides the most advanced features that the latest developers are
looking for. Few of the most important features are described as follows.
• Code Editor
The Visual Studio has the best in class Code editor which supports multiple
functionalities. It enables bookmarks in code to incorporate Quick Navigation. In
addition to the normal text, VS also provides Debugger The remarkable Debugger
of the MS Visual Studio can work both as a Machine Level Debugger as well as a
Source Level Debugger. It is capable to debug Mapped Code as well as Native
Code. It is capable to compile any programming language that is supports VS.
• Designer
Other tools
• Extensibility
Visual Studio permits developers to write down extensions for Visual Studio to
extend its capabilities.
These extensions “plug into” Visual Studio and extend its functionality. Extensions
are available in the form of macros, add-ins, and packages.
Benefits of IDE
The overall goal and main benefit of an integrated development environment is
improved developer productivity. IDEsboost productivity by reducing setup time,
increasing the speed of development tasks, keeping developers up to date and
standardizing the development process.
• Faster setup: Without an IDE interface, developers would need to spend time
configuring multiple development tools. With the application integration of an
IDE, developers have the same set of capabilities in one place, without the need
for constantly switching tools.
• Faster development tasks: Tighter integration of all development tasks improves
developer productivity.
For example, code can be parsed and syntax checked while being edited,
providing instant feedback when syntax errors are introduced. Developers don’t
need to switch between applications to complete tasks. addition, the IDE’s tools
and features helps developers organize resources, prevent mistakes and take
shortcuts.
Lab Assignment-1
Features of .Net Framework 4.0
Security Changes in the .NET Framework 4 and up
They implemented two major changes in security the code that calls security
policy APIs receives a Not Supported Exception in addition to compiler warnings
at run time and also they invoked obsolete request permissions.
• Machine-wide security policy
• Security transparency
Features in Web:
1. Web Forms controls, including a new Chart control.
2. Microsoft Ajax, including additional support for client-based Ajax applications in
the Microsoft Ajax Library.
3. Multi-targeting, including better filtering for features that are not available in
the target version of the .NET Framework.
4. Web Forms, including more integrated support for ASP.NET routing, enhanced
support for Web standards, updated browser support, new features for data
controls, and new features for view state management.
5. MVC, including new helper methods for views, support for partitioned MVC
applications, and asynchronous controllers.
6. Deployment, including new tools for automating typical deployment tasks.
7. MVC, including new helper methods for views, support for partitioned MVC
applications, and asynchronous controllers.
Enhancements in WPF
1. New Controls,
a. DataGrid
b. Calendar
c. DatePicker
2. Visual State Manager.
3. Touch and Manipulation.
4. Graphics and Animations,
a. Layout Rounding
b. Cached Composition
c. Pixel Shader 3 Support
d. Easing Functions
5. Text,
a. New Text Rendering Stack
b. Selection and Caret Customization
6. Binding,
a. XAML Browser Applications
b. HTML-XBAP Script Interop
c. Full-Trust XBAP Deployment
7. WPF and Windows.
8. WPF and Silverlight Designer
a. Improved Support for Silverlight.
b. Support for Multiple Platform Versions.
c. Visual Databinding.
d. Auto Layout.
e. Improved Property Editing.
f. The Properties window now enables visually creating and editing Brush
resources.
DATA:
1. ADO.NET
a. Foreign Keys in the Conceptual Model.
b. New Methods for N-Tier Application Development.
c. Entity Data Source Support for the Query Extender Control.
d. Testability with I Object Set<T>.
2. Dynamic Data
a. Automatic validation that is based on constraints that are defined in the data
model.
b. The ability to easily change the markup that is generated for fields in the
GridView and DetailsView controls by using field templates that are part of a
Dynamic Data project.
Benefits of IDE
The overall goal and main benefit of an integrated development environment is
improved developer productivity. IDEs boost productivity by reducing setup time,
increasing the speed of development tasks, keeping developers up to date and
standardizing the development process.
• Faster setup: Without an IDE interface, developers would need to spend time
configuring multiple development tools. With the application integration of an
IDE, developers have the same set of capabilities in one place, without the need
for constantly switching tools.
• Faster development tasks: Tighter integration of all development tasks improves
developer productivity. For example, code can be parsed and syntax checked
while being edited, providing instant feedback when syntax errors are introduced.
Developers don’t need to switch between applications to complete tasks. In
addition, the IDE’s tools and features helps developers organize resources,
prevent mistakes and take shortcuts.
Practical 2
Introduction to various types of projects selection:
A solution is a container that's used to organize one or more related code
projects, for example a class library project and a corresponding test project
Projects: A project has two main jobs: to act as a container for our source
files and to compile those files into some kind of component, typically either a
Dynamic Link Library (DLL) or Windows Executable (EXE). We shall now run
through the main types of projects supported by VS.NET.
1. Open Visual Studio.
Create a solution
We'll start our exploration by creating an empty solution. After you get to know
Visual Studio, you
probably won't find yourself creating empty solutions very often. When you
create a new project,
Visual Studio automatically creates a solution to house the project if there's not a
solution already
open.
2. On the start window, choose Create a new project.
3. On the Create a new project page, enter blank solution into the search box,
select the Blank Solution template, and then choose Next
Run-Time Files
When you compile your application, all the necessary design-time files are
included in the run-time executable files. Run-time files are listed in the following
table:
RUN-TIME FILES
Extension Description
.dll In-process ActiveX component
.exe Executable file or ActiveX component
.ocx ActiveX control
.vbd ActiveX document state file
.wct WebClass HTML template
Default Storage
The default is the Projects folder inside your Documents. Right-click on the tab
name of any file you have open and select 'open containing folder' to get there
quickly.
Project Backup Location: You can find the project backed up in C:\Users\<User
Name>\Documents\Visual Studio 2010\Backup Files or n Visual Studio when you
create a new project or use the File -> Open dialog, it will default a location for
you. By default this is %USERPROFILE%\AppData\source\repos in 2019
You can change default folder for new projects in Visual Studio settings.
1. Click Tools menu
2. Click Options
3. Find "Projects and Solutions"
4. Choose "Project location"
5.AppData folder is hidden. You have to type its address in address bar manually
or you can enable view for hidden files in Windows Explorer.
Windows Forms
Windows Forms is a Graphical User Interface (GUI) class library which is bundled
in .Net Framework. Its main purpose is to provide an easier interface to develop
the applications for desktop, tablet, PCs. It is also termed as the WinForms. The
applications which are developed by using Windows Forms or WinForms are
known as the Windows Forms Applications that runs on the desktop computer.
WinForms can be used only to develop the Windows Forms Applications not web
applications. WinForms applications can contain the different type of controls like
labels, list boxes, tooltip etc.
Lab Assignment 2
Steps to Create an application project in Vb.net
First, open the Visual Studio then Go to File -> New -> Project to create a new
project and then select the language as Visual C# from the left menu. Click on
Windows Forms App (.NET Framework) in the middle of current window. After
that give the project name and Click OK.
Editor Window or Main Window: Here, you will work with forms and
code editing. You can notice the layout of form which is now blank. You will
double click the form then it will open the code for that.
Output:
1.Windows Form
2.calculator
Assignment 7
Program: Create Windows Form Application for
Student Registration Form using
various common controls
‘Windows Form Code:
Public Class Form1
Dim std_name As String
Dim f_name As String
Dim cont_no As String
Dim e_id As String
Dim national As String
Dim address As String
Dim gender As String
Dim b_group As String
Dim s_dom As String
Dim cata As String
Dim quali As String
Dim cour As String
Dim dob As Date
Private Sub Label3_Click(sender As Object, e As EventArgs) Handles Label3.Click
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
std_name = RichTextBox3.Text
f_name = RichTextBox1.Text
cont_no = RichTextBox5.Text
e_id = RichTextBox4.Text
national = ListBox1.SelectedItem
address = RichTextBox2.Text
dob = DateTimePicker1.Value
cata = ComboBox1.SelectedItem
quali = ListBox2.SelectedItem
cour = ComboBox3.SelectedItem
If RadioButton1.Checked Then
gender = RadioButton1.Text
End If
If RadioButton2.Checked Then
gender = RadioButton2.Text
End If
If RadioButton3.Checked Then
gender = RadioButton3.Text
End If
If RadioButton3.Checked Then
gender = RadioButton3.Text
End If
If RadioButton4.Checked Then
b_group = RadioButton4.Text
End If
If RadioButton5.Checked Then
b_group = RadioButton5.Text
End If
If RadioButton6.Checked Then
b_group = RadioButton6.Text
End If
If RadioButton7.Checked Then
b_group = RadioButton7.Text
End If
If RadioButton8.Checked Then
b_group = RadioButton8.Text
End If
If RadioButton9.Checked Then
b_group = RadioButton9.Text
End If
If RadioButton10.Checked Then
b_group = RadioButton10.Text
End If
If RadioButton11.Checked Then
b_group = RadioButton11.Text
End If
If RadioButton12.Checked Then
s_dom = RadioButton12.Text
End If
If RadioButton13.Checked Then
s_dom = RadioButton13.Text
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles
Button3.Click
RichTextBox1.Text = Nothing
RichTextBox2.Text = Nothing
RichTextBox3.Text = Nothing
RichTextBox4.Text = Nothing
RichTextBox5.Text = Nothing
ListBox1.SelectedItem = Nothing
RadioButton1.Checked = False
RadioButton2.Checked = False
RadioButton3.Checked = False
RadioButton4.Checked = False
RadioButton5.Checked = False
RadioButton6.Checked = False
RadioButton7.Checked = False
RadioButton8.Checked = False
RadioButton9.Checked = False
RadioButton10.Checked = False
RadioButton11.Checked = False
RadioButton12.Checked = False
RadioButton13.Checked = False
ComboBox1.SelectedItem = Nothing
ListBox2.SelectedItem = Nothing
ComboBox3.SelectedItem = Nothing
DateTimePicker1.ResetText()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles
Button2.Click
MsgBox("Student name : " + std_name + vbNewLine + "Father's Name :" +
f_name +
vbNewLine + "Contact no : " + cont_no + vbNewLine + "Email ID : " + e_id +
vbNewLine +
"Nationality : " + national + vbNewLine + "Address : " + address + vbNewLine +
"Gender :
" + gender + vbNewLine + "Blood Group :" + b_group + vbNewLine + "Domicile :" +
s_dom +
vbNewLine + "category :" + cata + vbNewLine + "Course : " + cour + vbNewLine +
"Qualification :" + quali + vbNewLine + "Date of birth :" + dob + vbNewLine)
End Sub
End Class
Output
Assignment 8
Program: Create Restaurant / Shop Billing
Application
Windows form coding:
Public Class Form1
Dim bill As Decimal = 0.0
Dim items As String = ""
Dim curr = DateTime.Now.TimeOfDay.Hours
Dim num As Integer
Dim table As String
Dim num_2 As Integer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For i As Integer = 1 To 36
Dim c As String = "checkbox" & i.ToString
DirectCast(Me.Controls.Find(c, False)(0), CheckBox).Visible = False
Next
For i As Integer = 1 To 36
Dim c As String = "textbox" & i.ToString
DirectCast(Me.Controls.Find(c, False)(0), TextBox).Visible = False
Next
End Sub
Private Sub CheckBox37_CheckedChanged(sender As Object, e As EventArgs)
Handles
CheckBox37.CheckedChanged
If CheckBox37.Checked Then
For i As Integer = 1 To 8
Dim c As String = "checkbox" & i.ToString
DirectCast(Me.Controls.Find(c, False)(0), CheckBox).Visible = True
Dim d As String = "textbox" & i.ToString
DirectCast(Me.Controls.Find(d, False)(0), TextBox).Visible = True
Next
Else
For i As Integer = 1 To 8
Dim c As String = "checkbox" & i.ToString
DirectCast(Me.Controls.Find(c, False)(0), CheckBox).Visible = False
Dim d As String = "textbox" & i.ToString
DirectCast(Me.Controls.Find(d, False)(0), TextBox).Visible = False
Next
End If
End Sub
Private Sub CheckBox38_CheckedChanged(sender As Object, e As EventArgs)
Handles
CheckBox38.CheckedChanged
If CheckBox38.Checked Then
For i As Integer = 9 To 16
Dim c As String = "checkbox" & i.ToString
DirectCast(Me.Controls.Find(c, False)(0), CheckBox).Visible = True
Dim d As String = "textbox" & i.ToString
DirectCast(Me.Controls.Find(d, False)(0), TextBox).Visible = True
Next
Else
For i As Integer = 9 To 16
Dim c As String = "checkbox" & i.ToString
DirectCast(Me.Controls.Find(c, False)(0), CheckBox).Visible = False
Dim d As String = "textbox" & i.ToString
DirectCast(Me.Controls.Find(d, False)(0), TextBox).Visible = False
Next
End If
End Sub
Private Sub CheckBox39_CheckedChanged(sender As Object, e As EventArgs)
Handles
CheckBox39.CheckedChanged
If CheckBox39.Checked Then
For i As Integer = 17 To 24
Dim c As String = "checkbox" & i.ToString
DirectCast(Me.Controls.Find(c, False)(0), CheckBox).Visible = True
Dim d As String = "textbox" & i.ToString
DirectCast(Me.Controls.Find(d, False)(0), TextBox).Visible = True
Next
Else
For i As Integer = 17 To 24
Dim c As String = "checkbox" & i.ToString
DirectCast(Me.Controls.Find(c, False)(0), CheckBox).Visible = False
Dim d As String = "textbox" & i.ToString
DirectCast(Me.Controls.Find(d, False)(0), TextBox).Visible = False
Next
End If
End Sub
Private Sub CheckBox40_CheckedChanged(sender As Object, e As EventArgs)
Handles
CheckBox40.CheckedChanged
If CheckBox40.Checked Then
For i As Integer = 25 To 28
Dim c As String = "checkbox" & i.ToString
DirectCast(Me.Controls.Find(c, False)(0), CheckBox).Visible = True
Dim d As String = "textbox" & i.ToString
DirectCast(Me.Controls.Find(d, False)(0), TextBox).Visible = True
Next
Else
For i As Integer = 25 To 28
Dim c As String = "checkbox" & i.ToString
DirectCast(Me.Controls.Find(c, False)(0), CheckBox).Visible = False
Dim d As String = "textbox" & i.ToString
DirectCast(Me.Controls.Find(d, False)(0), TextBox).Visible = False
Next
End If
End Sub
Private Sub CheckBox41_CheckedChanged(sender As Object, e As EventArgs)
Handles
CheckBox41.CheckedChanged
If CheckBox41.Checked Then
For i As Integer = 29 To 32
Dim c As String = "checkbox" & i.ToString
DirectCast(Me.Controls.Find(c, False)(0), CheckBox).Visible = True
Dim d As String = "textbox" & i.ToString
DirectCast(Me.Controls.Find(d, False)(0), TextBox).Visible = True
Next
Else
For i As Integer = 29 To 32
Dim c As String = "checkbox" & i.ToString
DirectCast(Me.Controls.Find(c, False)(0), CheckBox).Visible = False
Dim d As String = "textbox" & i.ToString
DirectCast(Me.Controls.Find(d, False)(0), TextBox).Visible = False
Next
End If
End Sub
Private Sub CheckBox42_CheckedChanged(sender As Object, e As EventArgs)
Handles
CheckBox42.CheckedChanged
If CheckBox42.Checked Then
For i As Integer = 33 To 36
Dim c As String = "checkbox" & i.ToString
DirectCast(Me.Controls.Find(c, False)(0), CheckBox).Visible = True
Dim d As String = "textbox" & i.ToString
DirectCast(Me.Controls.Find(d, False)(0), TextBox).Visible = True
Next
Else
For i As Integer = 33 To 36
Dim c As String = "checkbox" & i.ToString
DirectCast(Me.Controls.Find(c, False)(0), CheckBox).Visible = False
Dim d As String = "textbox" & i.ToString
DirectCast(Me.Controls.Find(d, False)(0), TextBox).Visible = False
Next
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
For i As Integer = 1 To 36
Dim c As String = "checkbox" & i.ToString
Dim d As String = "textbox" & i.ToString
If DirectCast(Me.Controls.Find(c, False)(0), CheckBox).Checked = True Then
bill = bill + DirectCast(Me.Controls.Find(d, False)(0), TextBox).Text
items = (items + DirectCast(Me.Controls.Find(c, False)(0), CheckBox).Text
+ vbNewLine)
End If
Next
If ComboBox1.SelectedItem = "-Not available-" Then
bill = bill - (0)
Else
If ComboBox1.SelectedItem = "5%" Then
bill = bill - (bill * 0.05)
Else
If ComboBox1.SelectedItem = "9%" Then
bill = bill - (bill * 0.09)
Else
If ComboBox1.SelectedItem = "12%" Then
bill = bill - (bill * 0.12)
Else
If ComboBox1.SelectedItem = "FREE FRUIT MUFFIN x2" Then
items = (items + "Muffins x2(by coupon)" + vbNewLine)
Else
If ComboBox1.SelectedItem = "FREE PEPSI x1" Then
items = (items + "Pepsi x1(By coupon" + vbNewLine)
End If
End If
End If
End If
End If
End If
MsgBox("bill : " + CType(bill, String) + vbNewLine +
"===============================" + vbNewLine + "Your Items :" +
vbNewLine + items +
vbNewLine + "*****Please visit again****** ")
bill = 0.0
items = ""
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles
Button2.Click
For i As Integer = 1 To 36
Dim c As String = "checkbox" & i.ToString
DirectCast(Me.Controls.Find(c, False)(0), CheckBox).Checked = False
Dim d As String = "textbox" & i.ToString
DirectCast(Me.Controls.Find(d, False)(0), TextBox).Visible = False
Next
For i As Integer = 1 To 36
Dim c As String = "checkbox" & i.ToString
DirectCast(Me.Controls.Find(c, False)(0), CheckBox).Visible = False
Next
bill = 0.0
items = ""
End Sub
End Class
Output-:
Assignment 9
Program: Create an application in VB.Net for
Student Mark Sheet / Result generation
using select case and Keypress and Text changed event
‘Windows Forms Coding:
Public Class Form1
Dim stu_name As String
Dim e_no As String = 0
Dim pro As String = 0
Dim per As Decimal = 0.0
Dim gra As Char
Dim agg As Decimal
Dim total As Decimal
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
stu_name = TextBox6.Text
e_no = TextBox7.Text
pro = ComboBox1.SelectedText
For i As Integer = 1 To 5
Dim c As String = "textbox" & i.ToString
total += DirectCast(Me.Controls.Find(c, False)(0), TextBox).Text
Next
agg = total / 5
TextBox10.Text = agg
per = (total / 500) * 100
TextBox8.Text = (per.ToString + " %")
gra = grade(per)
TextBox9.Text = gra
End Sub
Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs)
Handles
TextBox1.KeyPress
If ((Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57) And Not ((Asc(e.KeyChar) = 10)
Or (Asc(e.KeyChar) = 8) Or (Asc(e.KeyChar)) = 9)) Then
MsgBox(" Only numeric data allowed")
e.KeyChar = ""
End If
End Sub
Private Sub TextBox2_KeyPress(sender As Object, e As KeyPressEventArgs)
Handles
TextBox2.KeyPress
If ((Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57) And Not ((Asc(e.KeyChar) = 10)
Or (Asc(e.KeyChar) = 8) Or (Asc(e.KeyChar)) = 9)) Then
MsgBox(" Only numeric data allowed")
e.KeyChar = ""
End If
End Sub
Private Sub TextBox3_KeyPress(sender As Object, e As KeyPressEventArgs)
Handles
TextBox3.KeyPress
If ((Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57) And Not ((Asc(e.KeyChar) = 10)
Or (Asc(e.KeyChar) = 8) Or (Asc(e.KeyChar)) = 9)) Then
MsgBox(" Only numeric data allowed")
e.KeyChar = ""
End If
End Sub
Private Sub TextBox4_KeyPress(sender As Object, e As KeyPressEventArgs)
Handles
TextBox4.KeyPress
If ((Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57) And Not ((Asc(e.KeyChar) = 10)
Or (Asc(e.KeyChar) = 8) Or (Asc(e.KeyChar)) = 9)) Then
MsgBox(" Only numeric data allowed")
e.KeyChar = ""
End If
End Sub
Private Sub TextBox5_KeyPress(sender As Object, e As KeyPressEventArgs)
Handles
TextBox5.KeyPress
If ((Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57) And Not ((Asc(e.KeyChar) = 10)
Or (Asc(e.KeyChar) = 8) Or (Asc(e.KeyChar)) = 9)) Then
MsgBox(" Only numeric data allowed")
e.KeyChar = ""
End If
End Sub
Private Sub TextBox7_KeyPress(sender As Object, e As KeyPressEventArgs)
Handles
TextBox7.KeyPress
If ((Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57) And Not ((Asc(e.KeyChar) = 10)
Or (Asc(e.KeyChar) = 8) Or (Asc(e.KeyChar)) = 9)) Then
MsgBox(" Only numeric data allowed")
e.KeyChar = ""
End If
End Sub
Function grade(ByVal p As Decimal)
Select Case per
Case >= 90
Return "A+"
Case 80 To 89
Return "B"
Case 70 To 79
Return "B+"
Case 60 To 69
Return "C+"
Case 50 To 59
Return "C"
Case 40 To 49
Return "D"
Case 0 To 33
Return "F"
End Select
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles
Button2.Click
MsgBox("Name of student :: " + stu_name + vbNewLine + "Enrollment Number ::
"+
e_no + vbNewLine + "Course :: " + pro + vbNewLine + "------------------------------------
-------" + vbNewLine + "Percentage :: " + per.ToString + vbNewLine + "Grade :: " +
gra.ToString + vbNewLine + "Aggregate marks :: " + agg.ToString)
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles
TextBox1.TextChanged
If (Val(TextBox1.Text) < 0 Or Val(TextBox1.Text) > 100) Then
MsgBox("Marks must be between 0 and 100")
TextBox1.Text = ""
TextBox1.Focus()
End If
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles
TextBox2.TextChanged
If (Val(TextBox1.Text) < 0 Or Val(TextBox1.Text) > 100) Then
MsgBox("Marks must be between 0 and 100")
TextBox1.Text = ""
TextBox1.Focus()
End If
End Sub
Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles
TextBox3.TextChanged
If (Val(TextBox1.Text) < 0 Or Val(TextBox1.Text) > 100) Then
MsgBox("Marks must be between 0 and 100")
TextBox1.Text = ""
TextBox1.Focus()
End If
End Sub
Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs) Handles
TextBox4.TextChanged
If (Val(TextBox1.Text) < 0 Or Val(TextBox1.Text) > 100) Then
MsgBox("Marks must be between 0 and 100")
TextBox1.Text = ""
TextBox1.Focus()
End If
End Sub
Private Sub TextBox5_TextChanged(sender As Object, e As EventArgs) Handles
TextBox5.TextChanged
If (Val(TextBox1.Text) < 0 Or Val(TextBox1.Text) > 100) Then
MsgBox("Marks must be between 0 and 100")
TextBox1.Text = ""
TextBox1.Focus()
End If
End Sub
End Class
Output-:
Assignment 10
Program: Create an vb.net application to show
various Math’s
operations Sum of Digit, Number Reverse,
Palindrome, Product of Digit,
Armstrong number, Even / Odd, Factorial
‘Windows Forms Coding:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim fac, i As Double
Dim num As Integer
num = CInt(TextBox2.Text)
fac = 1
For i = 1 To num
fac = fac * i
Next
TextBox1.Text = fac.ToString
End Sub
Private Sub TextBox2_KeyPress(sender As Object, e As KeyPressEventArgs)
Handles
TextBox2.KeyPress
If ((Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57) And Not ((Asc(e.KeyChar) = 10)
Or (Asc(e.KeyChar) = 8) Or (Asc(e.KeyChar)) = 9)) Then
MsgBox(" Non integral values are not allowed ")
e.KeyChar = ""
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles
Button2.Click
Dim fibo As Integer
Dim num As Integer
num = CInt(TextBox2.Text)
fibo = Fib(num)
TextBox1.Text = (fibo)
End Sub
Function Fib(n As Long) As Long
Dim first As Long
Dim second As Long
Dim sum As Long
Dim i As Long
first = 0
second = 1
sum = 0
If n = 0 Then
Fib = first
ElseIf n = 1 Then
Fib = second
Else
For i = 2 To n
sum = first + second
first = second
second = sum
Next i
Fib = sum
End If
End Function
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles
Button4.Click
Dim num, flag As Integer
flag = 0
num = CInt(TextBox2.Text)
flag = prime(num)
If flag = 1 Then
TextBox1.Text = (num.ToString + "is a prime number")
Else
TextBox1.Text = (num.ToString + " is not a prime number")
End If
End Sub
Function prime(Num As Double) As Integer
Dim i As Integer
If (Num = 1 Or Num = 0) Then
Return 0
End If
For i = 2 To Num
If ((Num Mod i) = 0) Then
Return 0
Else
Return 1
End If
Next
Return 1
End Function
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles
Button5.Click
Dim num, dummy, sum, remain As Integer
num = CInt(TextBox2.Text)
dummy = num
sum = 0
remain = 0
While dummy > 0
remain = dummy Mod 10
sum = sum + remain
dummy = Math.Truncate(dummy / 10)
End While
TextBox1.Text = ("Sum of Digit :: " + sum.ToString)
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles
TextBox1.TextChanged
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles
Button6.Click
Dim t As String = ""
Dim i As Integer
Dim num As Integer
num = CInt(TextBox2.Text)
For i = 1 To 10
t = t + (num * i).ToString + ", "
Next
MsgBox(" Table of " & num & " is " & t)
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles
Button7.Click
Dim num, rev, remain, dummy As Integer
rev = 0
num = CInt(TextBox2.Text)
dummy = num
While num <> 0
remain = num Mod 10
rev = rev * 10 + remain
num = Math.Truncate(num / 10)
End While
If rev = dummy Then
TextBox1.Text = (rev.ToString + " :: Is palindrome")
Else
TextBox1.Text = (rev.ToString + " :: Is not palindrome")
End If
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles
Button8.Click
Dim num, remain, pro As Integer
pro = 1
num = CInt(TextBox2.Text)
While num <> 0
remain = num Mod 10
pro = pro * remain
num = Math.Truncate(num / 10)
End While
TextBox1.Text = ("Product of Digit :: " + pro.ToString)
End Sub
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles
Button9.Click
Dim num As Integer
num = TextBox2.Text
If (num Mod 2 = 0) Then
TextBox1.Text = (num.ToString + " is even")
Else
TextBox1.Text = (num.ToString + " is odd")
End If
End Sub
Private Sub Button10_Click(sender As Object, e As EventArgs) Handles
Button10.Click
TextBox1.Text = 0
TextBox2.Text = 0
End Sub
Private Sub Button12_Click(sender As Object, e As EventArgs) Handles
Button12.Click
Dim num, dum, remain, result As Integer
num = CInt(TextBox2.Text)
result = 0
dum = num
While dum <> 0
remain = dum Mod 10
result += remain * remain * remain
dum = Math.Truncate(dum / 10)
End While
If result = num Then
TextBox1.Text = (num.ToString + " :: Is Armstrong")
Else
TextBox1.Text = (num.ToString + " :: Is not Armstrong")
End If
End Sub
End Class
Output:
Assignment 11
Program: Matrix - Addition, Multiplication, Sparse
and Transpose Using Dynamic Array:
‘Widows Form Coding:
Public Class Form1
Dim a(100, 100), b(100, 100), c(100, 100), d(100, 100), s1(100, 100), s2(100, 100)
As
Integer
Dim sizeg As Integer = 0
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles
Button2.Click
Dim i, j As Integer
For i = 1 To sizeg
For j = 1 To sizeg
c(i, j) = a(i, j) + b(i, j)
TextBox3.Text = TextBox3.Text & " " & c(i, j)
Next j
TextBox3.Text = TextBox3.Text + vbNewLine
Next i
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles
Button3.Click
Dim i As Integer
Dim j As Integer
For i = 1 To sizeg
For j = 1 To sizeg
c(i, j) = a(i, j) - b(i, j)
TextBox3.Text = TextBox3.Text & " " & c(i, j)
Next j
TextBox3.Text = TextBox3.Text + vbNewLine
Next i
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles
Button4.Click
Dim i As Integer = 0
Dim j As Integer = 0
Dim k As Integer = 0
For i = 1 To sizeg
For j = 1 To sizeg
For k = 1 To sizeg
c(i, k) = c(i, k) + a(i, j) * b(j, k)
Next k
Next j
Next i
For i = 1 To sizeg
For j = 1 To sizeg
TextBox3.Text = TextBox3.Text & " " & c(i, j)
Next j
TextBox3.Text = TextBox3.Text + vbNewLine
Next i
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles
Button6.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim size1 As Integer
Try
size1 = InputBox("Enter size of the array :: ")
sizeg = size1
Dim i As Integer
Dim j As Integer
For i = 1 To size1
For j = 1 To size1
a(i, j) = InputBox("Enter elements of matrix A :: " & "(" & i & "," &
j & ")")
Next j
Next i
For i = 1 To size1
For j = 1 To size1
TextBox1.Text = TextBox1.Text & " " & a(i, j)
Next j
TextBox1.Text = TextBox1.Text + vbNewLine
Next i
For i = 1 To size1
For j = 1 To size1
b(i, j) = InputBox("Enter elements of matrix B :: " & "(" & i & "," &
j & ")")
Next j
Next i
For i = 1 To size1
For j = 1 To size1
TextBox2.Text = TextBox2.Text & " " & b(i, j)
Next j
TextBox2.Text = TextBox2.Text + vbNewLine
Next i
Catch ex As Exception
msgbox("please enter valid size")
End Try
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles
Button8.Click
TextBox3.Text = ""
TextBox4.Text = ""
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles
Button5.Click
Dim i, j As Integer
i=1
j=j
TextBox4.Visible = True
Label4.Visible = True
For i = 1 To sizeg
For j = 1 To sizeg
c(i, j) = a(j, i)
TextBox3.Text = TextBox3.Text & " " & c(i, j)
Next j
TextBox3.Text = TextBox3.Text + vbNewLine
Next i
For i = 1 To sizeg
For j = 1 To sizeg
d(i, j) = b(j, i)
TextBox4.Text = TextBox4.Text & " " & d(i, j)
Next j
TextBox4.Text = TextBox4.Text + vbNewLine
Next i
End Sub
Dim i, j As Integer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TextBox4.Visible = False
Label4.Visible = False
End Sub
End Class
Output -:
Assignment: 12
Program: to show the use of Array List and its
functions- ADD , INSERT , REMOVE, SORT,
REMOVEAT
‘Windows Form Coding:
Public Class Form1
Dim arr As New ArrayList
Dim num As String = ""
Dim val As String = ""
Dim pos As String = ""
Dim flag As Integer = 0
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim i, j As Integer
num = InputBox("Enter how many elemnts you want to enetr ::")
For i = 1 To num
arr.Add(InputBox(i.ToString + "th Value :: "))
flag = 1
Next
If flag = 1 Then
MsgBox("Elements inserted")
Else
MsgBox("An Error Occured, Please try again with valid values")
End If
ListBox1.Items.Clear()
For i = 0 To arr.Count - 1
ListBox1.Items.Add(arr.Item(i))
Next
TextBox1.Text = arr.Count
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles
Button7.Click
arr.Clear()
ListBox1.Items.Clear()
For i = 0 To arr.Count - 1
ListBox1.Items.Add(arr.Item(i))
Next
TextBox1.Clear()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles
Button2.Click
pos = InputBox("Enter position where you want to insert new element :: ")
val = InputBox("Enter value you want to insert :: ")
Try
arr.Insert(pos, val)
Catch ex As Exception
MsgBox("Please check size of array ")
End Try
ListBox1.Items.Clear()
For i = 0 To arr.Count - 1
ListBox1.Items.Add(arr.Item(i))
Next
TextBox1.Clear()
TextBox1.Text = arr.Count
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles
Button3.Click
Try
arr.RemoveAt(arr.Count - 1)
Catch ex As Exception
MsgBox("Array list is empty ")
End Try
ListBox1.Items.Clear()
For i = 0 To arr.Count - 1
ListBox1.Items.Add(arr.Item(i))
Next
TextBox1.Clear()
TextBox1.Text = arr.Count
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles
Button6.Click
End
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles
Button4.Click
arr.Sort()
MsgBox("Sorting complete !! ")
ListBox1.Items.Clear()
ListBox1.Items.Clear()
For i = 0 To arr.Count - 1
ListBox1.Items.Add(arr.Item(i))
Next
TextBox1.Clear()
TextBox1.Text = arr.Count
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles
Button5.Click
num = InputBox("Enter position of element you wish to remove")
Try
arr.RemoveAt(num)
flag = 1
Catch ex As Exception
MsgBox("Please enter valid positon ")
End Try
If flag = 1 Then
MsgBox("Elements Removed")
Else
MsgBox("An Error Occured, Please try again with valid values")
End If
ListBox1.Items.Clear()
For i = 0 To arr.Count - 1
ListBox1.Items.Add(arr.Item(i))
Next
TextBox1.Clear()
TextBox1.Text = arr.Count
End Sub
End Class
Assignment 13
Program: Advance Calculator
Private Sub Combo1_()
Select Case Combo1.ListIndex
Case 0
Label1 = Str$(Val(Text1.Text) + Val(Text2.Text))
Case 1
Label1 = Str$(Val(Text1.Text) - Val(Text2.Text))
End Select
End Sub
Private Sub Command1_Click()
Select Case Combo1.ListIndex
Case 0
Label1 = Str$(Val(Text1.Text) + Val(Text2.Text))
Case 1
Label1 = Str$(Val(Text1.Text) - Val(Text2.Text))
Case 2
Label1 = Str$(Val(Text1.Text) * Val(Text2.Text))
Case 3
Label1 = Str$(Val(Text1.Text) / Val(Text2.Text))
End Select
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Combo1.AddItem "+"
Combo1.AddItem "-"
Combo1.AddItem "x"
Combo1.AddItem "%"
Combo1.ListIndex = 1
End Sub
Private Sub CmdSin_Click()
sinx = Round(Sin(displayValue * 4 * Atn(1) / 180), 4)
panel.Caption = sinx
End Sub
Private Sub CmdCos_Click()
cosx = Round(Cos(displayValue * 4 * Atn(1) / 180), 4)
panel.Caption = cosx
End Sub
Private Sub CmdTan_Click()
tanx = Round(Tan(displayValue * 4 * Atn(1) / 180), 4)
panel.Caption = tanx
End Sub
Private Sub CmdLn_Click()
panel.Caption = Log(displayValue)
End Sub
Private Sub CmdLog_Click()
panel.Caption = Log(displayValue) / Log(10)
End Sub
Program 20: traffic light controller
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public int count=10;
public int a;
public Form1()
{
InitializeComponent();
a = 1;
pictureBox1.Visible = true;
pictureBox2.Visible = false;
pictureBox3.Visible = false;
txt_msg.Text = "Turn OFF your engine";
}
}
}
}
14. Write a program to perform following operation:a. ADDb.
SUBTRACTc. MULTIPLYd. DIVISIONe. MODPublic Class Form1Private Sub
Button1_Click(sender As Object, e As EventArgs) Handles
Button1.ClickTextBox3.Text = Val(TextBox1.Text) +
Val(TextBox2.Text)End SubPrivate Sub Button4_Click(sender As Object,
e As EventArgs) Handles Button4.ClickTextBox3.Text =
Val(TextBox1.Text) - Val(TextBox2.Text)End SubPrivate Sub
Button2_Click(sender As Object, e As EventArgs) Handles
Button2.ClickTextBox3.Text = Val(TextBox1.Text) *
Val(TextBox2.Text)End SubPrivate Sub Button3_Click(sender As Object,
e As EventArgs) Handles Button3.ClickTextBox3.Text =
Val(TextBox1.Text) / Val(TextBox2.Text)End SubPrivate Sub
Button6_Click(sender As Object, e As EventArgs) Handles
Button6.ClickTextBox3.Text = Val(TextBox1.Text) Mod
Val(TextBox2.Text)End SubEnd Class