VB Part 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

Visual Programming

1. What is Visual Basic?


Visual Basic is a powerful application development toolkit developed by John Kemeny and
Thomas Kurtz. It is a Microsoft Windows Programming language.
Visual means methods used to create the GUI using in-built objects.
Basic refers to the basic language used in the form of basic syntax statements.

2. What are different Editions available in VB?


Visual basic is available in 3 editions: Standard, Professional and Enterprise
Standard – Creates simple windows application. Basic controls are setup, icons and help files.
Professional – Used by Computer professionals, it includes Active X and internet controls.
Enterprise – Most advanced edition used to build applications in a team environment, it includes
features like OLE automation and Remote Database access tools.

3. List the various features of VB


The features of VB are as follows:
1. Client- Server Architecture – It supports Client- Server Architecture, ActiveX, COM
(Component Object Model), DCOM (Distributed Component Object Model) and ODBC
(Open Data-Base Connectivity).
2. IntelliSense – This feature enables the system to interact with user during coding. Few
IntelliSense features are:
a) Quick Info – Displays syntax in a Tool Tip like window.
b) Complete Word –Automatically completes the word after enough characters have been
typed.
c) Data Tips – A yellow Tool Tip that displays values at run time.
d) List Members - The properties of a given object are shown.
e) List Constants – It lists all the constants of an object.
3. IDE (Integrated Development Environment) – Multiple projects can be done at the same
time, hence saving time for coding and debugging.
4. ADODC (ActiveX DataObject DataControl)- It allows to create database application with
codes.
5. Data List, Data Combo Controls–These controls contain data which can be linked to
ADODC in the form of a List Box or a Combo box.
6. Data Time Picker Control – It allows to pick date and time.
7. Data Report – It is used to create reports from any record set.
8. IIS (Internet Information Server) Applications – The user can write Server side Internet
application which use VB 6.0
9. Hierarchical Flex Grid, Data Grid Control – Records can be displayed as a separate row
within the grid using both Grids.
10. Bookmarks – This feature is placed for quick search.
11. Property Window – Made to list properties alphabetically or by category.
12. Mouse usage: i. This feature toggles breakpoints.
ii. All highlighted code can be commented or uncommented.

4. What is IDE? What are the types of applications that can be created in VB
Visual Basic is an Integrated Development Environment (IDE). The most important
applications that can be developed in Visual Basic are:
 Standard EXE:Standard EXE application is common to all versions of Visual Basic.

 ActiveX EXE, ActiveXDLL:Both are code building components which do not have a visible
interface, they exhibit identical functions but both are packaged into different Dynamic Link
Libraries or executable files.

 ActiveX Control:This application is used to build own custom controls also called OCX file.

 VB Application Wizard:VB Application Wizard project is used to provide a new skeleton for
an application (similar to word processor template).

 VB Wizard Manager:VB Wizard Manager is used to build a new wizard. A wizard is a


sequence of windows, which calls information from the user.

 Data Project:Data Project is like Standard EXE project but it adds those controls which are
used in accessing database.

 DHTML application:DHTML Application provides facility for the development of dynamic


HTML pages with the use of Visual Basic tools. It can develop those pages, which are
displayed in the browser's window on a client computer.

 Add-in:Add-in is used for the creation of special type of commands in Visual Basic IDE. E.g.
Visual Data Manager.

5. What is a Form object? Mention its events and properties


The Form is where the user interface is drawn. It is central to the development of Visual
Basic applications.

Form Properties:

Appearance Selects 3-D or flat appearance.


BackColor Sets the form background color.
BorderStyle Sets the form border to be fixed or sizeable.
Caption Sets the form window title.
Enabled If True, allows the form to respond to mouse and
Keyboard events; if False, disables form.
Font Sets font type, style, size.
ForeColor Sets color of text or graphics.
Picture Places a bitmap picture in the form.
Visible If False, hides the form.

Form Events:

Activate Form_Activate event is triggered when form becomes


the active window.
Click Form_Click event is triggered when user clicks on
form.
DblClick Form_DblClick event is triggered when user double-
clicks on form.
Load Form_Load event occurs when form is loaded. This
is a good place to initialize variables and set any run-
time properties.

