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

All VB Solved Past Papers

The document consists of a series of short questions and answers related to VB.NET programming, covering fundamental concepts such as variables, data types, flow charts, object-oriented programming, and control structures. It provides definitions and explanations for various programming terms and constructs, as well as differences between related concepts. The content serves as a study guide for understanding the basics of VB.NET and its framework.

Uploaded by

Ria Malik
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 views61 pages

All VB Solved Past Papers

The document consists of a series of short questions and answers related to VB.NET programming, covering fundamental concepts such as variables, data types, flow charts, object-oriented programming, and control structures. It provides definitions and explanations for various programming terms and constructs, as well as differences between related concepts. The content serves as a study guide for understanding the basics of VB.NET and its framework.

Uploaded by

Ria Malik
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/ 61

Prepared by: Noor-un-nisa (DIT 2017-18)

Short Questions
Q1: what is vb.net?

Vb.net is a windows based programming language which supports object


oriented programming structure.vb.net is a plate form where vb(visual basic) is
used.

Q2: what is namespace and assembly?

Namespace:

Namespace is the collection of different classes. The import keyword is


used to call the namespace to your project.

Assembly:

Assembly is the collection of one or more EXE or DLL files. assembly is the
basic building block of .NET framework.

Q3: what is variable?

“A quantity whose value change during the execution of program is called


variable”

A value of a variable can change during program execution but the name of variable
cannot be changed.

Q4: what is system flow chart?

It is a way of displaying how data flows in system and what decisions are made to
control events.

Q5: what is flow chart?

“A symbolic or graphical representation of a pseudo code or an algorithm is


called flow chart”

1
Prepared by: Noor-un-nisa (DIT 2017-18)

Q6: what are advantages of flow chart?

1. It is a better way to communicate the logic of a system to all involved.


2. Problems can be analyzed with more effective way
3. It is helpful in proper debugging

Q7: what is pseudo code/algorithm?

“A step by step procedure to solve a problem is called pseudo code or an


algorithm”

Q8: what is an object program/object code?

“A program which is written in a low level language or a machine language is


called object program/object code”

Q9: what is shared method?

A shared modifier indicates a method known as shared method. A shared


method doesn’t operate the specific instance of a type.

Q10: what are disadvantages of flow chart?

1. Sometimes program logic is quite complicated in that cases flow chart is


complex and clumsy.
2. If alterations are required the flow chart may require redrawing completely
This will usually waste value able time.
3. As the symbols of flow chart cannot be typed reproduction of flow chart
becomes a problem.

Q11: what is loop?

“A constant structure that execute a statement or a number of statements


repeatedly is known as loop”

Q12: what is object oriented programming?

Object oriented programming(oop) is a technique in which programs are

2
Prepared by: Noor-un-nisa (DIT 2017-18)

written on the basis of object. An object is the collection of data and functions.

Q13: what is data type?

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.

Q14: what is queue in vb.net?

A queue is the generic collection of vb.net. it implements a FIFO(first in first


out)algorithm.

Q15: what is tracing?

Tracing refers to collecting information about an application while it is


running. You can use traced information to troubleshoot an application.

Q16: what is constructor?

A constructor is a member function of a class that is called or executed


automatically when an object of that class is created. A constructor function may
have arguments but it cannot return any value.

Q17: what is array list?

It is a dynamic array.an array list size automatically changed when elements


in the array list are added or deleted.

Q18: what is class?

“A collection of data and functions is called class”

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)

Q19: what is a syntax error?

Syntax error are occur when we write an invalid statement in a code window.
e.g. misspelling of keyword is a syntax error.

Q20: what is read only keyword in vb.net?

Read only keyword specifies that a variable or property can be read but not
written.

Q21: what is data table?

A data table is a class in .net frame work and in simple words a data table
object represents a table from database.

Q22: what is data set?

A data set contains a collection of zero or more tables represented by data


table object. The data table collection contains all the data table objects in a data set.

Q23: what is hashtable in vb.net?

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.

Q24: what are class access modifier?

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

Q25: briefly explain for next loop?

For next loop executes one or more statements for a specified number of time.

4
Prepared by: Noor-un-nisa (DIT 2017-18)

Syntax:

For (variable name)=starting value to ending value step (step value)

next

Q26: what is conditional statement?

The conditional statements are used to execute or ignore a set of statements


after testing a condition.

Q27: what is the use of internel keyword?

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.

Q28: what is partial keyword in vb.net?

We can divide the declaration of the class or structure among several


declarations by using the partial keyword in vb or in visual c#.

Q29: what is reference type and value type?

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?

✓ Common language runtime(CLR)


✓ .net framework class library

Q31: what is the purpose of ANSI keyword in vb.net?

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.

