0% found this document useful (0 votes)
7 views20 pages

VB UNIT - III Part - II

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)
7 views20 pages

VB UNIT - III Part - II

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/ 20

ARRAY

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.

1. single dimension 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.

Example: Dim marks(3) As integer

Accessing and initialization of array


Dim marks(3) As integer
Marks(0)=10
Marks(1)=20
Marks(2)=30
2. multi dimensional array

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.

Example: Dim Temp(2,3) As integer.

Acessing & initialisationof 2-dimensional array.

Dim Temp(2,3) As integer.

Temp(0,0)=10
Temp(0,1)=11
Temp(0,2)=12

Visual Programming - I B.C.A Semester III: Visual Programming 1


 Dynamic arrays:
The arrays whose dimension value of size is changed at run time called dynamic arrays.
The dynamic arrays are similar to fixed arrays except that the dimension value is not defined
at declaration instead it is redefined at any instant in run time.

1. single dimension array:

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.

Example: Dim dynmarks() As integer

when you know how many elements have to be stored redimension using Redim statement
as shown in below.

Example : Redim Dynmarks(user_count)

2. Multi dimensional dynamic arrays:

The multidimensional dynamic array also possible.The redim stasement can be used to
redimension a dynamic array to multiple dimensions.

Declare the array using Dim statyement as shown

Example: Dim Dynmarks() As integer.

Then change number of dimensions using Redim as shown

Example : Redim Dynmarks(2,3,4)

Visual Programming - I B.C.A Semester III: Visual Programming 2


 CONTROL ARRAY

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.

CREATING CONTROL, ARRAY AT DESIGN 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.

Visual Programming - I B.C.A Semester III: Visual Programming 3


Multiple Document interface

What is different between SDI and MDI(4m)(Nov 2009)(2011)(2012)


Or
What is MDI and SDI(6m)(2016)(2017)

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

Visual Programming - I B.C.A Semester III: Visual Programming 4


File
A file is a storehouse of a information, which stores information permanently in a disk or in any
other secondary storage device unlike RAM the file is structured memory block seen by the operating
system, where the programmer can store or retrieve the large amount of data which is almost impossible task
by the traditional variables.

Different types of accessing files:

 SEQUENTIAL ACCESSING FILES:


Data is written or retrieved in sequential manner i.e. to read or write particular item
previous data must have to be tracked over before the operation takes place in vb. this approach is
used for text files having fixed length records or variable length records

 RANDOM ACCESS FILES :


Data is written or retrieved in random manner i.e. any piece of data is accessed without
scanning the previous piece of data in vb. this approach is used for text files having only fixed length
records.

 BINARY ACCESS FILES:


Binary access allows the user to store data as single string of binary characters . it is similar
to random access , except that there are no assumptions made about data type or record length .
however ,one must know precisely how the data was written to the file to retrieve it correctly . binary
files are generally compact ,flexible and can store any type of data .

Visual Programming - I B.C.A Semester III: Visual Programming 5


file handling and file operator or modes

operations :

1.opening the file :


provides a connection between the file and program and serves memory for temporary
storage .
Synatax :

Open “file name” FOR[]input/[output/append/random access] as # file number [len=buffer]

The sequential file can be opened using above open statement .

3. reading or writing data:


Allow reading or writing data from or to the file.

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

Write # filenum, str1, int num.

To randomly accessing data from sequential file use,


Get # file num position employ1
Put # file num position employ1

3.closing the file:


removes connection between the file and program and releases memory used for temporary
storage .

The syntax is.


Close # file number
The close statement can be used to close many files as close

Visual Programming - I B.C.A Semester III: Visual Programming 6


visual basic file controls OR drive list box, dirlist box, file list box control

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.

Visual Programming - I B.C.A Semester III: Visual Programming 7


MENU EDITOR

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.

Visual Programming - I B.C.A Semester III: Visual Programming 8


6. The visible check box: If it is set to off then the menu item and it’s sub-menus will not be visible.
This can be turned on or off at run time.
7. The text window: This gives a preview of what you have entered, you can also view the hierarchy
of menus and sub-menus by looking at the indentations.
8. The left arrow button brings the menu item one level up.
9. Clicking on the right arrow moves the menu item one level deeper.
10. The up arrow interchanges the current line with the line above.
11. The down arrow interchanges the current line with the line below.
12. Index: Allows you to assign a numeric value that determines the control’s position within a control
array. This position isn’t related to the screen position.
13. Help context ID: Allows you to assign a unique numeric value for the context ID. This value
is used to find the appropriate help topic in the help file identified by the help file property.
14. Negotiate position: Allows you to select the menu’s negotiate position property. This property
determines whether and how the menu appears in a container form.
15. Next: Moves selection to the next line.
16. Insert: Inserts a line in the list box above the currently selected line.
17. Delete: Deletes the currently selected line.
18. Ok: Closes the menu editor and applies all the changes to the last form you selected.
19. Cancel: Closes the menu editor and cancels all changes.

