0% found this document useful (0 votes)
33 views54 pages

Lab Manual - CA-322 Advanced Technology Lab

The document provides guidelines for students taking an Advanced Technology Lab course. It includes the course objectives, outcomes, vision, and mission statements. It also lists the experiments to be completed over 8 weeks, including creating applications using various controls and connecting to a database using ADO.NET.

Uploaded by

Akash Yadav
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)
33 views54 pages

Lab Manual - CA-322 Advanced Technology Lab

The document provides guidelines for students taking an Advanced Technology Lab course. It includes the course objectives, outcomes, vision, and mission statements. It also lists the experiments to be completed over 8 weeks, including creating applications using various controls and connecting to a database using ADO.NET.

Uploaded by

Akash Yadav
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/ 54

INTEGRAL UNIVERSITY LUCKNOW

Dasauli, Bas-ha Kursi Road, Lucknow – 226026

Department of Computer Application

LAB MANUAL

Session : 2021-2022

Subject Name : Advanced Technology Lab

Subject Code : CA322

Branch : BCA

Year : 3rd
6th
Semester :

Department of Computer Application (CA 322)


Revision History
REVISION HISTORY

REVISION AUTHOR(S) REVIEWER(S) DATE OF OWNER SUMMARY OF


RELEASE CHANGES
Revision -1 Mr. Pradeep Internal 04/03/2022 HOD - Initial Release
Kumar Singh Reviewers CA

Revision -2 Mr. Malik Departmental 05/03/2022 HOD - Major revisions


Shahzad Iqbal QAC CA made. Incorporated
review comments
from departmental
QAC into Revision-2

Department of Computer Application (CA 322)


Vision
• To lead the teeming millions of the world through the wilderness of ignorance and
illiteracy, as "Kindly Light" (Exodus 13:21) with the resounding divine
proclamation. "Read: Thy Lord is the most bounteous (Quran 30:96:3)." and to
educate them in the most constructive and innovative ways.

• To integrate the ebullience, intellect and dynamism of youth with decency,


decorum, discipline and dedication through value-based quality education.

Mission
• To make every student a role model of intellectuals and torch bearer for others all
over the world through his / her inspiring existence.

• To inculcate a spirit of confidence, self-respect and firm commitment in students


along with farsighted wisdom and understanding.

• To make India a self-reliant and dominant G-1 country recognized for quality
education, higher economic growth and valuable moral practices.

Department of Computer Application (CA 322)


Programme Educational Objectives (PEO)

• To acquaint students about principles of system analysis, design, development and


project management.
• To impact knowledge about various sub domains related to the field of computer science
and applications.
• To apply IT practices to model and analyze the real-life problems and interpret the
results.
• To build and lead cross-functional teams, upholding the professional responsibilities &
ethical values.

Programme Outcomes (PO)

• Ability to demonstrate knowledge of Computer science and its applications in order to


enhance basic understanding of various software technologies.
• Ability to analyze and identify various business and technical problems to further solve
problems with effective communication.
• Ability to adapt analytical, logical and managerial skills with the technical aspects in
order to design and deploy reliable software programs and application for real world
problems.
• Ability to investigate complex problems and provide computer-based solutions.
• Ability to understand and deliver ethical, social and cultural responsibilities in
professional environment as an individual and team.
• Ability to adapt new technologies for upgrading their skills and contributing to a lifelong
learning.
• Ability to create and manage multidisciplinary projects and successfully apply software
and project management principles.
• Ability to become employable in a variety of IT companies and government sector and
also seek entrepreneurship opportunities for the betterment of an individual and society at
large.

Department of Computer Application (CA 322)


Course Objectives: (CA322 Advanced Technology Lab)

1. Able to understand the use of .Net Frameworks

2. Able to solve real world problems using OOP techniques.

3. Able to understand the use various properties, methods, and events.

4. Able to understand the use of Packages and Interface in .Net

5. Able to develop and understand console, window and web applications

6. Able to understand connectivity with vb.net

7. Able to design GUI based applications and develop web applications.

8. Able to understand ADO.Net

Course outcome

After undergoing this laboratory module, the participant should be able to:

1. Understand .NET Framework and describe some of the major enhancements to the new
version of Visual Basic.
2. Describe the basic structure of a Visual Basic.NET project and use main features of the
integrated development environment (IDE)
3. Design forms to test its various properties, methods, and events.
4. Create a rich GUI for web based application using a rich set of controls.
5. To Create a data base in M S Access and SQL Express Server and Able to understand
ADO.NET classes to access databases.

Department of Computer Application (CA 322)


Guidelines for the Students

1. The students should implement the given Program individually.

2. While conducting the experiments students should see that their programs would Meet
the following criteria:

I. Programs should be interactive with appropriate prompt messages, error messages


if any, and descriptive messages for outputs.

II. Programs should perform input validation (Data type, range error, etc.) and give
appropriate error messages and suggest corrective actions.

III. Comments should be used to give the statement of the problem and every function
should indicate the purpose of the function, inputs and outputs

IV. Statements within the program should be properly indented.

V. Use meaningful names for variables and functions.

VI. Make use of Constants and type definitions wherever needed.

3.Once the experiment(s) get executed, they should show the program and
results to the instructors and copy the same in their Lab Report.
4. Students should be regular and come prepared for the lab practice.
5. In case a student misses a class, it is his/her responsibility to complete that
missed experiment(s).
6. Students should bring the lab Report, class notes can be kept ready for
reference if required.

Department of Computer Application (CA 322)


List of Lab Experiments

Week Experime Name of the Experiments Page No.