Q32: write the difference between property and method?

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.

Q33: what is difference between compiler and interpreter?

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.

Q34: what is difference between local and global variables?

Local variables:

A variable that is declared inside a procedure can be used only in that


particular procedure and cannot be used in any other procedure.

Global variables:

Global variables are the variables that can be used by all procedure within
an application. Global variables are declared in modules.

Q35: what is difference between data grid and grid view?

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)

Q36: what is difference between constant, read only and static?

• Constant: the value can’t be changed


• Read only: the will be initialized only once from the constructor of the
class.
• Static: value can be initialized once.

Q37: what is difference between custom control and user control?

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:

A user control is shared among the single application files.

Q38: write the values of size mode property of picture box control?

✓ Normal
✓ Stretch image
✓ Auto size
✓ Centre image
✓ Zoom

Q39: what are difference between structure and class?

✓ Structure are value type, class are reference type


✓ Structure do not have constructors and destructors, class have both
constructors and destructors
✓ Structure do not supports inheritance, class support inheritance.

Q40: what is polymorphism?

7
Prepared by: Noor-un-nisa (DIT 2017-18)

Poly means many and morphism means change/forms. the concepts


introduces in the form of many behaviors of an object.

Q41: what is the top.net /base class of .net that everything is derived from?

System.object

Q42: what is the use of error provider control?

Error provider control is used to indicate invalid data on a data entry form.

Q43: what is difference between convert.tostring and .tostring method?

Convert.tostring handles null while .tostring doesn’t handles null.

Q44: what are the advantages of vb.net?

➢ .net is a language independent


➢ Automatic memory management(garbage collector)
➢ Object oriented
➢ disconnected architecture

Q45: what is the maximum size of the textbox?

65536

Q46: which namespaces are used for data access?

✓ System.data
✓ System.data.OLEDB
✓ System.data.SQLclient

Q47: what is the difference between array and array list?

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)

It is dynamic array. An array list size automatically changed when elements in


the array list are added or deleted.

Q48: what is the source code to display picture in button click event?

Picturebox1.image=image.fromfile(“image01.png”)

Q49: what are difference between close(),exit(),and end() function?

✓ Close() is used to close the form.


✓ Exit()is used to exit the procedure and transfer control immediately
to the statement
✓ A function is enclosed by end function

Q50: what is size of .net object?

.net object contains different sizes e.g 4 byte, 8 byte.

Q51: what is VBA?

VBA is the abbreviation of visual basic for application. It is the programming


language of excel and other office programs.

Q52: what is code window?

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.

Q53: what is the purpose of name property window?

It is used to set the names of controls/objects to reduce the complexity


during writing the codes.

Q54: explain the difference between constant and variable?

Constant:

“A quantity whose value doesn’t change during the execution of program”

9
Prepared by: Noor-un-nisa (DIT 2017-18)

Variable:

“A quantity whose value change during the execution of program”

Q55: differentiate between if else and select case statement?

If else:

It executes one block of statement when the condition is true and the other
when it is false.

Select case statement:

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.

Q56: what is difference between for loop and do.. loop?

For next loop:

It is use to execute one or more statement for a specified numbers of time.

Do while loop:

It is use to execute one or more statement while the given condition is true.

Q57: define array, element, subscript?

Array:

An array is a set of variables that can store similar type of data.

Elements:

The individual variables in an array referred as elements.

Subscript:

The position of the element within an array is called subscript.

10
Prepared by: Noor-un-nisa (DIT 2017-18)

Q58: how does an option button is different from checkboxes?

In a group of checkboxes, any number of boxes may be selected. Option buttons


are used when only one button from a group may be selected.

Q59: what is the purpose of timer control?

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.

Q60: differentiate between SDI and MDI?

SDI:

SDI is the abbreviation of single document interface. Each window of the


application holds a single document.

MDI:

MDI is the abbreviation of multiple document interface. each window with an


application hold multiple document.

Q61: what is tool tip? How it can be used?

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.

Q62: define an object?

“A collection of properties and methods is an object”

Q63: what is inheritance?

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)

Q64: explain conversion functions?

Conversion function is used to convert one data type to another data type.

Q65: what is a run time error?

Run time error occur during the execution of program. Such error occur due
to the invalid input by the user.

Q66: difference between step into and step over?

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.

Q67: what is primary key?

A candidate key which uniquely identify a tuple or attribute in a relation, is


called primary key.

Q68: what is the use of * in select statement?

*Specifies that all fields from the specified table or tables are selected.

Q69: what is DLL?

DLL is a dynamic link library. DLL file were created so that multiple programs
could use their information at the same time.

Q70: what is compiling?

“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)

Q71: what is encapsulation?

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.

