0% found this document useful (0 votes)
143 views96 pages

Shubham Joshi PDF

The document provides information on Visual Basic .NET practicals and describes Visual Basic as a high-level programming language evolved from BASIC. It discusses features of Visual Studio like its code editor, designer, debugger, and extensibility. It also summarizes the history of Visual Basic, introduction to .NET framework, main components of .NET framework including CLR and FCL, and defines what an integrated development environment is. Finally, it discusses features of .NET Framework 4.0 including security changes, application compatibility, new features, and enhancements in areas like web, WPF, data, and communications.

Uploaded by

Shubham Joshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
143 views96 pages

Shubham Joshi PDF

The document provides information on Visual Basic .NET practicals and describes Visual Basic as a high-level programming language evolved from BASIC. It discusses features of Visual Studio like its code editor, designer, debugger, and extensibility. It also summarizes the history of Visual Basic, introduction to .NET framework, main components of .NET framework including CLR and FCL, and defines what an integrated development environment is. Finally, it discusses features of .NET Framework 4.0 including security changes, application compatibility, new features, and enhancements in areas like web, WPF, data, and communications.

Uploaded by

Shubham Joshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 96

Shubham joshi

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.

History of Visual Basic


The first version of visual basic, VB 1.0, was announced in the year 1991. The
creation of user interface through a drag and drop design was inspired a beta
generator that was developed by Alan Cooper at Tripod, which was Cooper’s
company.
Microsoft entered into a contract with Cooper and his partners to create Tripod
into a system that is programmable for Windows 3.0. This system was developed
under the code name of Ruby, which has no relationship with the Ruby
Programming Language

Introduction to .NET Framework


.NET is a software framework which is designed and developed by Microsoft. The
first version of the .Net framework was 1.0 which came in the year 2002. In easy
words, it is a virtual machine for compiling and executing programs written in
different languages like C#, VB.Net etc.
It is used to develop Form-based applications, Web-based applications, and Web
services. There is a variety of programming languages available on the .Net
platform, VB.Net and C# being the most common ones. It is used to build
applications for Windows, phone, web, etc. It provides a lot of functionalities and
also supports industry standards.
.NET Framework supports more than 60 programming languages in which 11
programming languages are designed and developed by Microsoft. The remaining
Non-Microsoft Languages which are supported by .NET Framework but not
designed and developed by Microsoft
11 Programming Languages which are designed and developed by Microsoft are:
• C#.NET
• VB.NET
• C++.NET
• J#.NET
• F#.NET
• JSCRIPT.NET
• WINDOWS POWERSHELL
• IRON RUBY
• IRON PYTHON
• C OMEGA
• ASML (Abstract State Machine Language)

Main Components of .NET Framework


Common Language Runtime (CLR):
CLR is the basic and Virtual Machine component of the .NET Framework. It is the
run-time environment in the .NET Framework that runs the codes and helps in
making the development process easier by providing the various services such as
remoting, thread management, typesafety, memory management, robustness,
etc.
Basically, it is responsible for managing the execution of .NET programs regardless
of any .NET programming language. It also helps in the management of code, as
code that targets the runtime is known as the Managed Code and code doesn’t
target to runtime is known as Unmanaged code.

Framework Class Library (FCL): It is the collection of reusables,


object-oriented class libraries and methods, etc. that can be integrated with CLR.
Also called the Assemblies. It is just like the header files in C/C++ and packages in
the java. Installing .NET framework basically is the installation of CLR and FCL into
the system. Below is the overview of .NET Framework
WHAT IS AN INTEGRATED DEVELOPMENT
ENVIRONMENT (IDE)?
An integrated development environment (IDE) is an application that facilitates
application development. IDEs are designed to encompass all programming tasks
in one application. Therefore, IDEs offer a central interface featuring all the tools
a developer needs, including the following:
• Code editor: This feature is a text editor designed for writing and editing source
code. Source code editors are distinguished from text editors because they
enhance or simplify the writing and editing of code.
• Compiler: This tool transforms source code written in a human
readable/writable language into a form executable by a computer.
• Debugger: This tool is used during testing to help debug application programs.
• Build automation tools: These tools automate common developer tasks.
In addition, some IDEs might also include the following:
• Class browser: This tool is used to examine and reference the properties of an
object-oriented class hierarchy.
• Object browser: This feature is used to examine the objects instantiated in a
running application program.
• Class hierarchy diagram: This tool allows the programmer to visualize the
structure of object-oriented programming code.

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