No nt No.
Week-1
1 Observe and Draw Visual .NET IDE layout and hands on practice to create save 8
1 and open the project.
2 Write, test and debug at least five loop, array and operator based VB.NET
programs.
Week-2
2 3 Design forms and write, test and debug programs to test its various properties, 12
methods, and events
4 Write, test and debug program to test inputbox and message box.
Week-3
5 Write, test and debug applications to use textbox, label, and button. 18
3
6 Write, test and debug applications to use radio button, checkbox, numericupdown
and group box controls.
Week-4
7 Write, test and debug application using datetimepicker, listbox, combo box, picture 23
4 box
8 Write, test and debug application using rich text box, progress bar, masked text
box, link label.
Week-5
5 9 Write, test and debug application using checked list box, scroll bars, timer. 29

Week-6
6 10 Write, test and debug applications using sub procedures and functions. 34

Week-7

7 11 Write, test and debug applications using math and string manipulation functions. 36

Week-8

8 12 Create and test connection using ADO.NET to view SQL Express 41


Server/Microsoft Access data in textbox controls.
Week-9

9 13 Write, test and debug small application to add, edit, search, and delete record in 48
database in unbounded mode i.e. through coding

Department of Computer Application (CA 322)


Week-1
OBJECTIVE: Observe and Draw Visual .NET IDE layout and hands on practice to create save
and open the project

Visual studio Environment

Overview of the VS.NET IDE

➢ Single IDE for all Languages.

➢ Server Explorer

➢ Event Viewer, Message Queues, Services

➢ SQL Databases, Data Connection, Etc.

➢ Integrated IE Browser

➢ HTML/XML Editors

➢ Dynamic Help

➢ Common Forms Editor

➢ VB.NET, C++, and C#

➢ Project: contains files for a part of the solution

➢ Project file is used to create an executable application

➢ Every project has a type (Console, Windows, etc.)

➢ Every project has an entry point: A Sub procedure named Main or a Form

Create a project

Create a Visual Basic application project. The project type comes with all the template files
you'll need, before you've even added anything.

1. Open Visual Studio.

2. On the start window, choose Create a new project.

Department of Computer Application (CA 322)


3. On the Create a new project window, select the Windows Forms App (.NET
Framework) template for Visual Basic.

4. In the Configure your new project window, enter HelloWorld as the Project name.
Then, select Create.

Department of Computer Application (CA 322)


Week-2
OBJECTIVE: Write, test and debug at least five loop, array and operator based VB.NET
programs.

Do Loop

Syntax:

Do { While | Until } condition

[ statements ]

[ Continue Do ]

[ statements ]

[ Exit Do ]

[ statements ]

Loop

-or

Do

[ statements ]

[ Continue Do ]

[ statements ]

[ Exit Do ]

[ statements ]

Loop { While | Until } condition


Program

Module loops
Sub Main() ' local variable definition
Dim a As Integer = 10 'do loop execution
Do
Console.WriteLine("value of a: {0}", a)
a=a+1
Loop While (a < 20)
Console.ReadLine()
Department of Computer Application (CA 322)
End Sub
End Module
Output

value of a: 10

value of a: 11

value of a: 12

value of a: 13

value of a: 14

value of a: 15

value of a: 16

value of a: 17

value of a: 18

value of a: 19

For Each…Next Loop

For Each element [ As datatype ] In group

[ statements ]

[ Continue For ]

[ statements ]

[ Exit For ]

[ statements ]

Next [ element ]

Program

Module loops

Sub Main()

Dim anArray() As Integer = {1, 3, 5, 7, 9}

Dim arrayItem As Integer

Department of Computer Application (CA 322)


'displaying the values

For Each arrayItem In anArray

Console.WriteLine(arrayItem)

Next

Console.ReadLine()

End Sub

End Module

Output

While… End While Loop

While condition

[ statements ]

[ Continue While ]

[ statements ]

[ Exit While ]

[ statements ]

End While

Program

Module loops
Sub Main()
Dim a As Integer = 10
' while loop execution '
While a < 20
Console.WriteLine("value of a: {0}", a)
Department of Computer Application (CA 322)
a=a+1
End While
Console.ReadLine()
End Sub
End Module

Output

value of a: 10

value of a: 11

value of a: 12

value of a: 13

value of a: 14

value of a: 15

value of a: 16

value of a: 17

value of a: 18

value of a: 19

Department of Computer Application (CA 322)


VB.NET Arrays

An array is a linear data structure that is a collection of data elements of the same type stored on
a contiguous memory location. Each data item is called an element of the array. It is a fixed size
of sequentially arranged elements in computer memory with the first element being at index 0
and the last element at index n - 1, where n represents the total number of elements in the array.

The following is an illustrated representation of similar data type elements defined in the
VB.NET array data structure.

In the above diagram, we store the Integer type data elements in an array starting at index 0. It
will continue to store data elements up to a defined number of elements.
Declaration of VB.NET Array

Dim array_name As [Data_Type] ()

In the above declaration, array_name is the name of an array, and the Data_Type represents the
type of element (Integer, char, String, Decimal) that will to store contiguous data elements in the
VB.NET array.

Example:

'Store only Integer values


Dim num As Integer() or Dim num(5) As Integer
'Store only String values
Dim name As String() or Dim name(5) As String
' Store only Double values
Dim marks As Double()

Initialization of VB.NET Array


In VB.NET, we can initialize an array with New keyword at the time of declaration.

For example,
Department of Computer Application (CA 322)
'Declaration and Initialization of an array elements with size 6
Dim num As Integer() = New Integer(5) { }
Dim num As Integer() = New Integer(5) {1, 2, 3, 4, 5, 6}
Initialize an array with 5 elements that indicates the size of an array
Dim arr_name As Integer() = New Integer() {5, 10, 5, 20, 15}
Declare an array
Dim array1 As Char()
array1 = New Char() {'A', 'B', 'C', 'D', 'E'}
Example:
Imports System
Module num_Array
Sub Main()
Dim i As Integer, Sum As Integer = 0
'In VB.NET the size of an array is n+1
'Declaration and Initialization of marks() array
Dim marks() As Integer = {58, 68, 95, 50, 23, 89}
Console.WriteLine(" Marks in 6 Subjects")
For i = 0 To marks.Length - 1
Console.WriteLine(" Marks {0}", marks(i))
Sum = Sum + marks(i)
Next
Console.WriteLine(" Grand total is {0}", Sum)