Q72: what is friend access specifier?

The friend keyword in the declaration specifies that the elements can be
accessed only within the same assembly but not from outside the assembly.

Q73: what is concatenation and when would it be useful?

Concatenation is a process of combining two or more items together. The “&”

Sign is used. It is very useful to join a string literal and a property.

Q74: what are intrinsic control?

“ The control which is automatically present in the tool box when you start a
visual basic project are called intrinsic control.”

Q75: write rules for declaring a variable?

✓ First character of variable must be a letter


✓ Underscore is allowed in variable name
✓ Reserve words are not allowed
✓ Blank spaces are not allowed

Q76: write steps to develop a computer program?

✓ Defining and analyze the problem


✓ Designing the algorithm
✓ Coding or writing a program
✓ Test execution
✓ Debugging
✓ Final documentation

Q77: what is difference between VB and VB.NET?

VB is used to write computer programs while VB.NET is a platform where VB

13
Prepared by: Noor-un-nisa (DIT 2017-18)

is used.

Q78: what is literal constant?

“A value which is typed directly in a program is called literal constant.”

Any type of value can be used in visual basic without storing in variable. e.g a=a+10

10 is a literal constant.

Q79: what is redim keyword and its use?

Redim keyword in a declaration statement is used to reallocate the storage


space of an array.

Q80: what are nested class?

“A class within a class is called nested class”

Q81: how many languages are supported by .net?

70+ languages are supported by .net

Q82: what is event handler in vb.net?

An event handler is the code you write to respond to an event. An event


handler in visual basic is sub procedure.

Q83: enlist some events used in vb.net?

✓ Click
✓ Load
✓ Tick
✓ Double click
✓ Mouseup

Q84: what is code security?

CAS(code access security) is a member of .net security model that determines

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.

Q85: enlist two access specifier?

✓ Public
✓ Private
✓ Friend
✓ Protected
✓ Protected friend

Q86: enlist two methods of textbox?

✓ Focus
✓ Clear

Q87: what is default size of integer data type?

The default size of integer data type is -2,147,483,648 to 2,147,483,647.

Q88: how to assign back color of label/button/textbox in vb.net?

Label1.backcolor=color.green

Button1.backcolor=color.blue

Textbox1.backcolor=color.pink

Q89: how to assign font to label at run time?

Richtextbox1.selectionfont=new font (richtextbox1.font, fontstyle.bold)

Q90: what is oop?

Oop is object oriented programming in which programs are written on the


basis of object. Object is the collection of data and function.

Q91: enlist the types of assembly?

✓ Private assembly

15
Prepared by: Noor-un-nisa (DIT 2017-18)

✓ Shared assembly

Q92: define ADO.NET?

ADO.NET is a set of computer software components that programmers that


can use to access data and data services from the database. ADO means ActiveX
data objects.

Q93: what is LINQ?

LINQ (link integrated query) offers a compact, expressive and intelligible


syntax for manipulating data.

Q94: what is the use of SQL command object?

SQL command object allows you to query and send commands to a


database.

Q95: write down the benefits of ADO.NET?

✓ Scalability
✓ Data source independence
✓ Interoperability
✓ Performance
✓ Firewall

Q96: what is boxing and unboxing?

Boxing is an implicit conversion of a value type to the reference type e.g


stuct type, enumeration type.

Unboxing is the explicit conversion from the reference to a value type e.g
class, interface.

Q97: define structured programming language?

structure programming language is a technique in which long program is


divided into small block of codes. Each block of code has a unique name that can be
used again and again.

16
Prepared by: Noor-un-nisa (DIT 2017-18)

Q98: what is IDE?

IDE is the abbreviation of integrated development environment.

“The environment in which computer a computer program is written, compiled,


debugged, tested and run is called IDE”

Q99: what is a form?

Form is the basic building block of graphical user interface. Various


controls are placed on form to perform specific function. We cannot develop an
application without using a form.

Q100: define control buttons?

Control buttons is generally used to generate a click event by providing a


handler for the click event.

Q101: what is break point?

Break point is used to break a code at specific line when user get a runtime
error or pauses project execution.

Q102: what is meant by object in vb?

“A collection of data and functions is called object”

Q103: how to declare a variable in vb?

Dim( variable name) as data type

Q104: what is loop and why it is used in programming?

“A constant structure that are executes a statement or number of statements


repeatedly is known as loop.” Loop can be used to execute a statement for specified
number of items.

Q105: what is listbox control?

17
Prepared by: Noor-un-nisa (DIT 2017-18)

Listbox represents a windows control to display a list of items to a user. A


user can select an item from the list.

Q106: what do you meant by GUI?

GUI(graphical user interface) is a human user interface that uses windows,


