0% found this document useful (0 votes)
28 views

Vb-Notes1

Event driven programming determines the sequence of operations based on user interaction rather than a predetermined path. Common events for Visual Basic objects include change, click, keydown, and lostfocus. Visual Basic supports numeric data types like integer and double that can be used for calculations requiring different levels of precision. Non-numeric types include string, date, boolean, and variant. Arrays store multiple values of the same type, while dynamic arrays allow the size to vary at runtime using the ReDim statement.
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)
28 views

Vb-Notes1

Event driven programming determines the sequence of operations based on user interaction rather than a predetermined path. Common events for Visual Basic objects include change, click, keydown, and lostfocus. Visual Basic supports numeric data types like integer and double that can be used for calculations requiring different levels of precision. Non-numeric types include string, date, boolean, and variant. Arrays store multiple values of the same type, while dynamic arrays allow the size to vary at runtime using the ReDim statement.
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/ 6

1.What do you understand by event driven programming?

List and explain


about some of the events supported by Visual Basic Objects.
Event Driven Programming :-

In conventional programming, the sequence of operations for an application is determined by a


central controlling program (e.g., a main procedure). In event-driven programming, the
sequence of operations for an application is determined by the user’s interaction with the
application’s interface (forms, menus, buttons,etc.).
In an event –driven application , the code doesn’t follow a predetermined path rather it
executes different code sections in response to events . Events can be triggered by the user’s
actions ,by messages from the system or other applications, or even from the application itself.
The sequence of these events determines the sequence in which the code executes , thus the
path through the application’s code or the sequence of execution differs each time the program
runs.

Events common to most VB controls are described in the table below.

Event Occurs When ...


Change The user modifies text in a combo box or text box.
Click The user clicks the primary mouse button on an object.
DblClick The user double-clicks the primary mouse button on an object.
DragDrop The user drags an object to another location.
DragOver The user drags an object over another control.
GotFocus An object receives focus.
KeyDown The user presses a keyboard key while an object has focus.
KeyPress The user presses and releases a keyboard key while an object has focus.
KeyUp The user releases a keyboard key while an object has focus.
LostFocus An object loses focus.
MouseDown The user presses any mouse button while the mouse pointer is over an
object.
MouseMove The user moves the mouse pointer over an object.
MouseUp The user releases any mouse button while the mouse pointer is over an
object.
2.What are the different data types supported by Visual Basic ? How they can be
declared ? Also mention their uses

Visual Basic Data Types


Visual Basic classifies the data types in two major categories:-
1). Numeric Data Types and 2).Non-Numeric data types.
1. Numeric Data Types
Numeric data types are types of data that consist of numbers, which can be computed
mathematically with various standard operators such as add, minus, multiply, divide and more.
Examples of numeric data types are examination marks, height, weight, the number of students in
a class, share values, price of goods, monthly bills, fees and others. In Visual Basic, numeric data
are divided into 7 types, depending on the range of values they can store. Calculations that only
involve round figures or data that does not need precision can use Integer or Long integer in the
computation. Programs that require high precision calculation need to use Single and Double
decision data types, they are also called floating point numbers. For currency calculation , you can
use the currency data types. Lastly, if even more precision is required to perform calculations that
involve a many decimal points, we can use the decimal data types. These data types summarized in
Table given below:-
Numeric Data Types
Type Storage Range of Values
Byte 1 byte 0 to 255
Integer 2 bytes -32,768 to 32,767
Long 4 bytes -2,147,483,648 to 2,147,483,648
-3.402823E+38 to -1.401298E-45 for negative values
Single 4 bytes
1.401298E-45 to 3.402823E+38 for positive values.
-1.79769313486232e+308 to -4.94065645841247E-324 for negative values
Double 8 bytes
4.94065645841247E-324 to 1.79769313486232e+308 for positive values.
Currency 8 bytes -922,337,203,685,477.5808 to 922,337,203,685,477.5807
+/- 79,228,162,514,264,337,593,543,950,335 if no decimal is use
Decimal 12 bytes
+/- 7.9228162514264337593543950335 (28 decimal places).

2. Non-numeric Data Types


Nonnumeric data types are data that cannot be manipulated mathematically using standard
arithmetic operators. The non-numeric data comprises text or string data types, the Date data
types, the Boolean data types that store only two values (true or false), Object data type and
Variant data type .They are summarized in Table given below:-

Non-Numeric Data Types

Data Type Storage Range


String(fixed length) Length of string 1 to 65,400 characters
String(variable length) Length + 10 bytes 0 to 2 billion characters
Date 8 bytes January 1, 100 to December 31, 9999
Boolean 2 bytes True or False
Object 4 bytes Any embedded object
Variant(numeric) 16 bytes Any value as large as Double
Variant(text) Length+22 bytes Same as variable-length string
3.Give difference between arrays and dynamic arrays. How they can be created in Visual Basic
? Give Syntax
Arrays :-
An array is a collection of values of the same data type. The values in an array are called array
elements. Array elements are accessed using a single name and an index number representing the
position of the element within the array.

Arrays are used in a database application to handle data for processing.