· Form Methods:

Cls Clears all graphics and text from form. Does not clear
any objects.
Print Prints text string on the form.

Examples

frmExample.Cls ' clears the form


frmExample.Print "This will print on the form"

6. List the various intrinsic controls, its properties and methods

The command button is probably the most widely used control. It is used to begin,
interrupt, or end a particular process.
7. What is MDI? What are the advantages of MDI forms and its features?

The Multiple Document Interface (MDI) was designed to simplify the exchange of
information among documents; you can maintain multiple open windows.
The main Form, or MDI Form, isn't duplicated, but it acts as a container for all the windows, and it
is called the parent window. The windows in which the individual documents are displayed are
called Child windows. At run time, an MDI form and all of its child forms take on special
characteristics:
• All child forms are displayed within the MDI form's workspace. The user can move and
size child forms like any other form; however, they are restricted to this workspace.
• By setting the AutoShowChildren property, you can display child forms automatically when
forms are loaded (True), or load child forms as hidden (False).

Advantages of MDI
 MDI applications can often handle multiple documents more readily than SDI
programs.
For example, many MDI text editors allow the user to open multiple text files side by
side in the same window.
 It easy to compare and look up information from a second document while working on
the first.
 MDI applications tend to perform more quickly than SDI programs
SDI MDI
(i) It stands for single Document Interface. (i) It stands for Multiple Document Interface.
(ii) There is no concept of parent window
rather every window is independent of each (ii) In MDI all the windows are a part of a larger
other. parent window
(iii) It act as an container for other controls or (iii) It acts as an container for other windows or
objects forms.
(iv) It has MDI-child property which is used to
(iv) No such type of property is available setup a window as child.
(v) The windows can be moved around only with
(v) All the windows can be moved freely the parent window.
(i) It stands for Multiple Document Interface.
(i) It stands for single Document Interface. (ii) In MDI all the windows are a part of a larger
(ii) There is no concept of parent window parent

8. Write short notes on the following – a) Activex Data Objects (ADO), b) Procedures and its
types and c) Control Array

a) Activex Data Objects. (ADO)


Microsoft’s latest set of data access objects are the ActiveX Data Objects (ADO). These objects let
you access data in a database server through any OLE DB provider. ADO is intended to give you a
consistent interface for working with a wide variety of data sources, from text files to ODBC relational
databases to complex groups of databases.
The ADO object model consists of six objects:
• Connection: Represents an open connection, in this case to an OLE-DB data source that
can be an ODBC data source, using MSDASQL (the Microsoft OLE-DB provider for
ODBC).
• Error: Contains details about data access errors, refreshed for each time an error occurs in
a single operation involving ADO.
• Command: Defines a specific command you wish to execute against data.
• Parameters: Optional collection off the command object for any parameters you wish to
provide to the command.
• Recordset: Represents a set of records from a table, command object, or SQL Syntax. Can
be created without any underlying Connection object.
• Field: Represents a single column of data in a recordset.
• Property: A collection of values raised by the provider for ADO.

b) Procedures and its types


A procedure is a set of one or more program statements that can be executed by referring to
the procedure name. We can reuse the code written in a procedure, as it can be executed any
number
 of times by making a call to the procedure.
The various types of Procedures are:
a) Sub procedure
b) Function procedure
c) Property procedure
In sub procedure has two types:
 General procedure
 Event handling procedure

General procedure Event handling Function procedure Property procedure


procedure
A general procedure is An Event handling A function procedure A property procedure
a block of code that procedure is a block of is a block of code is a set of code
performs a specific code that is executed enclosed within the statements that are
task. If we need to when a specific event function. End function used to assign or
perform as specific occurs, such as the click statements a function creative the value of
times in different parts of button the loading of procedure unlike a sub the properties
of the application, we a form in the memory or procedure, returns a declared with in a
can write the code in a fulfillment of a user value to the calling module, a class or a
procedure and call the defined condition. code. If we need a structure. Properties
procedure from Example: If a user click a procedure to returns a are type of variables
anywhere within the command button object value so that the that store the values
application. It is a with the name return value can be for an object of a class
declared as public command1, the further procedure in or a structure.
then other application procedure named the calling code, we
can use it. command1_click() is should create a
called and the code function procedure
within the procedure is instead a sub
execute. procedure.