icons and menues that can be manipulated by a mouse.

Q107: what is SQL?

SQL is not a full featured programming language it is simply a data sub


language which means that it only has language statement for data processing.

Q108: what is meant by project explorer/solution explorer window?

The application program in visual basic is known as project.

A project is a collection of different components stored in separate files. These


components include forms, modules, classes etc. the solution explorer window
displays forms, modules, reports and classes etc. used in project.

Q109: discuss five properties of form?

✓ Back color: to set the back color of form


✓ Border style: form border style
✓ Caption: set the title of form
✓ Fore color: change the font color
✓ Name: set the name of form

Q110: what is DAO?

A data access object is an object that provides an abstract interface to same


type of database.

Q111: write the general syntax of msg box function?

18
Prepared by: Noor-un-nisa (DIT 2017-18)

Msg box(“prompt”, style, “title”)

Q112: what is meant by debugging?

“Debugging is a process to find a software error and also remove it”

Q113: write two main features of ADO.NET?

✓ Dataset
✓ Data adapter

Q114: write down the syntax of for next loop?

For (variable name)=starting value to ending value step (step value)

Statement

Next

Q115: define frame?

“combination/collection of different forms is called frame”

Q116: how menues are added to a form?

By using menu strip we can add menues to a form. The menu strip control is
a multiple document interface.

Q117: describe any two control used to display information?

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.

Q118: describe the scroll bar 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.

Q119: how to create a constant in vb.net?

Const (variable name) as data type = value

Q120: define dim statement?

Dim statement is used to declare a variable

Syntax: dim ( variable name) as data type

Q121: define enum keyword?

Declares an enumeration and defines the values of its members.

Q122: define purpose of class statement?

We declare data members and data functions in class. Class is a collection


of data functions.

Q123: what is jagged array?

“ An array in which each element of an array itself an array is called jagged


array”

Q124: write purpose of structure statement?

Declares a name of structure and introduces the definition of the variables,


properties, events and procedures that the structure comprises.

Q125: write purpose of Unicode keyword?

Specifies that visual basic should marshal all strings to Unicode values
regardless of the name of the external procedure being declared.

Q126: write purpose of widening keyword in vb.net?

Indicates that a conversion operator converts a class or structure to a type

20
Prepared by: Noor-un-nisa (DIT 2017-18)

that can hold all possible values of the original class or structure.

Q127: Write purpose of with events keyword?

Specifies that one or more declared member variables refer to an instance


of a class that can raise events.

Q128: write purpose of writeonly keyword?

Specifies that a property can be written but not read.

Q129: write purpose of module statement?

Declares a name of a module and introduces the definition of the


variables, properties, events and procedures that the module comprises.

Q130: write purpose of interface statement?

Declares the name of an interface and introduces the definition of the


members that the interface comprises.

Q131: write purpose of function statement?

Declares the name, parameter and codes that define a function procedure.

Q132: write purpose of sub statement?

Declares the name, parameter and codes that defines a sub procedure.

Q133: write purpose of declare statement?

Declares a reference to a procedure implemented in an external file.

Q134: write purpose of operator statement?

Declares the operator symbols, operands and the codes that define a
operator procedure on a class or structure.

Q135: write purpose of property statement?

Declares the name of the property, and the property procedure used to

21
Prepared by: Noor-un-nisa (DIT 2017-18)

store and retrieve the value of the property.

Q136: write purpose of event statement?

Declares the user defined event.

Q137: write purpose of delegate statement?

Used to declare a delegate. Delegate are objects that refers to a functions.


Delegates are type safe function pointer.

Q138: write purpose of addressof operator?

Creates a procedure delegates instance that reference the specific


procedure.

Q139: write purpose of get type operator?

Return a type object for the specified type. The type object provide
information about the type such as its properties , methods and events.

Q140: write purpose of function expression?

Declares the parameters and codes that define a function lambda


expression.

Q141: write purpose of if operator?

Uses short circuit evaluation to conditionally return one of two values. The
if operator can be called with three arguments or with two arguments.

Q142: write purpose of exit statement?

Exit procedure and transfer control immediately to the statement.

Q143: write purpose of continue statement?

Transfer control immediately to the next iteration of loop.

Q144: write purpose of goto statement?

22
Prepared by: Noor-un-nisa (DIT 2017-18)

Branches unconditionally to a specified line in a procedure.

Q145: what is sorted list?

Represent a collection of key /value pairs that are sorted by the keys
and are accessible by key and by index.

Q146: what is stack?

Represent a simple last in first out (LIFO) non generic collection of object.

Q147: what is bitarray?

Manages a compact array of bit values which is represented as Boolean


where true indicates the bit is on(1) and false indicates the bit is off(0).