Console.WriteLine(" Press any key to exit...")


Console.ReadKey()
End Sub
End Module
Output:

1. Write a Console Program to take 10 input values from user and print 10 values
using Array.

Module Module1
Sub Main()
Dim a(10) As Integer

Department of Computer Application (CA 322)


Console.WriteLine("Enter 10 Number")
For i As Integer = 0 To 10
a(i) = CInt(Console.ReadLine())
Next
For i As Integer = 0 To 10
Console.WriteLine("Num is " & a(i))
Next
Console.ReadLine()
End Sub
End Module
2. Write a Console Program for Calculator to perform operation like +,-,*,/,%.
Module Module1
Sub Main()
Dim a As Double
Dim b As Double
Dim c As Double
Console.WriteLine("Enter 2 Values")
a = CDbl(Console.ReadLine())
b = CDbl(Console.ReadLine())
Console.WriteLine("Select Operation")
Console.WriteLine("Press 1 for Sum")
Console.WriteLine("Press 2 for Substraction")
Console.WriteLine("Press 3 for Multiplication")
Console.WriteLine("Press 4 for Division")
Console.WriteLine("Press 5 for Modulo")
c = CInt(Console.ReadLine())
Select Case c
Case 1 : Console.WriteLine("Sum of 2 Num is " & (a + b))
Case 2 : Console.WriteLine("Substraction of 2 Num is " & (a - b))
Case 3 : Console.WriteLine("Multiplication of 2 Num is " & (a * b))
Case 4 : Console.WriteLine("Division of 2 Num is " & (a / b))
Case 5 : Console.WriteLine("Modulo of 2 Num is " & (a Mod b))
End Select
Console.ReadLine()
End Sub
End Module
Output:

Department of Computer Application (CA 322)


Week-3

Objective: - Design forms and write, test and debug programs to test its various properties, methods, and events

How to Create a TextBox

Step 1) To create a TextBox, drag the TextBox control from the toolbox into the WindowForm:

Step 2)
1. Click the TextBox Control that you have added to the form.
2. Move to the Properties section located on the bottom left of the screen. Change the name
of the text box from TextBox1 to HelloTextBox:

Department of Computer Application (CA 322)


Step 3) Add the following code to add text to the control:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


'Add text to the control
HelloTextBox.Text = "Hello. Welcome to Guru99!"
End Sub
Step 4) You can now run the code by clicking the Start button located at the top bar:

Step 5) You should get the following form:

Here is a screenshot of the complete code for the above:

Department of Computer Application (CA 322)


Experiment 2: Write, test and debug program to test inputbox and message box.

The InputBox( ) Function


An InputBox( ) function will display a message box where the user can enter a value or a
message in the form of text. In VB2005, you can use the following format:

myMessage=InputBox(Prompt, Title, default_text, x-position, y-position)


myMessage is a variant data type but typically it is declared as string, which accept the message
input by the users. The arguments are explained as follows:

Prompt - the message displayed normally as a question asked.

Title - The title of the Input Box.

default-text - The default text that appears in the input field where users can use it as his
intended input or he may change to the message he wish to enter.

x-position and y-position - the position or tthe coordinates of the input box.

However, the format won't work in Visual Basic 2012 because InputBox is considered a
namespace. So, you need to key in the full reference to the Inputbox namespace, which is

Microsoft.VisualBasic.InputBox(Prompt, Title, default_text, x-position, y-position)


The parameters remain the same.

