All VB Solved Past Papers
All VB Solved Past Papers
Short Questions
Q1: what is vb.net?
Namespace:
Assembly:
Assembly is the collection of one or more EXE or DLL files. assembly is the
basic building block of .NET framework.
A value of a variable can change during program execution but the name of variable
cannot be changed.
It is a way of displaying how data flows in system and what decisions are made to
control events.
1
Prepared by: Noor-un-nisa (DIT 2017-18)
2
Prepared by: Noor-un-nisa (DIT 2017-18)
written on the basis of object. An object is the collection of data and functions.
Data type is particular type of data items, as defined by the values it can take,
the programming language are used and the operations that can be perform on it.
OR
A class is a concrete representation of an entity.it represents a group of objects,
which hold similar attributes and behavior. It provides abstraction and
encapsulation.
3
Prepared by: Noor-un-nisa (DIT 2017-18)
Syntax error are occur when we write an invalid statement in a code window.
e.g. misspelling of keyword is a syntax error.
Read only keyword specifies that a variable or property can be read but not
written.
A data table is a class in .net frame work and in simple words a data table
object represents a table from database.
A hashtable class represent a collection of key and value pairs that are
organizes based on the hash code of the key. It uses the key to access the elements in
the collection.
Class access modifier are keywords used to specify the declared accessibility of
a member or type. The different access modifiers are:
✓ Public
✓ Private
✓ Protected
✓ Friend
✓ Protected friend
For next loop executes one or more statements for a specified number of time.
4
Prepared by: Noor-un-nisa (DIT 2017-18)
Syntax:
next
Internal keyword is one of the access specifier available in .net frame work ,
that makes a type visible in a given assembly. e.g. a single dll can contain multiple
modules.
Reference types are allocated on the managed CLR heap, just like object types.
Value type are allocated on a stack just like primitive types in vb script.
Q30: what are the two main parts of .net frame work?
ANSI keyword specifies that visual basic should marshal all strings to American
national standards institute(ansi) values regardless of the name of the external
procedure being declared.
5
Prepared by: Noor-un-nisa (DIT 2017-18)
Property display the feature of an object and methods are action that can
performed by an object.
Compiler:
A type of translator which is used to convert high level language to low level
language and low level language to high level language . it reads our program at
once and display the number of error if exist.
Interpreter:
A type of translator which is used to convert high level language to low level
language and low level language to high level language.it reads our program line by
line and stop the execution of program if found any error.
Local variables:
Global variables:
Global variables are the variables that can be used by all procedure within
an application. Global variables are declared in modules.
Data grid:
Data grid is used in windows application. we cannot write the codes for data
grid properties in data grid.
Grid view:
Grid view is used in web application. we can write the code like template
column items template etc.
6
Prepared by: Noor-un-nisa (DIT 2017-18)
Custom control:
Custom controls are compiled code (dlls), easier to use, difficult to create, can
be placed in toolbox. drag and drop controls. Attributes can be set visually at design
time.
User control:
Q38: write the values of size mode property of picture box control?
✓ Normal
✓ Stretch image
✓ Auto size
✓ Centre image
✓ Zoom
7
Prepared by: Noor-un-nisa (DIT 2017-18)
Q41: what is the top.net /base class of .net that everything is derived from?
System.object
Error provider control is used to indicate invalid data on a data entry form.
65536
✓ System.data
✓ System.data.OLEDB
✓ System.data.SQLclient
Array:
“An array is a set of variable that can store similar type of data”
Array list:
8
Prepared by: Noor-un-nisa (DIT 2017-18)
Q48: what is the source code to display picture in button click event?
Picturebox1.image=image.fromfile(“image01.png”)
Code window is a text editor.it is used to write and edit the codes for the
controls/objects.it is also known as code editor window.
Constant:
9
Prepared by: Noor-un-nisa (DIT 2017-18)
Variable:
If else:
It executes one block of statement when the condition is true and the other
when it is false.
It is used for checking the result of single expression with multiple values. The
expression is evaluated at the top of structure and result of expression is compared
with different cases.
Do while loop:
It is use to execute one or more statement while the given condition is true.
Array:
Elements:
Subscript:
10
Prepared by: Noor-un-nisa (DIT 2017-18)
Timer control is use to execute one or more statements after a certain time
period. e.g we want to change he back color of form after every 10 seconds by using
timer control.
SDI:
MDI:
Tooltip is a small label that appears on the screen when user pauses a mouse
pointer over a toolbar button or control. A tool tip can appear for the control by
setting the control’s tool tip text property.
In inheritance, code of existing classes is used for making new classes. A class
that are used on the basis for inheritance is called base class or parent class.
11
Prepared by: Noor-un-nisa (DIT 2017-18)
Conversion function is used to convert one data type to another data type.
Run time error occur during the execution of program. Such error occur due
to the invalid input by the user.
Step into:
The next line of code is executed and the program pauses in break time. If the
line of code call the another procedure, the first line of other procedure is displayed.
Step over:
It execute one line of code at a time step over does not display the code in the
called procedure but only displays the lines of codes in the current procedure being
analyzed.
*Specifies that all fields from the specified table or tables are selected.
DLL is a dynamic link library. DLL file were created so that multiple programs
could use their information at the same time.
“A process of converting high level language to low level language and low
level language to high level language is called compiling”
12
Prepared by: Noor-un-nisa (DIT 2017-18)
Encapsulation is a OOP concept that binds together the data and functions that
manipulate the data and that keeps safe from outside interference and misuse.
The friend keyword in the declaration specifies that the elements can be
accessed only within the same assembly but not from outside the assembly.
“ The control which is automatically present in the tool box when you start a
visual basic project are called intrinsic control.”
13
Prepared by: Noor-un-nisa (DIT 2017-18)
is used.
Any type of value can be used in visual basic without storing in variable. e.g a=a+10
10 is a literal constant.
✓ Click
✓ Load
✓ Tick
✓ Double click
✓ Mouseup
14
Prepared by: Noor-un-nisa (DIT 2017-18)
whether or not a piece of code is running, and what resources it can use when it is
running.
✓ Public
✓ Private
✓ Friend
✓ Protected
✓ Protected friend
✓ Focus
✓ Clear
Label1.backcolor=color.green
Button1.backcolor=color.blue
Textbox1.backcolor=color.pink
✓ Private assembly
15
Prepared by: Noor-un-nisa (DIT 2017-18)
✓ Shared assembly
✓ Scalability
✓ Data source independence
✓ Interoperability
✓ Performance
✓ Firewall
Unboxing is the explicit conversion from the reference to a value type e.g
class, interface.
16
Prepared by: Noor-un-nisa (DIT 2017-18)
Break point is used to break a code at specific line when user get a runtime
error or pauses project execution.
17
Prepared by: Noor-un-nisa (DIT 2017-18)
18
Prepared by: Noor-un-nisa (DIT 2017-18)
✓ Dataset
✓ Data adapter
Statement
Next
By using menu strip we can add menues to a form. The menu strip control is
a multiple document interface.
Label:
Label is used to add caption for any control which display on a form.
Textbox:
It is used to get input and display information on run time, for this reason it is
mostly used control.
A vertical bar on the right side of window and a horizontal bar at the bottom
19
Prepared by: Noor-un-nisa (DIT 2017-18)
of the window that is used is used to move the content up and down and right and
left is known as scroll bar.
Specifies that visual basic should marshal all strings to Unicode values
regardless of the name of the external procedure being declared.
20
Prepared by: Noor-un-nisa (DIT 2017-18)
that can hold all possible values of the original class or structure.
Declares the name, parameter and codes that define a function procedure.
Declares the name, parameter and codes that defines a sub procedure.
Declares the operator symbols, operands and the codes that define a
operator procedure on a class or structure.
Declares the name of the property, and the property procedure used to
21
Prepared by: Noor-un-nisa (DIT 2017-18)
Return a type object for the specified type. The type object provide
information about the type such as its properties , methods and events.
Uses short circuit evaluation to conditionally return one of two values. The
if operator can be called with three arguments or with two arguments.
22
Prepared by: Noor-un-nisa (DIT 2017-18)
Represent a collection of key /value pairs that are sorted by the keys
and are accessible by key and by index.
Represent a simple last in first out (LIFO) non generic collection of object.
The async modifier indicates that the method or lambda expression that it
23
Prepared by: Noor-un-nisa (DIT 2017-18)
Specifies that visual basic should marshal strings according to .net frame
work rules based on the external name of the external procedure being declared.
Specifies that an argument is passed in such a way that the called procedure
can change the value of a variable underlying the argument is the calling code.
24
Prepared by: Noor-un-nisa (DIT 2017-18)
Specifies that a class can be used only as a base and that you cannot create
an object directly from it.
25
Prepared by: Noor-un-nisa (DIT 2017-18)
Specifies that the variable or property can be readout but not written.
26
Prepared by: Noor-un-nisa (DIT 2017-18)
Long Questions
Q1: what is IDE? explain its components.
IDE:
“The environment in which a computer program is written, compiled,
debugged, tested and run is called IDE”
Components of IDE:
1. Start page
2. Title bar
3. Menu bar
4. Standard toolbar
5. Toolbox
6. Solution explorer window
7. Properties window
8. Form window/design window
9. Code window
10. Error list window
1. Start page:
When we load visual studio 2010 for the first time, we will see the
27
Prepared by: Noor-un-nisa (DIT 2017-18)
The commands that are used to develop, compile and run VBs
application are given in the menu bar.
4. Standard toolbar:
5. Toolbox:
7. Property window:
28
Prepared by: Noor-un-nisa (DIT 2017-18)
position, object name etc. property window displays the attributes of selected
objects. Each object/control in visual basic has a unique set of properties.
Some properties such as height, width, color are common to all controls while
others are unique to each object/control.
9. Code window:
Code window is like a text editor. It is used to write or edit codes for
the controls /objects. It is also known as code editor window. Visual basic has an
intelligent editor program used for coding. When an incorrect syntax is typed, it
identifies an error immediately during design time.
Error list window is used to display a list of errors which are occur
during the writing code in code window.
1. Textbox:
The textbox control is used to get input and display(output) the information
at run time, for this reason it is mostly used control. It can handle string(text) and
numeric data. It contain different properties like name, size, color etc. We can set
these properties by using property window.
2. Label:
Label control is used to add caption for any control which display on a
form.it is generally used to display some informative text on GUI which is not
29
Prepared by: Noor-un-nisa (DIT 2017-18)
3. Command button:
4. Picture box:
The picture box control is used for displaying images on the form the
image property of the control allows you to set an image both at design time or at
run time. Its image property determine the picture that the control displays and size
mode property determines how the image is sized to fit into the control.
5. Listbox:
Control structure:
30
Prepared by: Noor-un-nisa (DIT 2017-18)
Conditional statement:
✓ if….then
✓ if….then…else
✓ if…then…elseif
✓ nested…if..then…else
✓ select case structure
if….then:
syntax:
if condition then
statement(s)
end if
if…..then….else:
Syntax:
31
Prepared by: Noor-un-nisa (DIT 2017-18)
If condition then
Block1
Else
Block 2
End if
If….then…elseif:
Syntax:
If condition 1 then
Block 1
Block 2
Else
Block n
End if
Nested if:
32
Prepared by: Noor-un-nisa (DIT 2017-18)
Syntax:
If condition 2 then
Block 1
Else inner if
Block 2
tae
End if
Else
Block 2
End if
Select case structure is used for checking the result of single expression with
multiple values. The expression is evaluated at the top of the structure and result of
expression is compared with different cases. If result match with any case value,
then corresponding block of statement will be executed.
Syntax:
Case 1
Statement
Case 2
Statement
33
Prepared by: Noor-un-nisa (DIT 2017-18)
Case else
Statement
End select
Data adapter has properties of type command, which represent the way it can
query, insert, delete and update the database. It contain different properties and
methods.
Properties description
34
Prepared by: Noor-un-nisa (DIT 2017-18)
Methods description
Form:
In visual basic, form is the main building block of the graphical user interface.
We cannot develop an application without using a form. Various controls are placed
on a form to perform specific functions. controls are GUI. Visual basic project may
contain multiple forms.
✓ title bar
✓ control buttons
✓ control icon
✓ border style
35
Prepared by: Noor-un-nisa (DIT 2017-18)
Form title
Maximize/restore button
Title bar
Minimize button
border
Working area
Title bar:
“ The colored bar on the top of the form is called the title bar”
It contains the title of the form. Each application in windows contains the title bar
that contain the name of application as name of document. the title of form is
known as caption of form.
Control buttons:
There are three buttons located at the top right corner of the title bar . the
buttons are:
36
Prepared by: Noor-un-nisa (DIT 2017-18)
Control icon:
Control icon is located at left corner of the title bar. It contain various
commands to restore, move, resize, maximize, minimize, and close the form
window.
Border style:
The four edges of the form window are called its border. The borders are used
to increase or decrease the size of form.
Q6: write down the difference between data reader and data set?
Data reader:
Data set:
37
Prepared by: Noor-un-nisa (DIT 2017-18)
38
Prepared by: Noor-un-nisa (DIT 2017-18)
Visual programming:
Features:
1. GUI
2. Modularization
3. Object oriented
4. Debugging
5. Macros IDE
6. Data access feature
1. GUI:
VB is a graphical user interface language. This means that a VB program
will always show something on the screen that the user can interact with
to get a job done.
2. Modularization:
It is considered good programming practice to modularize your
program small modules where it is clearly indicated what comes into the
module and what goes out makes a program easy to understand.
3. Object oriented:
OOP is a technique where programs are written on the basis of
objects. Objects are the collection of data and functions.
4. Debugging:
It is process to find a software error and remove it.
5. Macros IDE:
It is similar in design and function to the visual studio IDE. the
macros IDE include a code editor, tool windows , the property window,
and editors.
39
Prepared by: Noor-un-nisa (DIT 2017-18)
Q9: what is event driven language. Explain different form events in visual
basic.
Event-driven programming
Event-driven programming is a programming paradigm in which the flow of
program execution is determined by events - for example a user action such as a
mouse click, key press, or a message from the operating system or another program.
An event-driven application is designed to detect events as they occur, and then deal
with them using an appropriate event-handling procedure. The idea is an extension
of interrupt-driven programming of the kind found in early command-line
environments such as DOS, and in embedded systems (where the application is
implemented as firmware). Event-driven programs can be written in any
programming language, although some languages(Visual Basic for example) are
specifically designed to facilitate event-driven programming, and provide
an integrated development environment (IDE) that partially automates the
production of code, and provides a comprehensive selection of built-in objects and
controls, each of which can respond to a range of events. Virtually all object-oriented
and visual languages support event-driven programming. Visual Basic, Visual C++
and Java are examples of such languages.
Form events:
Event Description
40
Prepared by: Noor-un-nisa (DIT 2017-18)
41
Prepared by: Noor-un-nisa (DIT 2017-18)
42
Prepared by: Noor-un-nisa (DIT 2017-18)
4. Date/Time
Numeric Variables
The variable that can store / hold the numeric data are called numeric type
variables. There are following types of numeric variables in VB.Net.
This data type is used to store integer values. In visual basic, ushort type is
used to holds unsigned 16 bit (2 byte)integer. The default value of ushort is 0. The
43
Prepared by: Noor-un-nisa (DIT 2017-18)
Long:
Long type variables are also called integer types. A long type variable holds
signed 6 bit (8 byte) integer. The default value of long is 0. The whole number
without a decimal part are called integers. The long variable cannot be used to store
numbers containing decimals.
This data type is used to store whole value and decimal values number. Its
memory consumption is 4 byte.
This data type is used to store both whole value and decimal value numbers
its memory consumption is 8 byte.
The decimal variable type can store either a whole number or a decimal
number up to 29 decimal places.
Syntax:
44
Prepared by: Noor-un-nisa (DIT 2017-18)
Boolean:
The data that can have true or false is called Boolean data and Boolean type
variables can holds that can be only true or false. Visual basic uses two byte to store
this type of data . in Boolean type 1, represent true and 0 represent false.
Date/time:
The visual basic date variable type holds a date and time value. You must
enclose a date literal within number signs (##). Dates are declared in the form
#mm/dd/yyyy#. Date ranging from 01-01-0001 to 31-12-9999 and time ranging
from 12:00:00 am (mid night)through 11:59:59.9999 pm.
Loop:
45
Prepared by: Noor-un-nisa (DIT 2017-18)
Example
Write a code that displays counting from 1 to 100.
Dim a As Integer
a=1
Do while (a<=100)
Listbox1.items.add(a)
a=a+1
Loop
Do Loop While:-
It executes one or more statement while the given condition is
true. This loop is similar to Do…while…loop except that it first executes the
loop body and then checks the condition. It means that the body of the loop is
executed once even if the condition is false. So the loop should be used when
you want to executes a statement at least once.
Syntax
Do
Statement(s)
Loop While condition
Example
Dim a As Integer
a=100
Do
Listbox1.items.add(a)
a=a-1
Loop while (a>=1)
Do Until Loop:-
This loop executes one or more statements while the given
condition remains false.
46
Prepared by: Noor-un-nisa (DIT 2017-18)
Syntax
Do Until condition
Statement(s)
Loop
Example
47
Prepared by: Noor-un-nisa (DIT 2017-18)
fac=fac*a
loop until (a=10)
Listbox1.items.add(fac)
For Next Loop:-
This loop executes one or more statements for a specified
numbers of time.
Syntax
For counter variable= starting value To ending value Step stepvalue
Statement(s)
Next
Example
48
Prepared by: Noor-un-nisa (DIT 2017-18)
End while
Nested Loops:-
A loop within a loop is called nested loop. In nested loops, the
inner loop is executed completely with each change in the value of counter
variable of outer loop.
Syntax
Example
Dim a,b As integer
For a = 1 To 5
For b = 1 To 5
ListBox1.Items.Add("I love Pakistan")
Next
ListBox1.Items.Add(a)
Next
Q11: what is common dialog explain its methods.
common dialog control:
The Common Dialog control provides an interface between Visual Basic and
the routines in the Microsoft Windows dynamic-link library Commdlg.dll. To create
a dialog box using this control, Commdlg.dll must be in your Microsoft Windows
SYSTEM directory.
You use the Common Dialog control in your application by adding it to a form and
setting its properties. The dialog displayed by the control is determined by the
methods of the control. At run time, a dialog box is displayed or the help engine is
executed, when the appropriate method is invoked; at design time, the Common
Dialog control is displayed as an icon on a form. This icon can't be sized.
49
Prepared by: Noor-un-nisa (DIT 2017-18)
The Common Dialog control can display the following dialogs using the specified
method.
50
Prepared by: Noor-un-nisa (DIT 2017-18)
4. Image data
5. Audio data
6. Video data
Database:
A database is the collection of information that is organized so that it can easily
be excessed, managed and updated.
There are different types of database applications:
1. Ms access
2. Db2
3. Informix
4. Ms SQL server
5. Oracle
Information:
“processed form of data is called information”
Information is output and meaningful and in a summarize form. information is used
frequently and reproduce easily.
Function of dbms:
1. Data dictionary management
2. Data storage management
3. Data transformation and presentation
4. Security management
5. Multiuser access control
6. Backup and recovery management
7. Data integrity management
8. Database access languages application programming interfaces
9. Database communication interfaces
10. Transaction management
Programs
1. Write a program to calculate a factorial of first 10 natural
numbers by using for loop.
51
Prepared by: Noor-un-nisa (DIT 2017-18)
Design view:
Listbox1
btnadd
Coding view:
Private Sub btnadd_click()
Dim a, fac As Integer
fac = 1
For a = 1 To 10
fac = fac * a
ListBox1.Items.Add(fac)
Next
End Sub
52
Prepared by: Noor-un-nisa (DIT 2017-18)
Design view
Label 1 Textbox1
Label 2 Textbox2
btncheck
Coding view:
Private Sub btncheck_click()
Dim obt, total As Integer
Dim per As Decimal
obt = TextBox1.Text
total = TextBox2.Text
per = obt / total * 100
Label3.Text = per
If (per >= 60) And (per <= 60) Then
MessageBox.Show("d")
MessageBox.Show("keep it up")
ElseIf (per >= 70) And (per <= 79) Then
MessageBox.Show("c")
MessageBox.Show("good")
ElseIf (per >= 80) And (per <= 89) Then
MessageBox.Show("b")
MessageBox.Show("well done")
ElseIf (per >= 90) And (per <= 100) Then
MessageBox.Show("a")
MessageBox.Show("excellent")
Else
MessageBox.Show("fail")
End If
53
Prepared by: Noor-un-nisa (DIT 2017-18)
End Sub
3. write a program that display table in list box.
Design view:
Listbox1
btndisplay
Coding view:
Private Sub btndisplay_click()
Dim a, n As Integer
n = InputBox("enter number")
For a = 1 To 100
ListBox1.Items.Add(n & "x" & a & "=" & n * a)
Next
End Sub
54
Prepared by: Noor-un-nisa (DIT 2017-18)
design view:
Label1 Textbox1
Label 2 Textbox2
Label 3
Textbox3
Label 4
Textbox4
Label 5
btnswap
Coding view:
Private Sub btnswap_click()
Dim a, b As Integer
a = TextBox1.Text
b = TextBox2.Text
a=a+b
b=a-b
a=a-b
TextBox3.Text = a
TextBox4.Text = b
End Sub
55
Prepared by: Noor-un-nisa (DIT 2017-18)
Design view:
Label 1 Textbox1
Label 2 Textbox2
btncalculate
Coding view:
Private Sub btncalculate_click()
56
Prepared by: Noor-un-nisa (DIT 2017-18)
design view:
btnadd
Coding view:
Private Sub btnadd_click()
Dim a, b, c As Integer
a = InputBox("enter value a")
b = InputBox("enter value b")
c=a+b
MessageBox.Show(c)
End Sub
7. write a program to change the backcolor of form as yellow,
green, blue when one of the command button on form its clicked
57
Prepared by: Noor-un-nisa (DIT 2017-18)
Design view:
btnchange
Coding view:
Public Class Form1
Dim a As Integer = 0
Private Sub btnchange_click()
a=a+1
If a = 1 Then
Me.BackColor = Color.Red
ElseIf a = 2 Then
Me.BackColor = Color.Yellow
ElseIf a = 3 Then
Me.BackColor = Color.Green
a=0
End If
End Sub
End Class
58
Prepared by: Noor-un-nisa (DIT 2017-18)
Design view:
Textbox1
Listbox1
btnadd btnremove
btnclear
btnexit
Coding view:
Private Sub btnadd_click()
ListBox1.Items.Add(TextBox1.Text)
End Sub
Private Sub btnremove_click()
ListBox1.Items.Remove(ListBox1.SelectedItem)
End Sub
59
Prepared by: Noor-un-nisa (DIT 2017-18)
60
Prepared by: Noor-un-nisa (DIT 2017-18)
61