Q148: what are shared variables?

Specifies that one or more declared programming elements are associated


with class or structure at large, and not with a specific instance of the class or
structure.

Q149: what are shadows variables?

Specifies that a declared programming elements redeclares and hides an


identically named element, or set of overloaded elements, in a base class.

Q150: what are static variables?

Specifies that one or more declared local variables are to continue or to


exist and retain their latest values after termination of the procedure in which they
are declared.

Q151: write purpose of assembly keyword?

Specifies that an attribute at the beginning of a source file applies to the


entire assembly.

Q152: write purpose of async keyword?

The async modifier indicates that the method or lambda expression that it

23
Prepared by: Noor-un-nisa (DIT 2017-18)

modifies is asynchronous. Such methods are referred as async method.

Q153: write purpose of auto keyword?

Specifies that visual basic should marshal strings according to .net frame
work rules based on the external name of the external procedure being declared.

Q154: write purpose of default keyword?

Identifies a property as the default property of its class, structure and


interface.

Q155: write purpose of byref keyword?

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.

Q156: write purpose of brval keyword?

Specifies that an argument is passed in such a way that the called


procedure or property cannot change the value of a variable underlying the
argument in the calling code.

Q157: write purpose of friend keyword?

Specifies that one or more declared programming elements are accessible


only from within an assembly that contain their declaration.

Q158: write purpose of in keyword?

Specifies that the type parameter is contra variant.

Q159: write purpose of iterator keyword?

Specifies that a function or a accessor is an iterator.

Q160: write purpose of module keyword?

Specifies that an attribute at the beginning of a source file applies to the

24
Prepared by: Noor-un-nisa (DIT 2017-18)

current assembly module.

Q161: write purpose of mustinherit keyword?

Specifies that a class can be used only as a base and that you cannot create
an object directly from it.

Q162: write purpose of mustoverride keyword?

Specifies that a property or procedure is not implemented in this class


and must be overridden in a derived class before it can be used.

Q163: write purpose of narrowing keyword?

Indicates that a conversion operator converts a class or structure to a


type that might not be able to hold some of the possible values of the original class
or structure.

Q164: write purpose of notinheritable keyword?

Specifies that a class cannot be used as a base class.

Q165: write purpose of notoverridable keyword?

Specifies that a property or procedure cannot be overridden in a derived


class.

Q166: write purpose of optional keyword?

Specifies that a procedure argument can be omitted when the procedure


is called.

Q167: write purpose of out keyword?

Specifies that the type is covariant

Q168: write purpose of overloads keyword?

Specifies that a property or procedure redeclares one or more existing

25
Prepared by: Noor-un-nisa (DIT 2017-18)

properties or procedures with the same name.

Q169: write purpose of overrideable keyword?

Specifies that the property or procedure can be overridden by an


identically named property or procedure in a derived class.

Q169: write purpose of overrides keyword?

Specifies that the property or procedure overrides by an identically


named property or procedure inherited from a base class.

Q170: write purpose of parramarray keyword?

Specifies that a procedure parameter takes an optional array of


elements of the specified type. Parramarray can be used only on the last parameter
of a parameter list.

Q171: write purpose of private keyword?

Specifies that one or more declared programming elements are


accessible only from within their declaration context, including from within any
contained types.

Q172: write purpose of protected keyword?

Specifies that one or more declared programming elements are


accessible only from within their own class or from a derived class.

Q173: write purpose of public keyword?

Specifies that one or more declared programming elements have no


access restrictions.

Q174: write purpose of readonly keyword?

Specifies that the variable or property can be readout but not written.

Q175: write purpose of shadow keyword?

Specifies that a declared programming element redeclares and hides an

26
Prepared by: Noor-un-nisa (DIT 2017-18)

identically named element, or set of overloaded elements, in a base class.

Q176: write purpose of shared keyword?

Specifies that one or more declared programming elements are associated


with a class or structure at large, and not with a specific instance of the class or
structure.

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”

IDE is an abbreviation of Integrated Development Environment. Visual basic is


an integrated application development environment. It provides a large number of
tools that help the programmers to develop a program. The programmers can
design graphical user interface screen for a program very easily.

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)

window called start page. Start page contain following options.


✓ New project: to create a new project.
✓ Open project: open an existing project which you have created or
saved.
✓ Recent project: it shows a list of projects that you have recently
opened.
2. 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.
3. Menu bar:

The commands that are used to develop, compile and run VBs
application are given in the menu bar.

4. Standard toolbar:

It provides a quick access to the commonly used menu commands.

5. Toolbox:

Toolbox contains different objects and controls that are used to


develop application. Controls are GUI components. Controls are placed on the form
to create user interface of an application. Buttons, list boxes, checkboxes are the
example of controls.