Example
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim userMsg As String
userMsg = Microsoft.VisualBasic.InputBox("What is your message?", "Message Entry
Form", "Enter your messge here", 500, 700)
If userMsg <> "" Then
MessageBox.Show(userMsg)
Else
MessageBox.Show("No Message")
End If
End Sub
The inputbox will appear as shown in the figure below when you press the command button

Department of Computer Application (CA 322)


MsgBox ( ) Function

The objective of MsgBox is to produce a pop-up message box and prompt the user to click on a
command button before he /she can continues. This format is as follows:

yourMsg=MsgBox(Prompt, Style Value, Title)

The first argument, Prompt, will display the message in the message box. The Style Value will
determine what type of command buttons appear on the message box, please refer to Table 12.1
for types of command button displayed. The Title argument will display the title of the message
board.

Table 12.1: Style Values

Style Value Named Constant Buttons Displayed

0 vbOkOnly Ok button

1 vbOkCancel Ok and Cancel buttons

2 vbAbortRetryIgnore Abort, Retry and Ignore buttons.

3 vbYesNoCancel Yes, No and Cancel buttons

4 vbYesNo Yes and No buttons

5 vbRetryCancel Retry and Cancel buttons

We can use named constants in place of integers for the second argument to make the programs
more readable. In fact, Visual Basic 2012 will automatically shows up a list of named constants
where you can select one of them.

For example:
yourMsg=MsgBox( "Click OK to Proceed", 1, "Startup Menu")
and
Department of Computer Application (CA 322)
yourMsg=Msg("Click OK to Proceed". vbOkCancel,"Startup Menu")
are the same.
yourMsg is a variable that holds values that are returned by the MsgBox ( ) function. The values
are determined by the type of buttons being clicked by the users. It has to be declared as Integer
data type in the procedure or in the general declaration section. Table 12.2 shows the values, the
corresponding named constant and buttons.
Table 12.2 : Return Values and Command Buttons

Value Named Constant Button Clicked

1 vbOk Ok button

2 vbCancel Cancel button

3 vbAbort Abort button

4 vbRetry Retry button

5 vbIgnore Ignore button

6 vbYes Yes button

7 vbNo No button

Example
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim testmsg As Integer
testmsg = MsgBox("Click to test", 1, "Test message")
If testmsg = 1 Then
MessageBox.Show("You have clicked the OK button")
Else
MessageBox.Show("You have clicked the Cancel button")
End If
End Sub

To make the message box looks more sophisticated, you can add an icon besides the message.
There are four types of icons available in VB2012 as shown in Table

Table 12.3 Types of Icons


Value Named Constant Icon
Department of Computer Application (CA 322)
16 vbCritical

3 vbQuestion

48 vbExclamation

64 vbInformation

Example
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim testMsg As Integer
testMsg = MsgBox("Click to Test", vbYesNoCancel + vbExclamation, "Test
Message")
If testMsg = 6 Then
MessageBox.Show("You have clicked the yes button")
ElseIf testMsg = 7 Then
MessageBox.Show("You have clicked the NO button")
Else
MessageBox.Show("You have clicked the Cancel button")
End If
End Sub

The first argument, Prompt, will display the message

Department of Computer Application (CA 322)


Week-4

Objective: Write, test and debug applications to use textbox, label, and button.

Labels provide text information (as well as optional images) and are defined with class Label (a
derived class of Control).

A Label displays text that the user cannot directly modify.

A Label's text can be changed programmatically by modifying the Label's Text property. Figure
1 lists common Label properties.

Figure1 Common Label properties.

Common Label properties Description

Font The font of the text on the Label.

Text The text on the Label.

TextAlign The alignment of the Label's text on the controlhorizontally (left,


center or right) and vertically (top, middle or bottom).

A textbox (class TextBox) is an area in which either text can be displayed by a program or the
user can type text via the keyboard.

A password TextBox is a TextBox that hides the information entered by the user. As the user
types characters, the password TextBox masks the user input by displaying a character you
specify (usually *). If you set the PasswordChar property, the TextBox becomes a password
TextBox. Users often encounter both types of TextBoxes, when logging into a computer or Web
sitethe username TextBox allows users to input their usernames; the password TextBox allows
users to enter their passwords.

TextBox properties and events.

TextBox properties
Description
and events

Common Properties

AcceptsReturn If TRue in a multiline TextBox, pressing Enter in the TextBox creates a


new line. If false, pressing Enter is the same as pressing the
default Button on the Form. The default Button is the one assigned to

Department of Computer Application (CA 322)


TextBox properties and events.

TextBox properties
Description
and events

a Form's AcceptButton property.

Multiline If true, the TextBox can span multiple lines. The default value is false.

PasswordChar When this property is set to a character, the TextBox becomes a password
box, and the specified character masks each character the user type. If no
character is specified, the TextBox displays the typed text.

ReadOnly If true, the TextBox has a gray background, and its text cannot be edited.
The default value is false.

ScrollBars For multiline textboxes, this property indicates which scrollbars appear
(None, Horizontal, Vertical or Both).

Text The TextBox's text content.

Common Event

TextChanged Generated when the text changes in a TextBox (i.e., when the user adds or
deletes characters). When you double click the TextBox control in Design
mode, an empty event handler for this event is generated.

Figure 2 lists the common properties and a common event of TextBoxes.

A button is a control that the user clicks to trigger a specific action or to select an option in a
program. As you will see, a program can use several types of buttons, such as checkboxes and
radio buttons.

All the button classes derive from class ButtonBase (namespace System.Windows.Forms), which
defines common button features. In this section, we discuss class Button, which typically enables
a user to issue a command to an application. Figure 1 lists common properties and a common
event of class Button.

Figure 1 Button properties and event.

Button properties
Description
and events

Common
Department of Computer Application (CA 322)
Figure 1 Button properties and event.

Button properties
Description
and events

Properties

Text Specifies the text displayed on the Button face.

FlatStyle Modifies a Button's appearanceattribute Flat (for the Button to display


without a three-dimensional appearance), Popup (for the Button to appear
flat until the user moves the mouse pointer over
the Button), Standard (tHRee-dimensional) and System, where the Button's
appearance is controlled by the operating system. The default value
is Standard.

Common Event

Click Generated when the user clicks the Button. When you double click
a Button in design view, an empty event handler for this event is created.

Figure 2 uses a TextBox, a Button and a Label. The user enters text into a password box and
clicks the Button, causing the text input to be displayed in the Label.

Normally, we would not display this textthe purpose of password TextBoxes is to hide the text
being entered by the user. When the user clicks the Show Me Button, this application retrieves
the text that the user typed in the password TextBox and displays it in another TextBox.

Figure 2. Program to display hidden text in a password box.

// Fig. 13.20: LabelTextBoxButtonTestForm.cs

// Using a TextBox, Label and Button to display

// the hidden text in a password TextBox.

using System;

using System.Windows.Forms;

// Form that creates a password TextBox and

// a Label to display TextBox contents

public partial class LabelTextBoxButtonTestForm : Form


Department of Computer Application (CA 322)
{

// default constructor

public LabelTextBoxButtonTestForm()

InitializeComponent();

} // end constructor

// display user input in Label

private void displayPasswordButton_Click(

object sender, EventArgs e )

// display the text that the user typed

displayPasswordLabel.Text = inputPasswordTextBox.Text;

} // end method displayPasswordButton_Click

} // end class LabelTextBoxButtonTestForm

Department of Computer Application (CA 322)


Week-5

Objective: Write, test and debug applications to use radio button, checkbox, numericupdown
and group box controls.

RadioButton

The RadioButton control is used to provide a set of mutually exclusive options. The user can
select one radio button in a group. If you need to place more than one group of radio buttons in
the same form, you should place them in different container controls like a GroupBox control.

Let's create a RadioButton control in the VB.NET Windows by using the following steps.

Step 1: Drag the RadioButton control from the toolbox and drop it to the Windows form, as
shown below.

Step 2: Once the RadioButton is added to the form, we can set various properties of the
RadioButton by clicking on the Radio control.

