VB UNIT - III Part - II
VB UNIT - III Part - II
An array is a collection of sequential memory locations identified by a single name and able to
hold similar type of data in all its locating.
Or
An array is a data item with a single name & can hold several values of same type.
Static array
The array whose dimensions of size is can not be changed at run time is called static array.
If array has only one dimension of indices is called single dimension array.
Declaration of array:
The arrays can be declared as code level,module level or local arrays.
The code level arrays are declared using public keyword(in code module).The module arrays
are declared using dim or private in general declaration section.The local arrays are declared
using dim or static in procedures or functions.
The array can also have multiple dimensions of indices is called Multi dimension array.
If array has two indices,it is refered as 2-dimensional array,similarly if the array as 3-
dimentional array and so on.thus multidimensional arrays are represented with multiple indices.
Temp(0,0)=10
Temp(0,1)=11
Temp(0,2)=12
To create a single dimension dynamic array declare it as that of fixed array using Dim(or public
or private)without specifying the dimension as shown below.
when you know how many elements have to be stored redimension using Redim statement
as shown in below.
The multidimensional dynamic array also possible.The redim stasement can be used to
redimension a dynamic array to multiple dimensions.
In many circumstances you need to have controls of same type like three text box controls or four
option button controls etc. you can place all such controls from ToolBox,however if all such controls are
used for certain group of activities the coding becomes laborious and bit difficult.
An alternate approach,the “array of controls”can be used to waive such difficulties.The array is
programming data type which consist several elements of same type
The array of controls or control array can be created at design time or at run time.
1. Place a control of your requirement on the container object such as form control (frame control can
also be the one choice).this control is template control for the next course of an action in creating a
control’s array.
2. Make a copy of it and paste it on the container object like form. The visual basics prompts you with
a message indicating the creation of control array.
3. Select option YES, the visual basic creates an array of controls and pastes the control at the left-of
container object
4. Drag the pasted control to a desired position on the container object
5. The template control is the first element in the array with index 0 and pasted control is next elements
in the control array with the array index1.
6. Once the control array is created, you can place any number of controls just by copy and paste
procedure .The visual basic will not prompt any message for the copy and paste operations.
MDI and SDI interface designs for handling documents within a single application.
SDI: stands for “ single document interface. it is an interface design for handling document
within single application. SDI exists independently form others and thus is a stand-alone window
.SDI supports one interface means you can handle only one application at a run time .for grouping
SDI uses window managers
MDI: stands for multiple document interface .it is an interface design for handling document
within a single application. When application consist of an MDI parent form containing all other
window consisted by app, then MDI interface can be used. switch focus to specific document can
be easily handled in MDI .For maximizing al documents parent window is maximized by MDI.
Key difference:
MDI stands for “multiple document interface” while SDI stands for “ single document interface “
One document per window is enforced in SDI while child windows per document are allowed in
MDI
MDI is a container control while SDI is not a contained control
SDI contain one window only at a run time But MDI contain multiple document at a run time
appeared as child window
MDI supports many interface means we can handle many application at a run time according to user
requirement .But SDI supports one interface means you can handle only one application at a run
time .
For switching between document, MDI uses special interface inside the parent window while SDI
uses task manager for that.
In MDI grouping is implemented naturally but in SDI grouping is possible through special window
managers
For maximizing all document ,parent window is maximized by MDI but in case of SDI it is
implemented through a special code or window manager
switch focus to specific document can be easily handled while in MDI but it is difficult to implement
in SDI
operations :
To read the data from the sequential file using input( ) method
Syntax:
line input #
or
input( )
Or
input#
To write the data from the sequential file using print() & write() method
Syntax:
Print # filenum , str1
visual basic provides three intrinsic controls on the tool box for accessing the computer file system,
namely drive list box , dirlist box ,file list box. The drive list box control is similar to combo box control and
other two controls are similar to list box control
drive list box : this control displays the drives on the system in a dropdown list from. The user can
select any drive from the list. The property of this control is the drive property which sets the drive
to be initially selected in the control or returns of the user selection.
directory box :this control displays a list of the folders in the current drive and lets the user move
up or down in the hierarchy of the folders , the basic property of this control is the path property
,which is the name of the folder whose sub folders are displayed in the control .
file list box : this control displays a list of all files in the current directory and lets the user moves
up or down in the hierarchy of files . the basic property of this control is also the path property
which is the path name of the folder whose files are displayed in the control.
Which is in the form of dialog & helps to simplify the creation of menus.
1. The caption box: What you type here is what the user sees.
2. The name box: The name entered here is the control name for the menu item, you enter the code
for menu item under this control name.
3. Shortcut box: You enter the shortcut keys for the menu items here click on the down arrow, a
drop down list box will be displayed with all the shortcut keys , click on the one you want to use.
4. The checked check box: Click on this if you want to display a tick mark to show that a menu
item has been selected. The default is off. This can be turned ON or OFF at run time.
5. Enabled checkbox: Click on this to make a menu item enabled. If a menu item is enabled, it will
respond to the mouse click. This can be turned on or off at run time.
TREE VIEW CONTROL AND LIST VIEW CONTROLS CAN BE USED TO ORGANIZE
DATA IN HEIRACHIES AND LISTS RESPECTIVELY
PROGRESS BAR: This control can be used as progress indicator by uploading it .The progress
indicator lets the user know how the calculations are proceeding and how much longer they will
take to complete
image combo control: Is similar to a combo box control with few major differences .the image
combo control can display images next to its items instead of text as in simple combo box control.
The window common dialog control is the most common control used for operations like font
selection,printer selection and file operation in vb.it is not displayed at run time like timer control.the
common dialog control provides the following built in windows dialog boxes.
Subroutines
A sub routines is a block of statements that curries out a well- defined unique defined
task and do not return result . the block of statements of makeup subroutine is placed with a pair of
sub/end sub statements.
Example :
Sub showtime()
Msgbox time()
End sub
When this subroutine is called , it displayed a message of current time.
Functions:
Functions are another kind of procedures available in VB . A function is block of statements
that carries out a well-defined unique task and return result.
The block of statements that makeup functions is placed with a pair of function/end function
statements. The function has a name similar to variables and can be invoked by this name.
Example:
Function findbig() as integer
Findbig=IIF(4>5),4,5)
End function