6. Solution explorer window:

The application program in visual basic is known as project. A project


is a collection of different components stored in separate files. The solution explorer
window display forms, modules, reports and classes etc. used in project.

7. Property window:

Properties are the attributes of an object/control such as size, color,

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.

8. Form window/design window:

We can create GUI by using form window. Controls are placed on a


form to perform specific functions. We cannot develop an application without using
a form. Visual basic projects contain multiple forms.

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.

10. Error list window:

Error list window is used to display a list of errors which are occur
during the writing code in code window.

Q2: explain the following user interface elements

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)

change during design time. It represent a standard windows label. It contain


different properties like text, color, fore color etc. we can set these properties by
using property window.

3. Command button:

A button is a window control used to initiate an action. A button is useful


when clicked, in which case the user position the mouse on it and presses one
of the mouse’s buttons. In some programming environment , the classic
buttons is called a 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:

The listbox represents a windows control to display a list of items to a


user. A user can select an item from the list. We can use the add or insert method to
add items in listbox. The control automatically displays scroll bar when needed.

Q3: what is control structure? What is difference between conditional and


case structure?

Control structure:

The components of a computer program are executed one after another in


which they are written .this is known as sequential execution of program.

The order of execution of statement in a program can be changed. This is


done with the help of control statement. the statements that are used to control the
order execution of statements in a program are called control statement or control
structure. There are two types of control statement or control structure.

✓ Un Conditional control statement

30
Prepared by: Noor-un-nisa (DIT 2017-18)

✓ conditional control statement

unconditional control statement:

The unconditional control statement is used to change the order of


execution of a program without any condition. The example of unconditional
statement is goto statement.

Conditional statement:

The conditional statement are used to execute or ignored a set of


statements after testing a condition.

Types of conditional statement

✓ if….then
✓ if….then…else
✓ if…then…elseif
✓ nested…if..then…else
✓ select case structure

if….then:

it is used to execute or to ignore a statement or set of statement after testing


a condition

syntax:

if condition then

statement(s)

end if

if…..then….else:

it is another type of statement.it executed one block of statement(s)


when condition is true and the other when it is false.

Syntax:

31
Prepared by: Noor-un-nisa (DIT 2017-18)

If condition then

Block1

Else

Block 2

End if

If….then…elseif:

If…then…elseif statement can be used to choose one block of statement


from many blocks of statements .this type of statement is used when there are
many options and only one block of statements should be executed on the basis of
a condition.

Syntax:

If condition 1 then

Block 1

Else if condition 2 then

Block 2

Else

Block n

End if

Nested if:

If within if is called nested if. We can use one if or elseif statements


inside another if. Elseif statements(s)

32
Prepared by: Noor-un-nisa (DIT 2017-18)

Syntax:

If condition 1 then outer if

If condition 2 then

Block 1

Else inner if

Block 2
tae
End if

Else

Block 2

End if

Select case statement/structure:

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:

Select case (variable name)

Case 1

Statement

Case 2

Statement

33
Prepared by: Noor-un-nisa (DIT 2017-18)

Case else

Statement

End select

Q4: Explain in detail property and method of data adapter component of


ADO.NET?

ADO.NET data adapter:

“Data adapter is the collection of command objects which acts like an


interface /bridge between database and data set for transferring the data”

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

1. Delete command Represent a delete statement or


Stored procedure for deleting
Records from the data source.
2. Insert command Represent an insert statement or

Stored procedure for inserting a

New record to the data source.

3. Select command represent a select statement or


Stored procedures can be used to
Select record from a data source.
4. Update command represent an update statement or
Stored procedure for updating
Record from a data source.
5. Table mappings represent a collection of mapping
Between actual data source table
And a data table object.

34
Prepared by: Noor-un-nisa (DIT 2017-18)

Data adapter methods:

The data adapter class provides many useful methods

Methods description

1. Fill this method fills data records from


a
Data adapter to a data set object.
2. Fill schema this method add a data table in
Dataset.
3. Get fill parameters this method retrieves parameters
That are used when a select
Statement is executed.
4. Update this method stores data from a
data
Data set to the data source.
Q5: what is form? Explain components of forms.

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.

Various components of form:

The components of form are:

✓ title bar
✓ control buttons
✓ control icon
✓ border style

35
Prepared by: Noor-un-nisa (DIT 2017-18)

Control icon Close button

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:

✓ minimize: this button is used to minimize the form.


✓ maximize: this button is used to maximize or restore the form.
✓ close button: this button is used to close or restore the form.

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 Reader is a connection oriented service.

Data Reader is designed to retrieve a read-only, forward-only stream of data from