RadioBtn.vb

Public Class RadioBtn

Department of Computer Application (CA 322)


Private Sub RadioBtn_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Text = "javaTpoint.com" ' Set the title of the form
Label1.Text = "Select the Gender"
RadioButton1.Text = "Male" ' Set the radiobutton1 and radiobutton2
RadioButton2.Text = "Female"
RadioButton3.Text = "Transgender"
Button1.Text = "Submit" ' Set the button name
Button2.Text = "Exit"
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


Dim gen As String
If RadioButton1.Checked = True Then
gen = "Male"
MsgBox(" Your gender is : " & gen)

ElseIf RadioButton2.Checked = True Then


gen = "Female"
MsgBox(" Your gender is : " & gen)
Else
gen = "Transgender"
MsgBox(" You have Selected the gender : " & gen)
End If

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click


End 'Terminate the program
End Sub
End Class

Department of Computer Application (CA 322)


Click on the Submit button. It shows the following message on the screen.

CheckBox Control:

The CheckBox control is a control that allows the user to select or deselect options from the
available options. When a checkbox is selected, a tick or checkmark will appear on the Windows
form.

Let's create a CheckBox control in the VB.NET Windows form using the following steps.

Step 1: We need to drag the CheckBox control from the toolbox and drop it to the Windows
form, as shown below.

Department of Computer Application (CA 322)


Step 2: Once the CheckBox is added to the form, we can set various properties of the checkbox
by clicking on the CheckBox control.

Checkbx.vb

Public Class Checkbxvb


Private Sub Checkbxvb_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Text = "javaTpoint.com" ' Set the title name of the form
Label1.Text = "Select the fruits name"
CheckBox1.Text = "Apple"
CheckBox2.Text = "Mango"
CheckBox3.Text = "Banana"
CheckBox4.Text = "Orange"
CheckBox5.Text = "Potato"
CheckBox6.Text = "Tomato"
Button1.Text = "Submit"
Button2.Text = "Close"
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim fruit As String
fruit = " "
If CheckBox1.Checked = True Then
fruit = "Apple"
End If
If CheckBox2.Checked = True Then
'fruit = CheckBox2.Text
fruit = fruit & " Mango"
End If
If CheckBox3.Checked = True Then
Department of Computer Application (CA 322)
fruit = fruit & " Banana"
End If
If CheckBox4.Checked = True Then
fruit = fruit & " Orange"
End If
If CheckBox5.Checked = True Then
fruit = fruit & " Potato"
End If
If CheckBox6.Checked = True Then
fruit = fruit & " Tomato"
End If
If fruit.Length <> 0 Then
MsgBox(" Selected items " & fruit)
End If
CheckBox1.ThreeState = True
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
End 'terminate the program
End Sub
End Class

Now select the fruit name by clicking on the items.

Department of Computer Application (CA 322)


Now click on the Submit button, it displays the following output on your screen.

NumericUpDown control:

A NumericUpDown control allows users to provide a spin (up/down) interface to move through
pre-defined numbers using up and down arrows

GroupBox control:

A GroupBox control is a container control that is used to place Windows Forms child controls in
a group. The purpose of a GroupBox is to define user interfaces where we can categories related
controls in a group.

Department of Computer Application (CA 322)


Week-6
Objective: Write, test and debug application using datetimepicker, listbox, combo box, picture
box

DateTimePicker Control

The DateTimePicker control allows the user to select or display date and time values with a
specified format in Windows Forms. Furthermore, we can determine the current date and time
using the Value property of the DateTimePicker control. By default, the Value property returns
the current date and time in the DateTimePicker.

Let's create a DateTimePicker control in the VB.NET Windows form using the following steps.

Step 1: The first step is to drag the DateTimePicker control from the toolbox and drop it on to
the form.

Step 2: Once the DateTimePicker is added to the form, we can set various properties of
the DateTimePicker by clicking on the DateTimePicker control.

DateTime.vb

1. Public Class DateTime


2. Private Sub DateTime_Load(sender As Object, e As EventArgs) Handles MyBase.Loa
d
3. Me.Text = "javatpoint.com"
Department of Computer Application (CA 322)
4. Button1.Text = "Calculate Days"
5. Label1.Text = "Calculate the total days from your date of birth to the current date."
6. Label2.Text = "Total Days"
7. Label3.Text = "Select the DOB"
8. Label4.Text = "Current Date"
9. DateTimePicker1.Format = DateTimePickerFormat.Long
10. End Sub
11. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

12. Dim dp As Date = DateTimePicker1.Value


13. Dim dp2 As Date = DateTimePicker2.Value
14. Dim result As TimeSpan = dp.Subtract(dp2)
15. Dim ds As Integer = result.TotalDays
16. TextBox1.Text = ds
17. TextBox1.ForeColor = ForeColor.Red
18. MsgBox(" Days = " & ds)
19. End Sub
20. End Class

Now, we select the date of birth from the DateTimePicker Control.

Department of Computer Application (CA 322)


After selecting the DOB and the Current date from the DateTimePicker Control, now click on
the Calculate button, and it shows the following result.

ListBox Control

The ListBox control is used to display a list of items in Windows form. It allows the user to
select one or more items from the ListBox Control. Furthermore, we can add or design the list
box by using the properties and events window at runtime.

Let's create a ListBox control in the VB.NET Windows by using the following steps.

Step 1: Drag the ListBox control from the Toolbox and drop it to the Windows form, as shown
below.

Department of Computer Application (CA 322)


Step 2: Once the ListBox is added to the Form, we can set various properties of the Listbox by
clicking on the ListBox control.

Let's create a program to select an item from the ListBox in the VB.NET form.

Listbx.vb

1. Public Class Listbx


