Lab Manual - CA-322 Advanced Technology Lab
Lab Manual - CA-322 Advanced Technology Lab
LAB MANUAL
Session : 2021-2022
Branch : BCA
Year : 3rd
6th
Semester :
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 make India a self-reliant and dominant G-1 country recognized for quality
education, higher economic growth and valuable moral practices.
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.
2. While conducting the experiments students should see that their programs would Meet
the following criteria:
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
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.
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
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
➢ Server Explorer
➢ Integrated IE Browser
➢ HTML/XML Editors
➢ Dynamic Help
➢ 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.
4. In the Configure your new project window, enter HelloWorld as the Project name.
Then, select Create.
Do Loop
Syntax:
[ statements ]
[ Continue Do ]
[ statements ]
[ Exit Do ]
[ statements ]
Loop
-or
Do
[ statements ]
[ Continue Do ]
[ statements ]
[ Exit Do ]
[ statements ]
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
[ statements ]
[ Continue For ]
[ statements ]
[ Exit For ]
[ statements ]
Next [ element ]
Program
Module loops
Sub Main()
Console.WriteLine(arrayItem)
Next
Console.ReadLine()
End Sub
End Module
Output
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
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
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:
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)
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
Objective: - Design forms and write, test and debug programs to test its various properties, methods, and events
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:
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
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
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:
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.
0 vbOkOnly Ok button
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
1 vbOk Ok 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
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
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's text can be changed programmatically by modifying the Label's Text property. Figure
1 lists common Label properties.
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
Description
and events
Common Properties
TextBox properties
Description
and events
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).
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.
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.
Button properties
Description
and events
Common
Department of Computer Application (CA 322)
Figure 1 Button properties and event.
Button properties
Description
and events
Properties
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.
using System;
using System.Windows.Forms;
// default constructor
public LabelTextBoxButtonTestForm()
InitializeComponent();
} // end constructor
displayPasswordLabel.Text = inputPasswordTextBox.Text;
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
End Sub
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.
Checkbx.vb
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.
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
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.
Let's create a program to select an item from the ListBox in the VB.NET form.
Listbx.vb
Output:
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.
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:
link.LinkData = "https://www.ict.social/";
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
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.
Let's create a program to select or check more than one item from the CheckedListBox in the VB
.NET form.
CheqListvb.vb
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.
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.
Objective1: - Write, test and debug applications using sub procedures and functions.
The Sub statement is used to declare the name, parameter and the body of a sub procedure. The
syntax for the Sub statement is −
[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.
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 Main()
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 −
Objective2: Create and test connection using ADO.NET to view SQL Express Server/Microsoft
Access data in textbox controls.
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.
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.
3. To display the query results, add the following code to the Form1_Load event procedure:
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".
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();
}
}