Application Compatibility and Deployment


The .NET Framework 4 does not automatically use its version of the common
language runtime to run applications that are built with earlier versions of the
.NET Framework. To run older applications with .NET Framework 4, you must
compile your application with the target .NET Framework version specified in the
properties for your project in Visual Studio, or you can specify the supported
runtime with the <supported Runtime> Element in an application configuration
file.
New features:
• Diagnostics and Performance
• Garbage Collection
• Code Contracts
• Design-Time-Only Interop Assemblies
• Dynamic Language Runtime
• Memory-Mapped Files

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.

Communications and Workflow:


1. WCF
a. Configuration Based Activation.
b. System Web Routing Integration.
c. Multiple IIS Site Bindings Support.
2. Work Flow
a. Workflow Activity Model.
b. Rich Composite Activity Options.
c. Expanded Built-In Activity Library.
d. Explicit Activity Data Model.
e. Enhanced Hosting, Persistence, and Tracking Options.
f. Easier Ability to Extend WF Designer Experience.

About VS version history


History of Visual Basic
The first version of visual basic, VB 1.0, was announced in the year 1991. The
creation of user interface through a drag and drop design was inspired a beta
generator that was developed by Alan Cooper at Tripod, which was Cooper’s
company. The introduction of Visual Basic 6.0 was made in the middle of 1998.
This version also came with a number of enhancements, including the striking
ability of creating web-based applications. The extended support for Visual Basic
6.0 was ceased in the month of March in 2008. The basic parts of development
environment of Visual Basic 6, however, still run in all the 32-bit Microsoft
windows, including Windows 8.1. After the cessation of mainstream and
extended support for Visual Basic 6.0 caused a number of programs to show
concern. The community members then created a lobby of users and a petition
was signed by them. The basic aim of this petition was to ensure that the product
remains alive. However, the petition did not attain its aim effectively

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

Solutions and projects


Despite its name, a solution is not an "answer". A solution is simply a container
used by Visual Studio to organize one or more related projects. When you open a
solution in Visual Studio, it automatically loads all the projects that the solution
contains.

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

4. Name the solution Quick Solution, and then choose Create.


A solution appears in Solution Explorer on the right-hand side of the Visual Studio
window. You'll probably use Solution Explorer often, to browse the contents of
your projects
The New Project dialog box allows you to create a new solution starting with a
particular project type:
On the left side of this screen, you can choose the language you will use to create
your new project.
Depending on the options you selected when you installed your Visual Studio
environment, you can choose from Visual Basic .NET, C#, C++, and any other .NET
programming language you have installed. Microsoft isn't the only supplier of
.NET-supported languages—other vendors have written languages that work just
as well in Visual Studio .NET as the languages provided by Microsoft.
On the right side of this screen, you can choose a default template for the type of
project you will be creating. You have many different templates to choose from,
as described in the next section.
Whichever Web server you choose, you must have installed the .NET Framework
on that machine prior to creating a Web project using Visual Studio .NET.
File Extensions
Visual Basic produces a number of files when you create and compile a project.
These can be categorized as follows: design-time, miscellaneous development,
and run-time. Design time files are the building blocks of your project: basic
modules (.bas) and form modules (.form), for example. Miscellaneous files are
produced by various processes and functions of the Visual Basic development
environment: Package and Deployment Wizard dependency files (.dep), for
example. Design-time and Miscellaneous Files The following table lists all the
design-time and miscellaneous other files that may be produced when you
develop an application:

DESIGN-TIME AND MISCELLANEOUS FILES


Extension Description
.bas Basic module
.cls Class module
.ctl User Control file
ctx User Control binary file
.dca Active Designer cache
.ddf Package and Deployment Wizard CAB information file
.dep Package and Deployment Wizard dependency file
.dob ActiveX document form file
.dox ActiveX document binary form file
.dsr Active Designer file
.dsx Active Designer binary file
.dws Deployment wizard script file
.frm Form file
.frx Binary form file
.log Log file for load errors
.oca Control TypeLib cache file
.pag Property page file
.pgx Binary property page file
.res Resource file
.tlb Remote Automation TypeLib file
.vbg Visual Basic group project file
.vbl Control licensing file
.vbp Visual Basic project file
.vbr Remote Automation registration file
.vbw Visual Basic project workspace file
.vbz Wizard launch file
.wct WebClass HTML template

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.

