You are on page 1of 12

1

VISUAL BASIC
SOLVED LONG TYPE QUESTIONS
1. Visual Basic is a Programming Language. Elaborate? Discuss the features of Visual Basic Language?
Ans. VISUAL BASIC is a high level programming language which is derived from the earlier CUI
version called BASIC, invented by Dartmouth College professors John Kemeny and Thomas Kurtz.
BASIC means Beginners' All-purpose Symbolic Instruction Code. Different types of BASIC versions
are Microsoft QBASIC, QUICKBASIC, GWBASIC, and IBM BASICA etc. Visual Basic is an easy
programming language to learn. The programming code resembles English Language. It was
originally created to make it easier to write programs for the Windows Computer Operating
System.
Visual Basic is an event-driven programming language and integrated development
environment (IDE) from Microsoft programming model first released in 1991. In Visual Basic,
programming is done in a graphical environment. You just need to drag and drop any graphical
object anywhere on the form. Examples of events are clicking a command button, entering text into
a text box, selecting an item in a list box etc.
The Visual Basic approach has become the norm for programming languages. Now, there are visual
environments for many programming languages available including C++, Pascal, Java and Dot Net
Environments. Visual Basic is sometimes called a Rapid Application Development (RAD) system
because it enables programmers to quickly build on-shelf prototype applications.
Features of Visual Basic:
 Full set of objects - you 'draw' the application.
 Lots of icons and pictures for your use.
 An event driven language where the flow program control depends upon an event.
 Response to mouse and keyboard actions.
 Clipboard and printer access.
 Full group of mathematical, string handling and graphics functions.
 Reusable record set objects with drag-and-drop functionality.
 Develop multimedia-rich applications using Dynamic HTML surface as the user interface.
 Useful debugger and error-handling facilities.

2. How many different categories of Operators available in VB? Discuss them briefly?
Ans. We have several types of operators:
 Arithmetic Operators
 Relational Operators
 Logical Operators
1


Arithmetical Operators
Operators Description Example Result
+ Add 5+5 10
- Subtract 10-5 5
/ Divide 25/5 5
\ Integer Division 20\3 6
* Multiply 5*4 20
^ Exponent (power of) 3^3 27

Relational Operators
Operators Description Example Result
> Greater than 10>8 True
< Less than 10<8 False
>= Greater than or equal to 20>=10 True
<= Less than or equal to 10<=20 True
<> Not Equal to 5<>4 True
= Equal to 5=7 False
Logical Operators
Operators Description
OR Operation will be true if either of the operands is true
AND Operation will be true only if both the operands are true

3. Discuss the concept of variables? How do you declare the variables?
Ans. In programming language, the programs need the short-term storage of data. The data is
stored in a variable, which is a temporary storage in the computer's memory. Thus, a variable is a
name given to a memory location where the real value is stored. The variable name is
1

the "identifier", used to recognize the data. In Visual Basic, a variable name must begin with a letter
and comprises a series of alphanumeric and underscore ‘_' up to 255 characters in length and not
contain any point.

Variable Declaration
The different ways of declaring variables in Visual Basic are listed below and elucidated in this
section.
 Implicit Declaration
 Explicit Declaration

Declaring a variable tells Visual Basic to reserve space in memory or making it transparent to the
program. It is not must that a variable should be declared before using it. Automatically whenever
Visual Basic encounters a new variable, it assigns the default (Variant) variable type and value. This
is called implicit declaration. Though this type of declaration is easier for the user, to have more
control over the variables, it is advisable to declare them explicitly. The variables are declared with
a Dim statement to name the variable and its type. The As type clause in the Dim statement allows
to define the data type or object type of the variable. This is called explicit declaration.

Syntax

Dim variable name [As type]
Examples:
Dim N As Integer
Dim A AS Double, B As Double
Dim Month As Date
Dim MyString, YourString as String

4. Disscuss with the help of examples types of constants in Visual Basic?
Ans. Constants
A constant is a meaningful name that takes the place of a number or string that does not change.
Visual Basic contains a number of predefined constants, mainly using for printing and displaying.
You can also create your own constants with the Const statement, using the same guidelines you
would for creating a variable name.
Declaring Constants
 Declare constants with the Const statement.