c) Control Array:
Array of controls having same type & same name which share common properties is known
as control array. They also share the same event procedures. Since controls have the same name
VB needs a way to distinguish them. This is done by a property called index. This index property
identifies the specific control & gives the flexibility to organize them at runtime. Control Array can
be created either in design time or in runtime.
 Elements of the same control array have their own property settings.
 Common uses for control arrays included menu controls and option button groupings.
 If you want to create a new instance of a control at run time, the control must be a member
of a control array
Using the control array mechanisms, each new control inherits the common event procedures already
written for the array.

9. Briefly explain the ODBC architecture.

The ODBC (Open Database Connectivity) architecture has four components:


• Application - (Spreadsheet, Word processor, Data Access & Retrievable Tool, Development
Language etc.) Performs processing by passing SQL Statements to and receiving results from
the ODBC Driver Manager.
• Driver Manager - a Dynamic Link Library that Loads
drivers on behalf of an application.
• Driver - a Dynamic Link Library that Processes ODBC
function calls received from the Driver Manager,
submitting the resultant SQL requests to a specific data
source, and returns results to the application. If
necessary, the driver modifies an application's request so
that the request conforms to syntax supported by the
associated DBMS.
• Data Source Consists of a DBMS, the operating system
the DBMS runs on, and the network (if any) used to
access the DBMS.

The Driver Manager and Driver appear to an application as


one unit that processes ODBC function calls.

Types of Drivers
ODBC defines two types of drivers:-
Single-tier - The driver processes both ODBC calls and SQL statements.
Multiple-tier - The driver processes ODBC calls and passes SQL statements to the data source.

10. What is module? Define class module, form module?


VB code that is not related to a specific form or control and which contains a procedure or
variable that implements the common codes is known as modules (.bas).
Procedures that are to be used repeatedly in response to events in several different controls are
placed in standard module hence it avoids duplication of code.

A module level variable can be accessible either within a module or used by all other modules.
Variables used within a module are declared or private and the variable used by all other modules is
declared as public.
There are three types of modules in VB:-
Form module, Standard modules, Class modules
The class module contains the defining characteristics of a class, including its properties and
methods.
The form module contains the graphic elements of the VB application along with the instruction.
The general module generally contains general-purpose instructions not pertaining to anything
graphic on-screen.

11. What is a Dynamic Link Library (DLL?)


All Windows applications at their most basic level interact with the computer environment
by using calls to dynamic link libraries (DLL). DLL’s are libraries of routines, usually written in C,
C++, or Pascal, that you can link to and use at run -time.

Each DLL usually performs a specific function. By using DLL routines with Visual Basic,
you are able to extend your application’s capabilities by making use of the many hundreds of
functions that make up the Windows Application Programming Interface (Windows API).
These functions are used by virtually every application to perform functions like
 displaying windows
 file manipulation
 printer control
 menus and dialog boxes
 multimedia
 string manipulation
 Graphics and managing memory.
12. Explain Document/View Architecture

 Document/View Fundamentals Application object provides message loop and sends


messages to the frame window and the view
 Frame Window object: –Shows menu, toolbar and status bar
 View object: –Displays (renders) data and translates mouse and keyboard input into
commands to operate the data.
 Document object: –Stores data –Manipulates data

Document View Architecture


MFC Document View Architecture is a framework to manage user module data and view of the
module separately. The design it follows is known as model-view architecture. Data part is managed
by model and in MFC this is known as Document and display part is managed by view class.
The MFC document/view architecture includes a combination of a document in which data is stored
and a view which has privileged access to the data.

Document
Document is the class to manage data part of the objects. Application often derives a class from
CDocument. This deals with saving and retrieving data fields to and from the file stream.

View
View is the class module to display data of the document. A derived class of CView is often used for
this purpose. This display part can be the display of the document in graphical form or with UI
elements or in the form of printable view which contains formatted text.