data sources. Data Reader has a connection oriented nature, whenever you want
fetch the data from database that you must have a connection. It's usually the most
efficient way to deal with records when you don't need any random access. It
fetches one row at a time so very less network cost when compare to Data Set.
Results are returned as the query executes, and are stored in the network buffer on
the client until you request them using the Read method of the Data Reader. Data
Reader is readonly so we can't do any transaction on them. It will be the best choice
where we need to show the data to the user which requires no transaction.

Data set:

Data Set is an in-memory representation of a collection of Database objects


including related tables, constraints, and relationships among the tables. It provides
a consistent relational programming model with multiple data sources from
different areas. We can say that the Data Set is a small database because it stores the
schema and data in the application memory area. Dataset is used to hold tables with
data. You can select data form tables, create views based on table and ask child rows
over relations. Also Data Set provides you with rich features like saving data as XML
and loading XML data.

37
Prepared by: Noor-un-nisa (DIT 2017-18)

Q7: differentiate between structure programming and object oriented


programming

Structured Programming Object Oriented Programming

Structured Programming is Object Oriented


designed which focuses Programming is designed
on process/ logical structure and which focuses on data.
then data required for that process.
Structured programming Object oriented programming
follows top-down approach. follows bottom-up
approach.
Structured Programming is also Object Oriented Programming
known as Modular supports inheritance,
Programming and a subset encapsulation,
of procedural programming abstraction, polymorphism,
language. etc.
In Structured Programming, In Object Oriented
Programs are divided into small Programming, Programs are
self-contained functions. divided into small entities
called objects.
Structured Programming Object Oriented Programming
is less secure as there is no way is more secure as having data
of data hiding. hiding feature.
Structured Programming can Object Oriented Programming
solve moderately complex can solve
programs. any complex programs.
Structured Programming Object Oriented Programming
provides less reusability, more provides more reusability,
function dependency. less function dependency.
Less abstraction and less flexibility. More abstraction and
more flexibility.

38
Prepared by: Noor-un-nisa (DIT 2017-18)

Q8: what is visual programming and give its feature.

Visual programming:

A visual programming language is language that lets user create


programs by manipulating program elements graphically rather than by specifying
them textually.

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)

6. data access feature:


By using data access feature, we can create databases, including
Microsoft SQL server and other enterprise level database.

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

1 Activated Occurs when the form is activated in code or by


the user.

2 Click Occurs when the form is clicked.

3 Closed Occurs before the form is closed.

40
Prepared by: Noor-un-nisa (DIT 2017-18)

4 Closing Occurs when the form is closing.

5 DoubleClick Occurs when the form control is double-clicked.

6 DragDrop Occurs when a drag-and-drop operation is


completed.

7 Enter Occurs when the form is entered.

8 GotFocus Occurs when the form control receives focus.

9 HelpButtonClicked Occurs when the Help button is clicked.

10 KeyDown Occurs when a key is pressed while the form has


focus.

11 KeyPress Occurs when a key is pressed while the form has


focus.

12 KeyUp Occurs when a key is released while the form has


focus.

13 Load Occurs before a form is displayed for the first


time.

14 LostFocus Occurs when the form loses focus.

15 MouseDown Occurs when the mouse pointer is over the form


and a mouse button is pressed.

16 MouseEnter Occurs when the mouse pointer enters the form.

41
Prepared by: Noor-un-nisa (DIT 2017-18)

17 MouseHover Occurs when the mouse pointer rests on the


form.

18 MouseLeave Occurs when the mouse pointer leaves the form.

19 MouseMove Occurs when the mouse pointer is moved over


the form.

20 MouseUp Occurs when the mouse pointer is over the form


and a mouse button is released.

21 MouseWheel Occurs when the mouse wheel moves while the


control has focus.

22 Move Occurs when the form is moved.

23 Resize Occurs when the control is resized.

24 Scroll Occurs when the user or code scrolls through the


client area.

25 Shown Occurs whenever the form is first displayed.

26 VisibleChanged Occurs when the Visible property value changes.

Q9: explain different data types in visual basic.

Data Types in Vb.Net


A variable can store different types of data. A variable can hold number, string or an
instance of object including forms and controls etc. Following are the major
categories of variable data types in visual basic.
1. Numeric Variables.
2. String variables.
3. Boolean

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.

• Integer Data Type


• Decimal / Floating Point Data Type

Integer Data Type