Solution Explorer Window: It is used to navigate between all items in


solution. For example, if you will select a file form this window then particular
information will be display in the property window.

Properties Window: This window is used to change the different properties


of the selected item in the Solution Explorer. Also, you can change the properties
of components or controls that you will add to the forms.

Files Created by visual studio windows application:


Files created in Project folder:
1. XML: Extensible Markup Language
2. .VB: Visual Studio
3. .resx: Registered Exporter system
4. .slm: solution file

Files created inside “My Project”:


1. .VB
2. .myapp
3. .resx
4. .settings
Practical 3
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.
A Windows forms application is one that runs on the desktop computer. A
Windows forms application will normally have a collection of controls such as
labels, textboxes, list boxes, etc.
Below is an example of a simple Windows form application. It shows a simple
Login screen, which is accessible by the user. The user will enter the required
credentials and then will click the Login button to proceed.

‘for an example of the controls available in the above application


1. This is a collection of label controls which are normally used to describe
adjacent controls. So in our case, we have 2 textboxes, and the labels are used to
tell the user that one textbox is for entering the user name and the other for the
password.
2. The 2 textboxes are used to hold the username and password which will be
entered by the user.
3. Finally, we have the button control. The button control will normally have some
code attached to perform a certain set of actions. So for example in the above
case, we could have the button perform an action of validating the user name and
password which is entered by the user.
Visual Basic Form is the container for all the controls that make up the user
interface. Every window you see in a running visual basic application is a form,
thus the terms form and window describe the same entity. Visual Studio creates a
default form for you when you create a Windows Forms Application.
Every form will have title bar on which the form's caption is displayed and there
will be buttons to close, maximize and minimize the form shown below −

VB.Net Forms Properties


Following table lists down the important properties of a form in VB.net.
Properties Uses
BackColor Set’s the background color for the form
BackgroundImage Set’s the background image for the form
Cursor Set the cursor image when it hovers over the form.
AllowDrop Specifies whether to accept the data dragged and
dropped onto the form.
Font Get or sets the font used in the form
Locked Specifies whether the form is locked.
FormBorderStyle Get or set border style of a form
Text Provide the title for a Form Window
Control Box Determines whether the ControlBox is available by
clicking the icon in the upper left corner of the window.
Icon Specifies icon for the window in the upper left corner.
MousePointer Sets the type of mouse pointer to be displayed
when hovered over a specific area.

VB.Net Forms Methods


The commonly used form methods in Visual Basic.Net are given in the following
table.
Method Name Description
Activate Activates the form and gives it focus.
ActivateMdiChild Activates the MDI child of a form.
BringToFront Brings the control to the front of the z-order.
CenterToParent Centers the position of the form within the bounds
of the parent form.
CenterToScreen Centers the form on the current screen Close
Refresh Forces the control to invalidate its client area and
ScaleControl Scales the location, size, padding, and margin ofa
control
Select Activates the control.
SendToBack Sends the control to the back of the z-order.
SetAutoScrollMargin Sets the size of the auto-scroll margins.
SetDesktopBounds Sets the bounds of the form in desktop coordinates.
Show Displays the control to the user.
ShowDialog Shows the form as a modal dialog box.

VB.Net Forms Events