2. Private Sub Listbx_Load(sender As Object, e As EventArgs) Handles MyBase.Load
3. ' set the title of the Form.
4. Me.Text = "JavaTpoint.com"
5. ' Add the items into the ListBox
6. ListBox1.Items.Add("Earth")
7. ListBox1.Items.Add("Mercury")
8. ListBox1.Items.Add("Mars")
9. ListBox1.Items.Add("Jupiter")
10. ListBox1.Items.Add("Venus")
11. ListBox1.Items.Add("Neptune")
12. ListBox1.Items.Add("Uranus")
13. ' Set the name of the Button1 and Button2
14. Button1.Text = "Show"
15. Button2.Text = "Exit"
16. Label2.Text = "Select the solar system from the ListBox"
17. End Sub
18. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

19. Dim lt As String ' define a local variable.


Department of Computer Application (CA 322)
20. lt = ListBox1.Text 'accept the data from the ListBox1
21. MsgBox(" Selected Solar System is " & lt) ' Display the selected item
22. End Sub
23. Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Han
dles ListBox1.SelectedIndexChanged
24. Label1.Text = ListBox1.SelectedItem.ToString() 'When a user clicks on an item, it
displays the item name.
25. End Sub
26.
27. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

28. End 'End or exit an application


29. End Sub
30. End Class

Output:

Department of Computer Application (CA 322)


Week 7
Objective1: Write, test and debug application using rich text box, progress bar, masked text
box, link label.

RichTextBox control:

The RichTextBox control allows the user to display, enter, and edit text while also providing
more advanced formatting features than the conventional TextBox control.

The RichTextBox control opens and saves files in both the RTF format and regular ASCII text
format.

MaskedTextBox control:

This is a special type of TextBox which allows us to specify in what format the user will be able
to enter data into it. This is useful, for example, for entering telephone numbers and other similar
data. The user can't enter anything other than the allowed format into the box, therefore there's
no need to validate the value.

The key property here is Mask, which specifies the format of the entered value. If we don't
choose from the predefined ones, we can easily create our own. We'll select <Custom> and enter
our desired format into the Mask box below. For example, 00/00/0000 would be a format for
entering a specific date.

In addition to the zeros, we can use the L symbol for letters. If we want to allow any character
we use ?. A allows the user to enter either a letter or a number. 0 is only for numbers,
and 9 allows numbers + free space.

link label Control:

As can be deduced from the name (as with the other controls), it's simply a Label that acts as a
link to a website. The properties are also similar to the ordinary Label. However, its use isn't
very intuitive. By using the LinkArea property, we specify which part of the LinkLabel can be
clicked on. Start specifies the start index, and Length specifies the number of characters. The
basic usage could look like this:

LinkLabel.Link link = new LinkLabel.Link();

link.LinkData = "https://www.ict.social/";

Department of Computer Application (CA 322)


linkLabel1.Links.Add(link);

We put the code above into the form constructor or the Load event handler of the form. The main
event of LinkLabel is LinkClicked. It's necessary to write the following code in it:

Process.Start(e.Link.LinkData as String);

It'll send a command to the system, and the set URL will be opened in the default browser. To
use this, you must first add using System.Diagnostics.

ProgressBar control:

The Window ProgressBar control is used by the user to acknowledge the progress status of some
defined tasks, such as downloading a large file from the web, copying files, installing software,
calculating complex results, and more.

Let's create a ProgressBar by dragging a ProgressBar control from the toolbox and dropping it to
the Windows form.

Step 1: The first step is to drag the ProgressBar control from the toolbox and drop it on to the
Form.

Step 2: Once the ProgressBar is added to the Form, we can set various properties of the
ProgressBar by clicking on the ProgressBar control.

Progressbr.vb

Public Class Progressbr

Department of Computer Application (CA 322)


Private Sub Progressbr_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me
Text = "javaTpoint.com" 'Set the title name for the form
1. Button1.Text = "Show"
2. Label1.Text = "Click to display the progress status of the ProgressBar"
3. Label1.ForeColor = ForeColor.Green
4. ProgressBar1.Visible = False
5.
6. 'create a progress bars
7. Dim Progressbr2 As ProgressBar = New ProgressBar()
8.
9. 'set the progressbar position
10. Progressbr2.Location = New Point(60, 70)
11. 'set the values for Progressbr2
12. Progressbr2.Minimum = 0
13. Progressbr2.Maximum = 500
14. Progressbr2.Value = 470
15.
16. 'add the progress bar status to the form.
17. Me.Controls.Add(Progressbr2)
18.
19. End Sub
20.
21. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

22. ProgressBar1.Visible = True


23.
24. Dim i As Integer
25. ProgressBar1.Minimum = 0
26. ProgressBar1.Maximum = 300
27.
28. For i = 0 To 300 Step 1
29. ProgressBar1.Value = i
30. If i > ProgressBar1.Maximum Then
31. i = ProgressBar1.Maximum
32. End If
33. Next
34. MsgBox("Successfully Completed")
35. End Sub
36. End Class
Output:

Department of Computer Application (CA 322)


Click on the Show button to display the progress status at run time in Windows Form.

And when the progress status reaches the progress bar's maximum value, it displays the
following message.

Objective2: Write, test and debug application using checked list box, scroll bars, timer.

CheckedListBox Control

The CheckedListBox is similar to Listbox except that it displays all items in the list with a
checkbox that allows users to check or uncheck single or multiple items.

Let's create a CheckedListBox control in the VB.NET Windows form using the following steps.

Step 1: Drag the CheckedListBox control from the Toolbox and drop it to the Windows form, as
shown below.

Department of Computer Application (CA 322)


Step 2: Once the CheckedListBox is added to the Form, we can set various properties of the
CheckedListbox by clicking on the CheckedListBox control.

Let's create a program to select or check more than one item from the CheckedListBox in the VB
.NET form.

CheqListvb.vb

1. Public Class CheqListvb