Examples:
Const school_sports_fee As Single = 2400.00
Const STATE_NAME As String = "Jammu and Kashmir”
Const JOB_TITLE As String = "Lecturer"
Const COURSE_NAME As String = ""Programming Visual Basic""

1

VB has two different types of constants
 Intrinsic Constants: these are defined as enumerations such as Color.Green and Color.Yellow.
These are called intrinsic because they are predefined in VB and always exist for your use.
 Named Constants: these are constants you define with a Const statement. These constants are
specific to your programming application. It is a space in memory filled with fixed value that will
not be changed. For example:



SHORT TYPE QUESTIONS

1. What is the use of Relational Operators? Express with the help of examples?
Ans.
Relational Operators
Operators Description Example Result
> Greater than 10>8 True
< Less than 10<8 False
>= Greater than or equal to 20>=10 True
<= Less than or equal to 10<=20 True
<> Not Equal to 5<>4 True
= Equal to 5=7 False

2. Discuss the IDE of VB?
Ans.
The Visual Basic Environment or Integrated Development Environment (IDE) consists of:
 A blank form for you to design your application's interface.
 The project window which displays the files that are created in your application.
 The properties window which displays the properties of various controls and objects that are
created in your application.
 Menu Bar contains a standard command like: File, Edit, View, Window, Help menus, and
specific command such as: Project, Format, or Debug menus.

3. What is an IF statement? Why do we use IF Statement?
Ans. The If...Then statement examines the truthfulness of an expression. Structurally, its
formula is:
Const pie = 3.14 Constant for procedure
Private Const pie = 3.14 Constant for form and all procedure
Public Const pie = 3.14 Constant for all forms
1

If ConditionCheck Then Statement
Therefore, the program examines a condition, in this case ConditionCheck. This ConditionCheck can be a
simple expression or a combination of expressions. If the ConditionCheck is true, then the program will
execute the Statement.
There are two ways you can use the If...Then statement. If the conditional formula is short enough, you
can write it on one line, like this:

If ConditionToCheck Then Statement
e.g., if percentage > 80 then text1.text = “A+”


4. What is an advantage of SWITCH statement over IF statement?
Ans. If You have a large number of conditions to examine, the If...Then...Else will go through each one of
them. Visual Basic offers the alternative of jumping to the statement that applies to the state of the
condition.
The formula of the Select Case is:
Select Case Expression
Case Expression1
Statement1
Case Expression2
Statement2
Case Expressionk
Statementk
End Select
The Expression will examined and evaluated once. Then it will compare the result of this examination
with the Expression of each case. Once it finds one that matches, it would execute the
corresponding Statement.


5. What is a Loop? When do we use the Loops?
Ans. Visual Basic allows a procedure to be repeated many times until a condition or a set of conditions is
fulfilled. This is generally called looping . Looping is a very useful feature of Visual Basic because it makes
repetitive works easier. There are two kinds of loops in Visual Basic, the Do...Loop and the For.......Next
loop.

Visual Basic loop structures allow you to run one or more lines of code repetitively. You can repeat the
statements in a loop structure until a condition is True, until a condition is False, a specified number of
times, or once for each element in a collection.

6. Discuss the difference between the four kinds of DO … LOOP Formats?
Ans. Differentiate between;
a. For Loop and Do Loop.
Do Loops
1

The Do...Loop construction allows you to test a condition at either the beginning or the end of a loop
structure. You can also specify whether to repeat the loop while the condition remains True or until it
becomes True.
For Loops
The For...Next construction performs the loop a set number of times. It uses a loop control variable, also
called a counter, to keep track of the repetitions. You specify the starting and ending values for this counter,
and you can optionally specify the amount by which it increases from one repetition to the next.

b. While Loop and Do Loop.
While Loop
The While...End While construction runs a set of statements as long as the condition specified in
the Whilestatement is True.
Do Loop
The Do...Loop construction allows you to test a condition at either the beginning or the end of a loop
structure. You can also specify whether to repeat the loop while the condition remains True or until it
becomes True.


7. Discuss the NESTING structures for;
a. IF Statements
Nested If...Then...Else selection structures test for multiple cases by placing If...Then...Else selection structures
inside If... Then... Else structures.
b. Loop Constructs.
When you have a loop within a loop, then you have created a nested loop. You can actually have as many
loops as you want in a nested loop provided the loops are not the never-ending type. For a nested loop that
consists of two loops, the first cycle of the outer loop will be processed first, then it will process the whole
repetitive process of the inner loop, then the second cycle of the outer loop will be processed and again the
whole repetitive process of the inner loop will be processed. The program will end when the whole cycle of the
outer loop is processed.