The following table shows the mostly used Form events in
Visual Basic.Net.
Event Description
Activated Occurs when the form is activated in code or by the user.
Click Occurs when the form is clicked.
Closed Occurs before the form is closed.
Closing Occurs when the form is closing.
DoubleClick Occurs when the form control is double-clicked.
DragDrop Occurs when a drag-and-drop operation is completed.
Enter Occurs when the form is entered.
GotFocus Occurs when the form control receives focus.
MouseEnter Occurs when the mouse pointer enters the form.
MouseHover Occurs when the mouse pointer rests on the form.
MouseLeave Occurs when the mouse pointer leaves the form.
MouseMove Occurs when the mouse pointer is moved over the form.
Move Occurs when the form is moved.
Resize Occurs when the control is resized
Lab Assignment 3
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.
Assignment 4
Program: Design and application form in vb.net to perform
Picture rotation.
‘Windows Form Coding:
Public Class picture_ro
Private Sub PictureBox1_Click(sender As Object, e As EventArgs)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
pic5.Image = pic1.Image
pic1.Image = pic2.Image
pic2.Image = pic4.Image
pic4.Image = pic3.Image
pic3.Image = pic5.Image
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles
Button2.Click
pic5.Image = pic1.Image
pic1.Image = pic3.Image
pic3.Image = pic4.Image
pic4.Image = pic2.Image
pic2.Image = pic5.Image
End Sub
End Class
Output ::
Assignment 5
Program: Create a Windows Form Application
project with calculator
Windows Form Coding:
Public Class Form1
Dim flag As Boolean = True
Dim op As String
Dim opr As Double
Dim opr2 As Double
Dim result As Double
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
If flag Then
TextBox1.Text = Button1.Text
flag = False
Else
TextBox1.Text += Button1.Text
End If
End Sub
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
If flag Then
TextBox1.Text = Button2.Text
flag = False
Else
TextBox1.Text += Button2.Text
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles
Button3.Click
If flag Then
TextBox1.Text = Button3.Text
flag = False
Else
TextBox1.Text += Button3.Text
End If
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles
Button5.Click
If flag Then
TextBox1.Text = Button5.Text
flag = False
Else
TextBox1.Text += Button5.Text
End If
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles
Button6.Click
If flag Then
TextBox1.Text = Button6.Text
flag = False
Else
TextBox1.Text += Button6.Text
End If
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles
Button7.Click
If flag Then
TextBox1.Text = Button7.Text
flag = False
Else
TextBox1.Text += Button7.Text
End If
End Sub
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles
Button9.Click
If flag Then
TextBox1.Text = Button9.Text
flag = False
Else
TextBox1.Text += Button9.Text
End If
End Sub
Private Sub Button10_Click(sender As Object, e As EventArgs) Handles
Button10.Click
If flag Then
TextBox1.Text = Button10.Text
flag = False
Else
TextBox1.Text += Button10.Text
End If
End Sub
Private Sub Button11_Click(sender As Object, e As EventArgs) Handles
Button11.Click
If flag Then
TextBox1.Text = Button11.Text
flag = False
Else
TextBox1.Text += Button11.Text
End If
End Sub
Private Sub Button14_Click(sender As Object, e As EventArgs) Handles
Button14.Click
If flag Then
TextBox1.Text = Button14.Text
flag = False
Else
TextBox1.Text += Button14.Text
End If
End Sub
Private Sub Button15_Click(sender As Object, e As EventArgs) Handles
Button15.Click
If Not (TextBox1.Text.Contains(".")) Then
TextBox1.Text += "."
End If
End Sub
Private Sub Button16_Click(sender As Object, e As EventArgs) Handles
Button16.Click
TextBox1.Text = Nothing
flag = True
opr = 0
opr2 = 0
result = 0
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles
Button4.Click
op = "+"
opr = Val(TextBox1.Text)
flag = True
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles
Button8.Click
If flag = True Then
TextBox1.Text = "-"
flag = False
Else
op = "-"
opr = Val(TextBox1.Text)
flag = True
End If
End Sub
Private Sub Button12_Click(sender As Object, e As EventArgs) Handles
Button12.Click
op = "*"
opr = Val(TextBox1.Text)
flag = True
End Sub
Private Sub Button17_Click(sender As Object, e As EventArgs) Handles
Button17.Click
op = "/"
opr = Val(TextBox1.Text)
flag = True
End Sub
Private Sub Button13_Click(sender As Object, e As EventArgs) Handles
Button13.Click
opr2 = Val(TextBox1.Text)
Select Case op
Case "+"
result = opr + opr2
Case "-"
result = opr - opr2
Case "*"
result = opr * opr2
Case "/"
result = opr / opr2
Case "^"
result = opr ^ opr2
End Select
TextBox1.Text = result
End Sub
Private Sub Button18_Click(sender As Object, e As EventArgs) Handles
Button18.Click
op = "^"
opr = Val(TextBox1.Text)
flag = True
End Sub
End Class
Assignment 6
Program: Demonstrate the concept of Try.
Catch in Quadratic Equation Problem Solving
using VB.net
‘Window Forms Coding:
Public Class Form1
Dim a, b As Integer
Dim c As UInteger = 0
Dim r1, r2 As Decimal
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles
Button2.Click
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim dn As Decimal
Try
a = CInt(TextBox1.Text)
b = CInt(TextBox2.Text)
c = CInt(TextBox3.Text)
Catch ex As exception
MsgBox("please enter valid input")
End Try
dn = ((b * b) - (4 * a * c))
Try
If (dn > 0) Then
r1 = (-b + Math.Sqrt(dn)) / (2 * a)
r2 = (-b - Math.Sqrt(dn)) / (2 * a)
Else
If (dn = 0) Then
r1 = r2 = (-b + Math.Sqrt(dn)) / (2 * a)
Else
MsgBox("imagianry roots ")
TextBox5.Text = "imag!"
TextBox4.Text = "imag!"
End If
End If
Catch ex As Exception
MsgBox("Exception occured ! Equation is not correct, please try again with
correct equation")
TextBox4.Clear()
TextBox3.Clear()
TextBox2.Clear()
TextBox1.Clear()
TextBox5.Clear()
End Try
TextBox4.Text = r1.ToString
TextBox5.Text = r2.ToString
End Sub
End Class

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";
}