2. Private Sub CheqListvb_Load(sender As Object, e As EventArgs) Handles MyBase.Lo
ad
3. Me.Text = " JavaTpoint.com"
4. CheckedListBox1.Items.Add("VB.NET")
5. CheckedListBox1.Items.Add("Java")
6. CheckedListBox1.Items.Add("Python")
7. CheckedListBox1.Items.Add("C")
8. CheckedListBox1.Items.Add("C#")
9. CheckedListBox1.Items.Add("PHP")
10. CheckedListBox1.Items.Add("JavaScript")
11. CheckedListBox1.Items.Add("Ruby Language")
12. CheckedListBox1.Items.Add("Android")
13. CheckedListBox1.Items.Add("Perl")
14. Label1.Text = "Choose one or more programming languages of your choice. "
15. Button1.Text = "Select"
16. Button2.Text = "Exit"
17. End Sub
18.
19. ' To submit the checked items, click on Button1 or Select
20. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

21. Dim cheq As New System.Text.StringBuilder


22. For Each item In CheckedListBox1.CheckedItems
Department of Computer Application (CA 322)
23. cheq.Append(item)
24. cheq.Append(" ")
25. Next
26. MessageBox.Show(" Your Checked Items are : " & cheq.ToString())
27.
28. End Sub
29.
30. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

31. End 'terminate the program


32. End Sub
Output:

In the above list, we can select more than one item from the CheckedListBox in Windows Form.

After that, click on the Select button to display the selected item in Windows Form.

Department of Computer Application (CA 322)


ScrollBars Control:

A ScrollBar control is used to create and display vertical and horizontal scroll bars on the
Windows form. It is used when we have large information in a form, and we are unable to see all
the data. Therefore, we used VB.NET ScrollBar control. Generally, ScrollBar is of two types:
HScrollBar for displaying scroll bars and VScrollBar for displaying Vertical Scroll bars.

Let's create a ScrollBar control in the VB.NET Windows form using the following steps.

Step 1: The first step is to drag the HScrollBar and VScrollBar control from the toolbox and drop
it on to the form.

Step 2: Once the ScrollBar is added to the form, we can set various properties of the ScrollBar by
clicking on the HScrollBar and VScrollBar control.

Let's create a simple program to understand the use of ScrollBar Control in the VB.NET
Windows Forms.

ScrollBar.vb
1. Public Class ScrollBar
2. Private Sub ScrollBar_Load(sender As Object, e As EventArgs) Handles MyBase.Loa
d
3. Me.Text = "javatpoint.com" 'Set the title for a Windows Form
4. Label1.Text = "Use of ScrollBar in Windows Form"
5. Label1.ForeColor = Color.Blue
6. Me.AutoScroll = True
7. Me.VScrollBar1.Minimum = 0
8. Me.VScrollBar1.Maximum = 100
9. Me.VScrollBar1.Value = 0
10. Me.VScrollBar1.BackColor = Color.Blue
11. Me.HScrollBar1.Minimum = 0
Department of Computer Application (CA 322)
12. Me.HScrollBar1.Maximum = 100
13. Me.HScrollBar1.Value = 35
14. End Sub
15. End Class

Output:

TimerControl:

This is a very handy control that allows us to perform certain actions automatically after a given
time interval has elapsed.

The key property here is Interval, which specifies the interval between actions being performed
in milliseconds. 60.000 ms is 1 minute. Quite important is also the Enabled property, which
specifies whether the Timer is active when the app is launched.

The second option is to start it using the Start() method. The Stop() method then logically stops
the Timer.

Let's create a Timer control in the VB.NET Windows form by using the following steps.

Step 1: Drag and drop the Timer control onto the window form, as shown below.

Department of Computer Application (CA 322)


Step 2: Once the Timer is added to the form, we can set various properties of the Timer by
clicking on the Timer control.

Department of Computer Application (CA 322)


Week-8

Objective1: - Write, test and debug applications using sub procedures and functions.

Defining Sub Procedures:

The Sub statement is used to declare the name, parameter and the body of a sub procedure. The
syntax for the Sub statement is −

[Modifiers] Sub SubName [(ParameterList)]

[Statements]

End Sub

Where,

Modifiers − specify the access level of the procedure; possible values are - Public, Private,
Protected, Friend, Protected Friend and information regarding overloading, overriding, sharing,
and shadowing.

SubName − indicates the name of the Sub

ParameterList − specifies the list of the parameters

Example

The following example demonstrates a Sub procedure CalculatePay that takes two parameters
hours and wages and displays the total pay of an employee −

Module mysub

Sub CalculatePay(ByRef hours As Double, ByRef wage As Decimal)

'local variable declaration

Dim pay As Double

pay = hours * wage

Console.WriteLine("Total Pay: {0:C}", pay)


Department of Computer Application (CA 322)
End Sub

Sub Main()

'calling the CalculatePay Sub Procedure

CalculatePay(25, 10)

CalculatePay(40, 20)

CalculatePay(30, 27.5)

Console.ReadLine()

End Sub

End Module

Output:

When the above code is compiled and executed, it produces the following result −

Total Pay: $250.00

Total Pay: $800.00

Total Pay: $825.00

Objective2: Create and test connection using ADO.NET to view SQL Express Server/Microsoft
Access data in textbox controls.

Create a simple data application by using ADO.NET


Create Visual Basic .NET Windows application

1. Start Visual Studio .NET, and create a new Visual Basic Windows Application project
named SQLDataAccess.

2. Open Form1. In the first line of Form1.vb, add a reference to the ADO.NET namespace
as follows:

Imports System.Data.SqlClient

3. From the Windows Start menu, point to Programs, point to Microsoft SQL Server, and
then click SQL Server Service Manager to ensure that the SQL Server service is running
on your computer.
Department of Computer Application (CA 322)
4. Set the Server property to the name of your computer, and then set the Services property
to MSSQLServer.

5. If the service isn't running, click Start.

6. Close the SQL Server Service Manager dialog box.

Create ADO.NET objects