Frame
MFC framework uses a Frame window or class CFrame to display window in the screen and thus a
CFrame class is always needed in any application which follows document view architecture.
13. Explain Input Box and Message Box functions.

Input Box :
Displays a prompt in a dialog box, waits for the user to input text or click a button, and returns a String
containing the contents of the text box.

Syntax :

memory_variable = InputBox (prompt[,title][,default])

memory_variable is a variant data type but typically it is declared as string, which accept the message
input by the users.

The arguments are explained as follows:

 Prompt - String expression displayed as the message in the dialog box. If prompt consists of
more than one line, you can separate the lines using the vbCrLf constant
 Title - String expression displayed in the title bar of the dialog box. If you omit the title, the
application name is displayed in the title bar
 default-text - The default text that appears in the input field where users can use it as his
intended input or he may change to the message he wish to key in.
 x-position and y-position - the position or the coordinate of the input box

Message Box:
Displays a message in a dialog box and wait for the user to click a button, and returns an integer
indicating which button the user clicked.

Syntax :

MsgBox ( Prompt [,icons+buttons ] [,title ] )

memory_variable = MsgBox ( prompt [, icons+ buttons] [,title] )


Prompt : String expressions displayed as the message in the dialog box.
Icons + Buttons : Numeric expression that is the sum of values specifying the number and type of
buttons and icon to display.
Title : String expression displayed in the title bar of the dialog box. If you omit title, the application
name is placed in the title bar.

Icons
Constant Value Description
vbCritical 16 Display Critical message icon
vbQuestion 32 Display Warning Query icon
vbExclamation 48 Display Warning message icon
vbInformation 64 Display information icon

Buttons

Constant Value Description


vbOkOnly 0 Display OK button only

vbOkCancel 1 Display OK and Cancel buttons

vbAbortRetryIgnore 2 Display Abort, Retry and Ignore buttons

vbYesNoCancel 3 Display Yes, No and Cancel buttons

vbYesNo 4 Display Yes and No buttons

vbRetryCancel 5 Display Retry and Cancel buttons

14. What do you mean by Connection String and Record Source in ADO data control?

Connection string property specify a data source by passing a detailed connection


string containing a series of argument=value statement separated by semicolons.
ADO supports five arguments for the connection string property:
• Provider: = specify the name of a provider to use for the connection.
• File name: = specifies the name of a provider specific file ( for example:= a persisted
data source object) containing present connection information.
• Remote provider: = specifies the name of a provider to use when opening a
client side connection. (Remote data service only)
• Remote server: = specifies the path name of the server to use when opening a
client side connection. (Remote data service)
• URL: = Specifies connection string as an absolute URL identifying a resource ,
such as a file or a directory.
Connection string property is read/write when the connection is closed and read-only, when it
is open. Record source:=
a) Gets or sets the statement or query that returns a Record set.
b) The Record source contains both the name of a database table and a valid SQL string
using syntax appropriate for the data source.
15. What is Common Dialog Control? Give its methods
Adding a Windows Common Dialog control to our program is easy: the steps are as
follows:
1. Select the Project|Components menu item.
2. Select the Control tab in the Components box that opens.
3. Select the entry labeled Microsoft Common Dialog Control, then click on OK to close the
Components box.
4. Add a Common Dialog control to a form in the usual way_just double-click the Common
Dialog tool in the toolbox, or select it and paint the control on the form.
5. Add the code we want to open the dialog box and make use of values the user sets.

To display various dialog boxes, we use these Common Dialog methods:-


CommonDialog1.ShowOpen_Show Open dialog box
CommonDialog1.ShowSave_Show Save As dialog box
CommonDialog1.ShowColor_Show Color dialog box
CommonDialog1.ShowFont_Show Font dialog box
CommonDialog1.ShowPrinter_Show Print or Print Options dialog box
CommonDialog1.ShowHelp_Invokes the Windows Help engine

Common Dialog box:- A Common Dialog Box is a window used to display and for accept
information.
Dialog Boxes can either be modal or modeless.
• A Modal Dialog Box does not let the user continue working with rest of the
application until it is closed.
• A Modeless Dialog Box, on the other hand lets the user shift the focus between the
dialog box and another form without having to close the dialog box

You might also like