private void timer1_Tick(object sender, EventArgs e)


{
if (a == 1)
{
count = 10;
pictureBox1.Visible = false;
pictureBox2.Visible = false;
pictureBox3.Visible = true;
txt_msg.Text = "Have a safe journey";
timer1.Interval = 10000;
a = 2;
}
else if (a == 2)
{
count = 10;
pictureBox1.Visible = false;
pictureBox2.Visible = true;
pictureBox3.Visible = false;
txt_msg.Text = "slow down your vehicle";
timer1.Interval = 10000;
a = 3;
}
else if (a == 3)
{
count = 10;
pictureBox1.Visible = true;
pictureBox2.Visible = false;
pictureBox3.Visible = false;
txt_msg.Text = "stop your vehicle";
timer1.Interval = 10000;
a = 1;
}
}

private void timer2_Tick(object sender, EventArgs e)


{
lbl_red.Text = count.ToString();
count = count - 1;

private void Form1_Load(object sender, EventArgs e)


{

}
}
}
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

23. Write a program, using recursive function to generate Fibonacci


Series.Public Class Form2. Write a program, using recursive function to
generate Fibonacci Series.Public Class Form1Function fib(ByVal n As
Integer) As IntegerIf (n = 0 Or n = 1) ThenReturn nElseReturn fib(n - 1) +
fib(n - 2)End IfEnd FunctionPrivate Sub Button1_Click(sender As Object,
e As EventArgs) Handles Button1.ClickDim n As Integer =
TextBox2.TextWhile (n >= 0)Dim s As String = fib(n)TextBox1.Text += s +
" "n -= 1End WhileEnd SubEnd Class
24. Write a program to add two matricesModule Module1Sub
Main()Dim m, n, c, d As Int16Dim first(,) As Int16 = New Int16(5, 5)
{}Dim second(,) As Int16 = New Int16(5, 5) {}Dim sum(,) As Int16 = New
Int16(5, 5) {}Console.WriteLine("Enter the number of rows and columns
of matrix")m = Convert.ToInt16(Console.ReadLine())n =
Convert.ToInt16(Console.ReadLine())Console.WriteLine("\nEnter the
elements of first matrix\n")c = 0While c < md = 0While d <
nConsole.WriteLine("Enter Element [" + c.ToString() + " , " + d.ToString()
+ "]")first(c, d) = Convert.ToInt16(Console.ReadLine())d = d + 1End
Whilec = c + 1End WhileConsole.WriteLine("Enter the elements of
second matrix")c = 0While c < md = 0While d <
nConsole.WriteLine("Enter Element [" + c.ToString() + " , " + d.ToString()
+ "]")

You might also like