Declaring Arrays

Unlike simple variables, arrays must be declared with the Dim (or Public, or Private) statement
followed by the name of the array and the index of the last element in the array in
parentheses for example:

Dim Ages(19) As Integer


Ages is the name of an array that holds 20 values (the ages of the 20 employees), with indices
ranging from 0 to 19. Ages(0) is the first person´s age, Ages(1) the second person´s age, and so
on. All we have to do is remember who corresponds to each age, but even this data can be
handled by another array. To do this, we declare another array of 19 elements as follows:

Dim Names(19) As String

and then assign values to the elements of both arrays:

Names(0)= "John"
Ages(0) =34
Names(1)= "Sam"
Ages(1) =38
Names(19)= "Hedric"
Ages (19) =45

Dynamic Arrays

Sometimes we will not know how large an array to create. The earlier approach was to make it
large enough to hold the maximum number of data. This will result in on an average, most of the
array will be empty. To avoid this we can declare a dynamic array. The size of a dynamic array can
vary during the execution of the software program.

With a dynamic array, we can discard the data and return the resources it occupied to the system.

To create a dynamic array, declare it as usual with the Dim statement, Public or Private but don´t
specify its dimensions:

Dim DynArray As Integer

Later in the program, when we know how many elements we want to store in the array, use the
ReDim statement to redimension the array, this time to its actual size. In the following example,
UserCount is a user-entered value:

ReDim DynArray(UserCount)

The ReDim statement can appear only in a procedure. Unlike the Dim statement, ReDim is
executable, it forces the application to carry out an action at runtime. Dim statements aren´t
executable, and they can appear outside procedures.

A dynamic array also can be redimensioned to multiple dimensions. Declare it with the Dim
statement outside any procedure as follows

Dim Matrix() As Double

and then use the ReDim statement in a procedure to declare a three-dimensional array:

ReDim Matrix(9,9 , 9)

Note that the ReDim statement can´t change the type of the array that´s why the As clause is
missing from the ReDim statement. Moreover, subsequent ReDim statements can change the
bounds of the array Matrix but not the number of its dimensions. For example, we can´t use the
statement ReDim Matrix(99, 99) later in your code. Once an array has been redimensioned once, its
number of dimensions can´t change. In the preceding example, the Matrix array will remain three-
dimensional through the course of the application.

The ReDim statement can be issued only from within a procedure. In addition, the array to be
redimensioned must be visible from within the procedure that calls the ReDim statement.

Sr No. Arrays Dynamic Arrays


1. An array is a collection of values of the Sometimes we will not know how large an
same data type. The values in an array array to create. The earlier approach was
are called array elements. Array to make it large enough to hold the
elements are accessed using a single maximum number of data. This will result
name and an index number in on an average, most of the array will
representing the position of the be empty. To avoid this we can declare a
element within the array. dynamic array. The size of a dynamic
array can vary during the execution of the
software program.

With a dynamic array, we can discard the


data and return the resources it occupied
to the system.
2. The size of an array can’t vary during The size of a dynamic array can vary
the execution of the program. during the execution of the software
program
3. Arrays must be declared with the Dim Dynamic array is also declared with the
(or Public, or Private) statement Dim statement, Public or Private but
followed by the name of the array and don´t specify its dimensions:
the index of the last element in the Dim DynArray As Integer
array in parentheses for example:
Later in the program, when we know how
Dim Ages(19) As Integer. many elements we want to store in the
array, use the ReDim statement to
redimension the array, this time to its
actual size. In the following example,
UserCount is a user-entered value:

ReDim DynArray(UserCount)

5.Write a program with a good interface in visual Basic to print first 20 Fibonacci
numbers.
Private Sub Command1_Click()
Dim x, g, n, i, sum As Integer
n = 20
x=0
y=1
Print x
Print y
For i = 3 To n
sum = x + y
Print sum
x=y
y = sum
y = sum
Next i
End Sub

6. a)

Sr No. List Box Combo Box


1. Occupies more space but shows more Occupies less space but shows only one
than one value. value for visibility .

2. We can select multiple items. Multiple select is not possible

3. we can use checkboxes with in the list can't use checkboxes within combo boxes
box.

4.

b) Diffence between picture box and image box :-

1. A Picture Box can act as a container , An image control can't.


2. An Image control has Stretch property, a Picture Box control does not.
3. Picture Box control has an AutoSize property, an Image control does not.
4. A Picture Box control is a container control, an Image control is not.
5. A Picture Box control also has a whole bunch of properties that an Image Control does not -
BackColor, FillColor, FillStyle, etc.

c) Diffence between Check Box and Option Button :-

1.
Option Button Checkbox

It is an element of a form It is also an element of a form


It is used for selecting options It is also used for selecting options
It is a graphical user interface widget It is also a graphical user interface widget
Only one option can be selected One or more options can be selected
Example:Selecting of Gender Example:Selecting the games known

Select your Highest Educational qualification: Select the games you can play:
B.Sc Hockey
M.Sc Cricket

B.Tech Baksket Ball

(d) Difference Between Pop Up and Dynamic Menu (do yourself)

You might also like