VERY SHORT TYPE QUESTIONS

1. Write a brief note on Boolean Data Type?
Ans. Boolean
Boolean data types hold either a true or false value. These are not stored as numeric values and
cannot be used as such. Values are internally stored as -1 (True) and 0 (False) and any non-zero
value is considered as true.

2. Discuss the different Data Types with memory size in VB?
Ans.
Data types
By default, Visual Basic variables are of variant data types. The variant data type can store numeric,
date/time or string data, etc. When a variable is declared, a data type is supplied for it that determines the
kind of data they can store. The fundamental data types in Visual Basic including variant are Integer, Long,
Single, Double, String, Currency, Byte and Boolean. Each data type has limits to the kind of information
1

and the minimum and maximum values it can hold. In addition, some types can interchange with some
other types.

Numeric
Byte Store integer values in the range of 0 – 255
Integer Store integer values in the range of (-32,768) - (+ 32,767)
Long Store integer values in the range of (- 2,147,483,468) - (+ 2,147,483,468)
Single Store floating point value in the range of (-3.4x10-38) - (+ 3.4x1038)
Double Store large floating value which exceeding the single data type value
Currency store monetary values. It supports 4 digits to the right of decimal point and 15 digits to
the left

String
A variable of type string requires 1 byte of memory per character and uses alphanumeric values gto
store. A variable length string can store approximately 4 billion characters.
Date
Use to store date and time values. A variable declared as date type can store both date and time
values and it can store date values 01/01/0100 up to 12/31/9999
Boolean
Boolean data types hold either a true or false value. These are not stored as numeric values and
cannot be used as such. Values are internally stored as -1 (True) and 0 (False) and any non-zero
value is considered as true.
Variant
Stores any type of data and is the default Visual Basic data type. In Visual Basic if we declare a
variable without any data type by default the data type is assigned as default. A variable of type
variant requires 16 bytes of memory.


3. What are different types of Operators available in VB?
Ans.
a) Arithmetic Operators
b) Logical Operators
c) Relational Operators

1

4. Is it necessary to put a break statement after the last CASE statement in a SWITCH … CASE
statement?
Ans. Yes

5. What is the function of Modulus (MOD) Operator in VB?
Ans. Modulus Operator (Mod), the modulo (sometimes called modulus) operation finds the remainder
of division of one number by another.
6. What is the Precedence of Operators?
Ans.
Order Operators
1 Parentheses
2 ^
3 *, /, \, Mod
4 +, -
5 Conditional Operators including LIKE
6 NOT
7 AND
8 OR
9 XOR

7. If x = 10 and y = 5, the output of values of ‘x’ and ‘y’ after program execution;
a. x = y – 2 * x
Ans. X = 5 – 2 * 10 = 5 – 20 = - 15
b. y = x + x / y – 3
Ans. = 10 + 10 / 5 – 3 = 10 + 2 – 3 = 12-3 = 9
c. x = (x + y) * 4 / 10
Ans. = (10 + 5) * 4 / 10 = 15 * 4 / 10 = 60 / 10 = 6
d. y = y ^ 2 – 5 * 10
Ans. = 5 ^ 2 – 5 * 10 = 25 – 50 = - 25
8. Write functions of a Logical Operators?
Ans.
Comparison operators compare two expressions and return a Boolean value that represents the
relationship of their values. There are operators for comparing numeric values, operators for
comparing strings, and operators for comparing objects.
An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.
VB is rich in built-in operators and provides following type of commonly used operators:
 Arithmetic Operators
 Comparison Operators
 Logical/Bitwise Operators
1