Visual Programming - I B.C.A Semester III: Visual Programming 9


design a tool bar

Use the following steps to creating tool bar


1.starts a new project .get the Microsoft common control on to the tool box area
2.place list image and tool bar control on the form
3.add some icon to the image list control as explained
4.open the property dialog of tool bar control on the general tab set a reference to the image list control
5.go to the buttons tab, add 4 button to the tool bar by checking a insert button command button set a style
property to tool bar default .enter on image number and add text to the caption property
The design form appears as show in figure
Then add following code

Private sub toolbar_button click(By val button as mscometlib.button)


Select case button .index
Case 1:
Msgbox ”the caption is:”&button caption
Case 2:
Msgbox “the caption is:”&button caption
Case 3:
Msgbox ”the caption is:”&button caption
Case 4:
Msgbox ”the caption is:”&button caption
End select
End sub

Visual Programming - I B.C.A Semester III: Visual Programming 10


MICROSOFT COMMON CONTROL
THE GROUP CONTROL AVAILABLE IN THE MICROSOFT WINDOWS COMMON
CONTROLS 6.0 IS REFFERED TO AS MICROSOFT COMMON CONTROLS .
THE FOLLOWING ARE MICROSOFT COMMON CONTROLS :
 TAB STRIP CONTROL
 TOOL BAR CONTROL
 STATUS BAR CONTROL
 PROGRESS BAR CONTROL
 PREE VIEW CONTROL
 LIST VIEW CONTROL
 IMAGE LIST CONTROL
 SLIDER CONTROL
 IMAGE COMBO

 TREE VIEW CONTROL AND LIST VIEW CONTROLS CAN BE USED TO ORGANIZE
DATA IN HEIRACHIES AND LISTS RESPECTIVELY

 IMAGE LIST CONTROL CONTROL :GIVES U A MEANS OF LOADING GRAPHICS FILES


,SUCH AS ICONS AND BITMAPS INTO UR APPLICATIONS FOR USE WITH OTHER
CONTROLS PARTICULARITY WITH TREE VIEW ,LIST VIEW AND TOOL BAR
CONTROL.

 TOOL BAR CONTROL: ENABLES U TO QUIKLY BUILD TOOL BAR IN UR


APPLICATION ,GIVING THE USRES AN ALTERNATIVE TO THE MENU FOR
PERFOMING ACTIONS

 STATUS BAR THIS CONTROL CAN BE ADDED TO AN APPLICATION TO PRESENT


INFORMATION ABOUT THE ENVIRONMENT TO THE USER THROUGH TEXT MSGS
AND PROGRESS BAR

 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.

Visual Programming - I B.C.A Semester III: Visual Programming 11


Microsoft common control dialog controller

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.

1. Open:it lets the user to select afile to open


2. Save as : this dialog box allows the user to specify or select a nane in which the opened file will be
saved.
3. Color : this dialog box lets the user to specify or select the color.
4. Font : this dialog box allows user to select a typespace and style to be applied to the current select
text.
5. Print: this dialog box facilitate the user to select or set up a printer .
6. Help: this dialog box display the help topics.

Using common dialog control


This control is not available in the toolbox ,in order to associate it with your project you have
to add it from component dialog.select components fro the project menu and on the file displayed
componenets dialog go to Microsoft commondialog control 6.0 and check the check box and click apply and
ok button .then the dialog control appears in the tool box area.
Method value Action
Showopen 1 display the open dialog box
Showsave 2 display the save as dialog box
Showcolor 3 display the color dialog box
Showfont 4 display the font dialog box
Showprinter 5 display the printer dialog box
Showhelp 6``` invoke the window help engine

Visual Programming - I B.C.A Semester III: Visual Programming 12


subroutines And functions
Procedures are small self contained segments of the programs used for implementing
the repetitive tasks in VB two types of procedures are available namely , subroutines and functions
the building blocks of application.

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

Visual Programming - I B.C.A Semester III: Visual Programming 13


Visual Programming - I B.C.A Semester III: Visual Programming 14
Visual Programming - I B.C.A Semester III: Visual Programming 15
Visual Programming - I B.C.A Semester III: Visual Programming 16
Visual Programming - I B.C.A Semester III: Visual Programming 17
Visual Programming - I B.C.A Semester III: Visual Programming 18
Visual Programming - I B.C.A Semester III: Visual Programming 19
Visual Programming - I B.C.A Semester III: Visual Programming 20

You might also like