Byte:-
A Byte holds a positive number in the range of 0 to 255. It takes 1 Byte of
memory. Because of the limited range.
SByte:-
A SByte variable holds signed integers that range in value from -128 through
127. It takes 1 Byte of memory.
Integer:-
An integer is a whole number that is a number without a fraction or decimal
point. In Visual Basic, Integer variable type is used to holds signed 32-bit (4-byte)
integers that range in value from -2,147,483,648 through 2,147,483,647. The default
value of integer is 0.
UInteger:-
This data type is also used to store integer values without any decimal point. In
visual basic, UInteger variable type is used to holds unsigned 32-bit (4-byte) integers
ranging in value from 0 through 4,294,967,295. The default value of integer is 0.
Short:-
This data type is used to store the integer values without any decimal point. In
Visual Basic, short is used to store whole numbers between -32768 to 32767. The
short variable is used to numbers containing decimals.
Ushort:

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)

ushort variable cannot be used to store numbers containing decimals.

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.

Decimal and floating point data type:

Single data type:

This data type is used to store whole value and decimal values number. Its
memory consumption is 4 byte.

Double data type:

This data type is used to store both whole value and decimal value numbers
its memory consumption is 8 byte.

Decimal data type:

The decimal variable type can store either a whole number or a decimal
number up to 29 decimal places.

String data type:

A type of variable which is used to store string values is known as string


variable. A set of characters enclosed in double quotation is called string. It may
consist of one and many characters. It may include upper and lower case letters,
digits, symbols, special characters and space. The arithmetic calculation cannot be
performed on it .

Syntax:

Dim (variable name) as string

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.

Q10: explain all looping statement in vb.net with simple example?

Loop:

“A loop is a sequence of instructions that is continually repeated until a certain


condition is reached.”
Types of loops:
• Do while loop
• Do loop while
• Do until loop
• Do loop until
• For loop
• While….End while loop
Do While Loop:-
It executes one or more statement while the given condition is
true.
Syntax
Do While condition
Statement(s)
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

Write a code that displays back-counting from 100 to 1.

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

Write a code that displays sum of 1st 100 integer numbers.

Dim a, sum As Integer


a=0
sum=0
Do until (a=100)
a=a+1
sum=sum + a
loop
Listbox1.items.add(sum)
Do Loop Until:-
It executes one or more statement while the given condition is
false. This loop is similar to Do…Until…Loop except that it first executed the
loop body and then checks the condition. It means that the body of the loop is
executed once even if the condition is true. So this loop should be used when
you want to execute a statement at least once.
syntax
Do
Statement(s)
Loop Until condition
Example

Write a code that displays factorial of 1st 10 integers.

Dim a, fac As Integer


a=0
fac=1
Do
a=a+1

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

Write a code that display even number between 1 and 100.


Dim a As Integer
For a=1 to 100
If a Mod 2=0 Then
Listbox1.items.add(a)
End if
Next
While…End while:-
It is the simplest loop of VB.Net language. It executes one or more
statements while the given condition is remains true.
Syntax
While condition
Statement(s)
End While
Example

Write a code that display odd number between 1 and 100.


Dim a As Integer
While a<=100
If a Mod 2<>0 Then
Listbox1.items.add(a)
End if

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.

Method Dialog Displayed

ShowOpen Show Open Dialog Box

ShowSave Show Save As Dialog Box

ShowColor Show Color Dialog Box

ShowFont Show Font Dialog Box

ShowPrinter Show Print or Print Options Dialog Box

ShowHelp Invokes the Windows Help Engine

Q12: explain the following


Data:
“raw facts and figures are called data”
It is used as input in computer, huge in volume and used rarely.
There are different types of data:
1. Numeric data
2. Alphabetic data
3. Alphanumeric data

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

2. Write a vb program to process the grades of a student along


with the form design.

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

4. write a program in which swap two numbers without using


third variable.

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

5. write a program to calculate the factorial of given number using


while loop. the number will be given at run time and display its
result in textbox.

55
Prepared by: Noor-un-nisa (DIT 2017-18)

Design view:

Label 1 Textbox1

Label 2 Textbox2

btncalculate

Coding view:
Private Sub btncalculate_click()

Dim a, n, fac As Integer


n = TextBox1.Text
fac = 1
a=1
Do While (a <= n)
fac = fac * a
a=a+1
Loop
TextBox2.Text = fac
End Sub

56
Prepared by: Noor-un-nisa (DIT 2017-18)

6. write a program in which add two numbers by using input box

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)

8. write a program that uses a listbox, textbox, four buttons. The


user can enter a text in the textbox and press a button to add
text in listbox. the second button is used to remove an item from
the list. The third button is used to clear the listbox and the last
button is used to exit the program.

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

Private Sub btnclear_click()


ListBox1.Items.Clear()
End Sub
Private Sub btnexit_click()
Me.Close()
End Sub

59
Prepared by: Noor-un-nisa (DIT 2017-18)

60
Prepared by: Noor-un-nisa (DIT 2017-18)

61

You might also like