9. Find the Output, Syntax / Logical errors if any, in the following VB program codes?
d) For a = 1 to 20
For b = 1 to 8
Print a, b
Next a
Print
Next b
Ans. Errors on line no.s 4 and 6, Next a should be replaced by Next b and Next b should be corrected as
Next a.
Output (after correction)
1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8
2 1 1 2 2 3 2 4 2 5 2 6 2 7 2 8
3 1 3 2 3 3 3 4 3 5 3 6 3 7 3 8
4 1 4 2 4 3 4 4 4 5 4 6 4 7 4 8
5 1 5 2 5 3 5 4 5 5 5 6 5 7 5 8 ......
b) Sum = 0
I = 1
While I >= 5
N = inputBox (“Enter Number:”)
Sum = Sum + N
I = I + 1
Wend
Print Sum
Ans. Say N gets the values as 5, 6, 7, 8, 9
Sum = 35

c) Dim S as string
Dim X as integer
S =”Board of School Education”
X =1
Do While X <= Len(S)
Print Mid (S, X, 1);
X = X + 1
Loop
Ans. Board of School Education

d) Dim S as string
Dim X as integer
S = “12345”
X = S Mod 10
Do
Print Val (Mid(S, X)
X = X – 1
Loop While X > 0
Ans.
5
4 5
3 4 5
2 3 4 5
1

1 2 3 4 5
MULTIPLE CHOICE QUESTIONS

1. Visual Basic Language was developed from;
a. C Language
b. C++ Language
c. Fortran
d. BASIC Ans. D
2. BASIC means;
a) Begin All Symbols Instruction Code
b) Beginners All Symbols Instruction Code
c) Beginners All-purpose Symbolic Instruction Code
d) Beginners All-purpose Symbolic Instruction Coding Ans. C
3. In Visual Basic language the __________ translators are used;
a. Interpreter
b. Compiler
c. Assembler
d. Both ‘a’ and ‘b’ options Ans. D
4. MSDN stands for;
a. Microsoft System Development Network
b. Microsoft Developer’s Network
c. Microsoft System Domain Networking
d. None of above Ans. A
5. A NULL string, sometimes called;
a. Zero-length string
b. Zero bytes in length
c. Null strings
d. All of these Ans. A
6. Boolean data, named after ___________, represents data that can take only two values.
a. Charles Babbage
b. Lady Ada
c. George Boole
d. Boole Johnson Ans. C
7. A Variant data type can hold any kind of data except;
a. Single
b. Decimal
c. Boolean
d. Fixed-length strings Ans. D
8. In Visual Basic, the variables are declared by;
a. Declare
b. Dim
c. Redim
d. Dimension Ans. B
9. The SELECT … CASE allows for a range of choices using ________ keyword;
a. From
b. Between
c. To
d. Either ‘a’ or ‘c’ option Ans. C
1

10. A special case occurs, if a value of one side or the other of a condition contains NULL value,
VB returns;
a. True
b. False
c. Null
d. Empty Ans. A
11. A FOR Loop may execute or run depending upon;
a. Start value
b. End value
c. Condition
d. Both ‘a’ and ‘b’ option Ans. C

FILL IN THE BLANKS

1. Visual Basic offers several wizards, but the one used most frequently is ___________ wizard.
2. An ___________ is an activity that occurs during a program execution, such as a mouse click
or a keystroke.
3. A Currency data type occupies ___________ bytes storage location in a PC’s memory.
4. A String is a series of ____________ or more characters.
5. If you don’t require variable declaration, VB assumes that an undeclared variable is of the
____________ data type.
6. The FOR Loop continues until a _____________ is met.
7. The __________ Loop automatically changes controlling variables by adding or subtracting
to or from the control variable each time the loop iterates.
8. Visual Basic supports another conditional operator ‘LIKE’, which compares values based on a
____________ match.

ANSWERS
1. Auto 2. Event 3. 32 4. One 5. Variant 6. Condition 7.
For 8. Condition
TRUE / FALSE QUESTIONS

1. A procedure is a section of VB programming code that holds only VB variable declarations.
2. The Form Window holds one form at a time.
3. VB automatically generates the first and the last level for the Click Event procedure when
you double click a control.
4. Properties Window in a VB support multiple events.
5. A literal’s value never changes.
6. A variable’s value always changes or modifies.
7. A nested statement is a one statement that appears outside another’s body.
8. You can combine the various forms of CASE expressions into a single SELECT … CASE
statement.
9. Both blocks of an IF … ELSE might execute together.

ANSWERS
1

1. False 2. False 3. True 4. True 5. False 6. True 7. False 8. True 9.
False
TRUE / FALSE QUESTIONS