Modify the Form1 class as follows:

Public Class Form1


Inherits System.Windows.Forms.Form
'Create ADO.NET objects.
Private myConn As SqlConnection
Private myCmd As SqlCommand
Private myReader As SqlDataReader
Private results As String

The SqlConnection object establishes a database connection, the SqlCommand object runs a
query against the database, and the SqlDataReader object retrieves the results of the query.

Use the SqlConnection object to open SQL Server connection


1. To set up the connection string of the SqlConnection object, add the following code to the
Form1_Load event procedure:

'Create a Connection object.


myConn = New SqlConnection("Initial Catalog=Northwind;" & _
"Data Source=localhost;Integrated Security=SSPI;")
2. To set up the Command object, which contains the SQL query, add the following code to
the Form1_Load event procedure:
'Create a Command object.
myCmd = myConn.CreateCommand
myCmd.CommandText = "SELECT FirstName, LastName FROM Employees"
'Open the connection.
myConn.Open()
Use the SqlDataReader object to retrieve data from SQL Server:
1. Add the following code to the Form1_Load event procedure:
myReader = myCmd.ExecuteReader()
2. When the myCmd.ExecuteReader method is executed, SqlCommand retrieves two fields
from the Employees table and creates a SqlDataReader object.

3. To display the query results, add the following code to the Form1_Load event procedure:

'Concatenate the query result into a string.


Do While myReader.Read()
Department of Computer Application (CA 322)
results = results & myReader.GetString(0) & vbTab & _
myReader.GetString(1) & vbLf
Loop
'Display results.
MsgBox(results)
The myReader.Read method returns a boolean value, which indicates whether there are
more records to be read. The results of the SQL query are displayed in a message box.
4. To close the SqlDataReader and SqlConnection objects, add the following code to the
Form1_Load event procedure:
'Close the reader and the database connection.
myReader.Close()
myConn.Close()
5. Save and run the project.

View database in Server Explorer:

1. On the View menu, click Server Explorer.


2. Right-click Data Connections, and then click Add connection.
3. In the Data Link Properties dialog box, click localhost in the Select or enter a server
name box.
4. Click Windows NT Integrated Security to log on to the server.
5. Click Select the database on the server, and then select Northwind database from the list.
6. Click Test Connection to validate the connection, and then click OK.
7. In the Server Explorer, click to expand the Data Connections tree so that
the Employees table node expands. The properties of individual fields appear in
the Properties window.

Department of Computer Application (CA 322)


Week-9

Objective: - Write, test and debug small application to add, edit, search, and delete record in
database in unbounded mode i.e. through coding
Solution:

A simple operations like save, delete, update, and search operations in a Windows Forms
application. At first, we should have a Database.

In this example my database name is "STUDENT" and database table is "student_detail" which
has four columns as "roll_no", "s_name", "age" and "course".

Create a Windows Forms Application. Take some UI controls.


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;
using System.Data.SqlClient;

namespace savedeleteupdateapp
{
public partial class Form1 : Form
{
Department of Computer Application (CA 322)
public Form1()
{
InitializeComponent();
}
SqlConnection conn;
SqlCommand comm;
SqlDataReader dreader;
string connstring = "server=localhost;database=student;user=sa;password=wintellect";
private void btnsave_Click(object sender, EventArgs e)
{
conn = new SqlConnection(connstring);
conn.Open();
comm = new SqlCommand("insert into student_detail values(" + txtrn.Text + ",'" +
txtname.Text + "'," + txtage.Text + ",'" + txtcourse.Text + "')", conn);
try
{
comm.ExecuteNonQuery();
MessageBox.Show("Saved...");
}
catch (Exception)
{
MessageBox.Show("Not Saved");
}
finally
{
conn.Close();
}
}

private void btnclear_Click(object sender, EventArgs e)


{
txtage.Clear();
txtcourse.Clear();
txtname.Clear();
txtrn.Clear();
txtrn.Focus();
}

private void btndelete_Click(object sender, EventArgs e)


{
conn = new SqlConnection(connstring);
conn.Open();
comm = new SqlCommand("delete from student_detail where roll_no = " + txtrn.Text +
" ", conn);
try
{
comm.ExecuteNonQuery();
MessageBox.Show("Deleted...");
Department of Computer Application (CA 322)
txtage.Clear();
txtcourse.Clear();
txtname.Clear();
txtrn.Clear();
txtrn.Focus();
}
catch (Exception x)
{
MessageBox.Show(" Not Deleted" + x.Message );
}
finally
{
conn.Close();
}
}

private void btnsearch_Click(object sender, EventArgs e)


{
conn = new SqlConnection(connstring);
conn.Open();
comm = new SqlCommand("select * from student_detail where roll_no = " + txtrn.Text
+ " ", conn);
try
{
dreader = comm.ExecuteReader();
if (dreader.Read())
{
txtname.Text = dreader[1].ToString();
txtage.Text = dreader[2].ToString();
txtcourse.Text = dreader[3].ToString();
}
else
{
MessageBox.Show(" No Record");
}
dreader.Close();
}
catch (Exception)
{
MessageBox.Show(" No Record");
}
finally
{
conn.Close();
}
}

private void btnupdate_Click(object sender, EventArgs e)


Department of Computer Application (CA 322)
{
conn = new SqlConnection(connstring);
conn.Open();
comm = new SqlCommand("update student_detail set s_name= '"+txtname.Text+"',
age= "+txtage.Text+" , course=' "+txtcourse.Text+"' where roll_no =
"+txtrn.Text+" ", conn);
try
{
comm.ExecuteNonQuery();
MessageBox.Show("Updated..");
}
catch (Exception)
{
MessageBox.Show(" Not Updated");
}
finally
{
conn.Close();
}
}

private void Form1_Load(object sender, EventArgs e)


{
txtrn.Focus();
}
}
}

Department of Computer Application (CA 322)

You might also like