Vb Contents

Embed Size (px)

Citation preview

  • 8/3/2019 Vb Contents

    1/39

    Question Bank for Visual Basic

    1) What is Visual Basic ? What are the various Editions of Visual Basic

    Available in market ?

    Visual basic is a powerful application development tool developed by Microsoft. It is

    used for creating customized windows based programs. Visual Basic is the fastest and

    easiest way to create application for Microsoft Windows. Visual Basic provides acomplete set of tools to simplify rapid application development, whether we are an

    experienced programmer or new to windows programming. Visual Basic consists of two

    parts Visual and Basic. The Visual part refers to the method used to create thegraphical user interface (GUI). Rather than writing numerous lines to code to describe the

    appearance and location of interface elements, We simply add objects which are prebuilt

    into place on screen. This part makes visual basic a true RAD ( Rapid ApplicationDevelopment) tool. The BASIC part refers to the BASIC language since Visual Basic is a

    descendent of BASIC (Beginners All Purpose Symbolic Instruction Code) which was

    often the first language that programmers used to learn in order to become familiar from

    the original BASIC language and now contains several hundred statements , functions

    and keywords , may of which relate directly to the Windows GUI. Visual Basic is not justa language but is an Integrated Development Environment (IDE). An IDE is basically a

    term commonly used in the programming world to describe the interface andenvironment where we can develop , run , test and debug our applications.

    The Visual Basic is available in the following three editions :

    1. Learning Edition : It allows programmers to easily create powerful applications

    for the Windows and Windows NT operating systems . Basically it contains all

    the tools like Visual Basic development environment , standard controls,samples , Setup Wizard and other tools that are required for creating a powerful

    application.2. Professional Edition : It adds to the capabilities of the Learning Edition by

    allowing us to create client/Server or Internet Enabled applications. The

    Professional Edition of Visual Basic has all the features that are found in the

    Learning Edition and includes advanced features such as tools to develop ActiveXand Internet controls.

    3. Enterprise Edition : In incorporate environment benefit by using the advanced

    features in the Enterprise Edition to create robust distributed applications in ateam setting. It includes all the features found in the professional Edition. It also

    includes Microsoft Visual Source Safe for source code control and the

    Automation and Component Manager.

    2) Define the following terms

    Design Time : The time an application is being developed in the Visual Basic

    Environment

    Run Time : The time an application is running . At run time the programmer

    interacts with application as a user would

    Neeraj Chopra 1

  • 8/3/2019 Vb Contents

    2/39

    Question Bank for Visual Basic

    Controls : Graphical representation of objects such as command button, Textbox,

    Label etc that are used by the user to provide information to the application

    Properties : The features of an object such as size, caption or color

    Methods : The actions that an object can perform or that can be performed on the

    object

    Forms : Customizable windows that serve as the interface for an application or asdialog boxes used to gather information from the user

    Project : A Visual Basic application is comprised of one or more components that

    are arranged under a project. The project is stored as a file with .vbp extension.

    Objects : A general term used to describe all the forms and controls that make up

    a program. In Visual Basic an application is a combination of Object like Form

    and Controls. Procedures that respond to Events, and other general purposeprocedures. Objects in Visual Basic as basically considered as combination of

    code and data which is treated and controlled as a unit. Command Buttons and

    other controls on a form are objects. These objects form a major part of a Visual

    Basic Application which allow the user to enter the data as well as view the

    results. Each form in a Visual Basic project is a separate object. Events : Events are the actions recognized by a form or control. Events occur a

    user, operating system or application interacts with the objects of a program. Any

    action performed by pressing a key one the keyboard or clicking a mouse for

    which code can be written is an event procedure that runs whenever the event

    occurs as a result of the user actions or program code, or they can be triggered bythe system. Depending on the event the corresponding procedure is executed but

    some events recognized by one object might not be the same as recognized by

    other objects.

    Event Driven Programming : When a program is event driven its code is executed

    in response to events invoked by the user, operating system or application. This

    differs from procedural programming where the program starts at the first line ofcode and follows a defined pathway calling procedures as needed. In traditional orprocedural applications the application itself determines which portion of code is

    to be executed and in what sequence. Execution starts with the first line of code

    and follows the coding sequence defined in the application. At times controls aretransferred to other parts of the program through statements and procedures.

    Whereas application written in Visual Basic are event driven. In an event driven

    application the code does not follow a predetermined path it executes differentcode sections in response to events. Events can be triggered itself by the user

    actions, by messages from the system or other application or even from the

    application itself. The sequence of these events determine the order in which the

    code executes thus the path differs each time the program runs.

    3) What are various types of projects available in Visual Basic Explain

    The Various types of project available in Visual Basic are as follows

    Neeraj Chopra 2

  • 8/3/2019 Vb Contents

    3/39

    Question Bank for Visual Basic

    Standard EXE A Standard EXE project is a typical and commonly used

    project type.

    ActiveX EXEActiveX DLL

    These types of projects are available with the ProfessionalEdition. ActiveX components are basic code building

    components. These are identical in functionality, but are

    packed differentlyActiveX Controls This type of project is also a feature of professional edition.

    ActiveX controls allow a user to develop their own custom

    controls or use ActiveX controls such as textbox or commandbutton control which are basic element of the user interface

    ActiveX Document Exe

    ActiveX Document DLL

    ActiveX documents are in essence Visual Basic applications

    that can run in the environment of a container that supports

    hyperlinks.VB Application Wizard

    VB Wizard Manager

    The Application Wizard provides a series of steps for setting

    up the skeleton of a new application and the wizard manager

    let the user builds its own wizard

    A wizard is a sequence of windows that collect informationfrom the user. After the user fills out all the windows, the

    wizard proceeds to build an application , install software orcarry out an automated operation for the end user.

    Data Project This is a feature of Enterprise Edition. And it does not

    correspond to a new project type. It is identical to the standard

    Exe project type but it automatically adds the control that areused in accessing databases to the toolbox. It also adds the

    database ActiveX Designers to the project Explorer Window.

    The ActiveX Designers are visual tools for accessing andmanipulating databases and generating reports.

    DHTML Application It allow us to build Dynamic HTML pages that can be

    displayed in the browsers window on the client computerIIS Application It allow us to build application that run on the Web Server and

    interact with clients over the internet with the internet

    information Server.Addin It allows us to create our own add-in for the visual basic IDE.

    Add ins are special commands that we can add to visual

    basics menu

    VB Enterprise EditionControl

    This is not a new type of project but it simply creates a newstandard Exe project and loads all the tools of the Enterprise

    Edition of Visual Basic

    4) What is Visual Basic ? Explain its various features

    Visual basic is a powerful application development tool developed by Microsoft. It isused for creating customized windows based programs. Visual Basic is the fastest and

    easiest way to create application for Microsoft Windows. Visual Basic provides a

    complete set of tools to simplify rapid application development, whether we are anexperienced programmer or new to windows programming. Visual Basic consists of two

    Neeraj Chopra 3

  • 8/3/2019 Vb Contents

    4/39

    Question Bank for Visual Basic

    parts Visual and Basic. The Visual part refers to the method used to create the

    graphical user interface (GUI). Rather than writing numerous lines to code to describe the

    appearance and location of interface elements, We simply add objects which are prebuiltinto place on screen. This part makes visual basic a true RAD ( Rapid Application

    Development) tool. The BASIC part refers to the BASIC language since Visual Basic is a

    descendent of BASIC (Beginners All Purpose Symbolic Instruction Code) which wasoften the first language that programmers used to learn in order to become familiar from

    the original BASIC language and now contains several hundred statements , functions

    and keywords , may of which relate directly to the Windows GUI. Visual Basic is not justa language but is an Integrated Development Environment (IDE). An IDE is basically a

    term commonly used in the programming world to describe the interface and

    environment where we can develop , run , test and debug our applications.

    Features of Visual Basic are as follows

    1. Global Object : To simplify the creation of reusable code libraries. Visual Basic

    let us mark objects in a code component as global so that their methods can beinvoked without explicitly creating an instance of the global objects.

    2. Portable : Both 16 bit application for windows 3.1 or 32 bit applications forwindows 95 and windows NT can be written using visual basic

    3. OLE programmability : On can write OLE server application using visual basic

    that can be manipulated from within other applications

    4. Support to Client / Server architecture : It supports client server architecturewhich can share everything from data processing power , distributing the

    responsible the responsibility for process and data integrity to the software and

    hardware of both the client and server.5. Multiple Project : Open multiple projects in the same instance of Visual Basic.

    Useful for debugging ActiveX controls.

    6. Polymorphism : The implements features allows our classes to support multipleinterfaces. Users of our component can early bind these interfaces, regardless of

    the object that implements them.

    7. Code Editor Environment : Through this feature we can block and Unblockcomments adds and removes the comment character for each line of selected

    block of text, list properties/methods presents a drop down list of properties

    available for that control.

    8. Wizards : The ActiveX Control Interface Wizards, ActiveX Document MigrationWizard , Data Form Wizard and Property Page Wizard are new . The Setup

    Wizard has been enhanced to support distribution via the Internet.

    5) What is an Integrated Development Environment ? Explain in detail

    Visual basic is a powerful application development tool developed by Microsoft. It isused for creating customized windows based programs. Visual Basic is the fastest and

    easiest way to create application for Microsoft Windows. Visual Basic provides a

    complete set of tools to simplify rapid application development, whether we are anexperienced programmer or new to windows programming. Visual Basic consists of two

    Neeraj Chopra 4

  • 8/3/2019 Vb Contents

    5/39

    Question Bank for Visual Basic

    parts Visual and Basic. The Visual part refers to the method used to create the

    graphical user interface (GUI). Rather than writing numerous lines to code to describe the

    appearance and location of interface elements, We simply add objects which are prebuiltinto place on screen. This part makes visual basic a true RAD ( Rapid Application

    Development) tool. The BASIC part refers to the BASIC language since Visual Basic is a

    descendent of BASIC (Beginners All Purpose Symbolic Instruction Code) which wasoften the first language that programmers used to learn in order to become familiar from

    the original BASIC language and now contains several hundred statements , functions

    and keywords , may of which relate directly to the Windows GUI. Visual Basic is not

    just a language but is an Integrated Development Environment (IDE). An IDE is

    basically a term commonly used in the programming world to describe the interface

    and environment where we can develop , run , test and debug our applications.

    The various features of this environment are as follows

    Visual Basic Menus : VB contains two types of menus :

    o

    Built In Menus : It appears on the menu bar across the top of VB window.Each menu contains commands that relate to the menu name. For example

    Format Menu contains commands used for formatting our form. Some of

    the commands have sub menus that contain more specific commands

    o Shortcut Menus : These are those menus containing frequently used

    commands that appear when we click the right mouse button or press

    SHIFT+F10 . The specific list of shortcuts available from context menus

    depends on the object on which we click the right mouse button.

    Toolbar : The buttons in the Toolbar represents the controls we can include in

    any program we develop. The toolbar is typically the main focus of our attention

    as we begin a new project and choose controls to depicts the options, proceduresand activities we are planning in our application

    Toolbox : The toolbox contains the objects and controls that can be added toforms to create the user interface of simple as well as complex applications. Even

    additional controls can be added to the toolbox by using the Components

    command on the Project menu.

    Form Window: In the middle of the screen between all the toolboxes and other

    windows, the form designer is place which is actually a workplace where we

    actually design the layout of the application

    Project Explorer Window : The project explorer window is quite similar towindow explorer which allows us to expand and collapse the subfolders.Projectexplorer is a quick reference to various elements forms, classes and modules in

    our project.

    Neeraj Chopra 5

  • 8/3/2019 Vb Contents

    6/39

    Question Bank for Visual Basic

    Property Window :It displays the various characteristics of the selected object .Each and every control for example a command button that appears on a form isalso an object and all characteristics of an object are called its properties.

    Code Editor Window :In visual basic , the editor is called the Code Window.Code Window can be opened by double clicking on a form or control in the formlayout window.The code can be either associated with a form in our project or

    contained in a separate code module. It contains two drop down list at the top of

    the window; the object list contains a list of all the controls contained in the formand the procedure list displays all the event for that control

    6) What are modules ? Explain its various types

    Code in visual basic is stored in three kinds of modules viz. Class module, Form module

    and Standard module. Single Application can consist of just a single form and all of code

    in the application resides in that form module. At times as our application gets larger and

    more complex we can add more forms. Eventually we may find that there is a certaincommon code we may want to execute in several forms and at the same time we does not

    want to duplicate the code in the forms. So at that point we can create a separate modulecontaining a procedure that implements the common code . This separate module should

    be a standard module. Each Standard, Class and Form module can contain :

    Procedure : A sub , function or property procedure contains pieces of code thatcan be executed as a unit

    Declarations : We can place constants , variables , procedure declarations at the

    module level of form , class or standard module.

    Standard Module: Standard modules (.BAS filename extension) are containers forprocedures and declarations commonly used by other parts of the application. They cancontain global or module level declarations of constants, variables, external proceduresand global procedures.

    Form Modules: Form modules (.FRM filename extensions) are the foundations ofany visual basic application. They contain the textual description of a Form and its

    control including their property settings. They can contain Form level declarations of

    types, constants, variables and external procedures that handle events and generalprocedures. Form are a part of our application that are visible to users at run time.

    Class Modules: Class modules (.CLS filename extension) mark up the foundation for the

    object-oriented programming in Visual Basic. We can write code in Class modules tocreate new objects. These new classes can include their own customized properties,

    methods and events. All of the properties and methods we create can also be used by

    other object in our application.

    7) What are the various step one has to follow for managing project

    Neeraj Chopra 6

  • 8/3/2019 Vb Contents

    7/39

    Question Bank for Visual Basic

    Three main steps are used to create an application in Visual Basic are as under :

    1. Creating an Interface

    2. Setting Properties3. Coding

    Creating an InterfaceForms are the foundation for creating the interface of an application. Forms can be used

    to add windows and dialog boxes to the application. These can also be used as containers

    for items that are not part of the applications interface. For example any application canhave a from that serves as a container for graphics that is planned to display in other

    forms.

    Creating a Form

    The first step in building Visual Basic application is to create the forms that will be the

    basis of the applications interface. To start with a new project use New project command

    from File menu or click open button after selecting a project type from the first dialog

    box titled as New project whenever you start visual basic for the first time.

    Coding

    Once we add objects on the form we have to set the objects properties. We can either set

    the properties using the Properties windows at design time or use code to modify the

    properties at run time. While setting the initial properties for the form and each objects

    we can add code that executes in response to events. For example, Click is one event thatoccurs for command button being clicked.

    8) What is Coordinate System ?The coordinate system is a two dimensional grid that defines location on the screen in a

    form, or other container. We define locations on this grid using coordinates in the form :(x,y)The value x is the location of the point along the x-axis with the default location 0 tothe extreme left. The value y is the location along the y-axis with the default location of 0

    at the extreme top.The upper left corner of the screen is always (0,0). The default

    coordinate system for any container starts with the (0,0) coordinate in the upper-leftcorner of the container.

    The following rules apply to the Visual Basic Coordinate System

    When inside a picture box use the coordinate system of that control

    Statements we move or resize a control we use the coordinate system of the

    controls container. If we draw the object directly on the form, the form is thecontainer. If we draw the control inside a frame or picture box , the frame or the

    control is the container.

    All graphics and print methods use the coordinate system of the container. Forexample statements that draw that resize or move form always express the forms

    position and size in twips. When we create code to resize or move a form, we

    should first check the Height and Width properties of the Screen object to makesure the form would fit on the screen.

    Neeraj Chopra 7

  • 8/3/2019 Vb Contents

    8/39

    Question Bank for Visual Basic

    Twips

    All visual basic movement sizing and graphical drawing statements use a unit of one

    twip. A twip is 1/20 of a printers point.

    9) What is Form and explain the various properties of the form and also

    list the various events which are associated with a form

    A Visual Basic form is used to develop the user interface . It is basically a window where

    we can different elements in order to create a complete application. Every application wesee on the screen is based on some type of form. Forms have their own properties , events

    and methods which are used to control their appearance and behavior. A default form

    Form1 is add to development environment when Visual Basic starts. It applies a defaultset of properties to this form and any forms that are added to the project. The properties

    of these forms can be changed for its appearance and behavior at design time or at run

    time.

    Properties of form

    1. Border Style property: It determines how the border of a form behaves and looks.This property is used for setting form size that can be set at design time and

    cannot be changed at run time.

    Setting Description

    0-None None (No border)

    1-Fixed Single This setting that the forms cannot be resized by dragging

    2-Sizeable It is default setting for Visual Basic forms and most otherwindow applications. The form can be resized by dragging

    borders

    3-Fixed Dialog It can include control menu box and title bar4-FixedToolwindow

    It displays a nonsizeable window with a close button

    5-SizeableToolWindow

    It displays a sizeable window with a close button, but does notinclude a maximize or minimize button .

    2. Caption Property : It is a text that appears on the title bar of the form. The captioncan be set either at design time by using Caption property in the properties

    window or by writing code at run time

    3. ControlBox : The control menu is a simple menu that allows the user to restore ,move , resize , minimize , maximize and close a form. This button can be enabled

    in the form by setting the forms controlbox property in the forms propertywindow. It can set to true or false. When we set to true then also set the Borderstyle property to either 1,2 or 3 to display the control box.

    4. Font : It is used to set the font for use in the form. Whatever controls are placed

    on the form will be by default use the font set for the form. Double click-click

    font property.5. Name : In Visual Basic the name property is the most important property as it is

    the name of the control that is refers to when the program runs. The default name

    Neeraj Chopra 8

  • 8/3/2019 Vb Contents

    9/39

    Question Bank for Visual Basic

    for a new form is Form plus a unique integer. The form name property is

    prefixed by letters frm and can include numbers with an underscore.

    6. Window State : This property is responsible for how the form starts up. By settingany of the three options the display of the form can be determined.

    Options Effect

    0-Normal Opens form in the normal state1-Minimized Opens form in the minimized state

    2-Maximized Opens form in the maximized state

    Form Events

    1. Load : It occurs when the form is loaded in to memory

    2. Activate : It occurs when the form is displayed initially or when the user returns

    from one form to another form3. Deactivate : It occurs when the user moves to another form or form is hidden

    4. Unload : It occurs when the form is unloaded from memory

    5. Initialize : It occurs when an instance of the form object is created6. Terminate : It occurs when an instance of the form object is destroyed

    10) What are controls and Explain its various types in details

    Controls are objects that are placed within form objects. Command buttons, List boxes

    and Scrollbars are examples of controls. Each type of control has its own set of

    properties, methods and events suitable for a particular purpose. The controls can beadded to a form by just double clicking on the control or by drawing the selected control

    on a form by dragging the mouse around the area where we want the control to be placed.

    When a control is created, Visual Basic gives a default name indicating the type of

    control, plus a unique integer which can be changed by starting it with a letter followedby number.

    Classification of controls

    There are two types of controls in Visual Basic

    1. Standard controls: The Standard Controls also known as Intrinsic Controls are

    always available on the toolbox

    2. ActiveX controls: These are those controls which can be added later on to thetoolbox. This can be either third party controls like some of them are provided by

    Microsoft or can be user created controls.

    Standard controls

    Label

    A Label control is a graphical control we can use to display text that user cant changedirectly. It used to display static information. It displays read only text; the user cannot

    edit the text directly. The property which is set in a label control is the caption property

    Neeraj Chopra 9

  • 8/3/2019 Vb Contents

    10/39

    Question Bank for Visual Basic

    which can be set either at design time or run time. At design time we set the property by

    selecting it from the controls properties window. At run time we can set the caption

    property to provide instruction or additional help to the user.

    Commonly used Label Properties

    Name : It returns the name used in code to identify the label.

    Caption: It determines the text displayed in the label

    Alignment : Specifies how the caption will be aligned in the label. The values 0,1

    and 2 indicate left,right and center alignment

    AutoSize : It returns or sets a value that determines whether whether label is

    automatically resized to display its entire contents

    BackStyle : It returns or sets a value indicating whether a label control istransparent or opaque

    BorderStyle : It returns or sets the border style for an object . It determines

    whether a visible border appears around the label or not

    Wordwrap : It returns or sets a value indicating whether a label control with its

    Autsize property set to True expands vertically or horizontally to fit the textspecified in its caption property.

    Textbox

    To obtain fill-in-the-blank information from the user or to display information providedby the application . It can be used in conjunction with a Data Control to display

    information from a database. It is also used to set up database queries or to edit records in

    a database.

    Commonly used TextBox properties

    Name : It returns the name used in code to identify the Textbox. Borderline : The default borderstyle is 1 which provides a thin line around the

    box.

    Enabled : It returns or sets the value that determine whether or not the textbox can

    respond to user generated events.

    Maxlength : It returns or sets a value indicating whether there is a maximum

    number of characters that can be entered in the Textbox control and if so specifiesthe maximum number of characters that can be entered.

    MousePointer : It is used to change the mouse pointer shape. The default shape is

    I-beam

    Multiline : It returns or sets a value indicating whether a Textbox control canaccept and display multiple lines of text.

    PasswordChar : It is used for displaying specified character when a password is

    typed by the user.

    ScrollBars : It sets a value indicating whether the textbox has horizontal or

    vertical scroll bars.

    Text : It returns or sets the text contained in the edit area of textbox.

    Neeraj Chopra 10

  • 8/3/2019 Vb Contents

    11/39

    Question Bank for Visual Basic

    Frame Control

    A Frame control provides an identifiable group of controls. It acts as container for othercontrols typically option button or checkboxes.

    Commonly used Frame properties

    Caption : It determines the caption to the frame control

    Enabled : It determines whether a control can respond to user generated events.

    Name : It gives a name to identify the frame

    Visible : It returns or sets a value indicating whether the frame is visible or

    hidden.

    Command Button

    It used to begin , interrupt or end a process. When chosen a command button appears

    pushed in and so is sometimes called push button. One can attached an access key to acommand button by placing an ampersand (&) before a character in the caption property.

    Commonly used Command button properties

    Caption : It returns or sets the text is displayed in the command button

    Name : It returns the name used in code to identify the command button

    Value : It returns or sets a value indicating whether the button is chosen. This is

    not available at design time

    CheckBox

    It used to give the user a True/False or Yes/No option . One can use checkbox control in

    groups to display multiple choices from which the user can select one or more.

    Commonly used checkbox properties are

    Alignment : It specifies the alignment of the checkbox with respect to the caption

    Caption : It specifies the text appears besides the checkbox

    Enabled : It sets a value that specifies whether the checkbox can respond to user

    generated events

    Name : It assigns a name to identify the checkbox Value : It is used to specify the state of checkbox. The value 0 or false indicates

    that the checkbox is deselected . Value 1 or true indicates that the checkbox is

    selected.

    Option Button

    An option button control displays an option that can be turned on or offCommonly used checkbox properties are :

    Neeraj Chopra 11

  • 8/3/2019 Vb Contents

    12/39

    Question Bank for Visual Basic

    Alignment : It specifies the alignment of the option button with respect to the

    caption

    Caption : It specifies the text appears besides the option button

    Name : It assigns a name to identify the option button.

    Value : It returns the state of the option button

    ScrollBar

    A ScrollBar enables the user to select a value by positioning it at the desired location. Itrepresents the set of values. The Min and Max property represents the minimum or

    maximum value. The value property of the ScrollBar represents its current value, which

    is any integer between the minimum and maximum value. The Horizontal and Verticalscrollbar are identical as they share the same properties , events and methods.

    File System Controls

    These controls are used to add the file handling capabilities to the application. They arenormally

    DriveListBox : It normally used in conjunction with DirListConroll and filelist

    control .It used to select a drive.

    DirListBox : It is used to display file and folders of the selected drive

    FileListBox : It is used to select a file or files of select directory.

    Timer

    The timer control is one of the few controls always hidden at run time. It can execute

    code at regular interval . It has some important propertiesInterval : The interval property is measured in milliseconds and is represented bya value from 1 to 65,535

    Enabled : The enabled property determines if the timer control will invoked the

    timer event in the time specified by the interval property.

    OLE ( Object Linking and Embedding)

    Reuse is a central goal in software design . Reusing instead of rewriting code saves

    development effort. ActiveX controls are reusable software components that can quickly

    add specialized functionality to web sites, desktop applications and development tools.

    ActiveX controls are a component object model (COM) technology. It is softwarearchitecture that allows application to be built from binary software components . COM

    is the underlying architecture that forms the foundation for higher level software services,

    such as those provided by OLE a technology for transferring and sharing informationamong applications, It is based on dynamic data exchange. It gave developers the ability

    to add new interfaces to an OLE component without needing to recompile the

    components clients.

    Neeraj Chopra 12

  • 8/3/2019 Vb Contents

    13/39

    Question Bank for Visual Basic

    Common ActiveX controls

    Status Bar

    It is a control that is displayed at the bottom of application window and displaysinformation about the current state of the application. The status bar control can display

    and update certain types of information automatically. Set the style property to display

    the following :1. Keyboard status for the CAPS LOCK, NUM LOCK,INSERT, and SCROLL

    LOCK keys

    2. Time

    3. DateIt can contain text and bitmaps. We can display messages from the application in the

    status bar using the Text property

    TreeView Control

    It is used to display information within a tree hierarchy. It is made up of nodes that arerelated to each other in some way. It display a hierarchical list of nodes objects, each of

    which consist of a label and an optional bitmap. After creating a treeview we can add ,

    remove , arrange and otherwise manipulate Nodes objects by setting properties.

    ListView Control

    It displays data as ListItem objects. Each ListItem object can have an optional iconassociated with the Label of the object. The ListView property is often used in

    association with a tree view control. The ListView also has several properties which canviewed using the property window.The property page in addition to the general tab hasthe following

    1. ImageList Tab to associate to a particular ImageList

    2. Sorting Tab to display fields that expose the properties related to storing in aListView control

    3. Column Header tab using which the index field is incremented every time a

    Columnheader object is added to the List View control

    ListView control can be used

    To display the results of a query of database

    To display all the records in a table

    In association with a TreeView control to give users an expanded view of

    TreeView control node.

    Progress Bar

    Neeraj Chopra 13

  • 8/3/2019 Vb Contents

    14/39

    Question Bank for Visual Basic

    This control allow us to graphically represent the progress of a transaction. The control

    consists of a frame that is filled as the transaction occurs. The value property determines

    how much of the control has been filled. The Min and Max properties set the limits of thecontrol

    Slider Control

    It consists of a scale , defined by the Min and Max properties and a thumb which the user

    can manipulate using the mouse or arrow keys. At run time the Min and Max propertiescan be dynamically reset to reflect a new range of values. The Value property returns the

    current position of the thumb. Using the events such as the MouseDown and MouseUp

    events , the slider control can be used to graphically select a range of values. Its working

    is same like the progress bar except that the looks of the two controls are different.

    11) What are Data types ? Explain the various data types available in

    Visual Basic ?

    Data types are explanation of data stored in the variables.Visual Basic also supportsmost of the fundamental data types used in several programming languages.

    Data Type Storage size

    Byte 1 bytes

    Boolean 2 bytes

    Integer 2 bytes

    Long 4 bytes

    Single(floating point) 4 bytes

    Double(floating point) 8 bytes

    Currency 8 bytes

    Decimal 14bytesDate 8 bytes

    Object 4 bytes

    String (variable length) 10 bytes + string length

    String (Fixed length) Length of string

    Variant 16 bytes

    User Defined Number required by elements

    Byte Data type

    Byte variables are stored as single , unsigned 8-bit numbers ranging in value 0-255. The

    byte data type is useful for containing binary data

    Boolean Data type

    Boolean variables are stored as 16-bit numbers but they can only be true or false.

    Example :

    Dim x as Boolean

    Neeraj Chopra 14

  • 8/3/2019 Vb Contents

    15/39

    Question Bank for Visual Basic

    x=true

    Numeric Data type

    The following data types are used for storing numeric values depending on data storage

    requirements

    Whole numbers Integer or longFraction-Single, Double or Currency

    Example :

    Dim age as integer

    Dim ID as long

    Dim sum as singleDim price as currency

    Date Data TypeData variable are stored as 64-bit floating point numbers. They represents dates ranging

    from 1 january 100 to 31 December 9999 and times 0:00:00 to 23:59:59.

    Dim mydate as Date

    String Data Type

    To store any text in a variable one can declare the variable as string data type. There are

    two kinds of strings variable length and fixed length strings.

    A variable length strings can contain upto 2 billion charactersA fixed length strings can contain 64K characters.

    Dim name as string

    Variant Data Type

    The variant data type is the data type for all variables that are not explicitly declared assome other type. The variant data type has no type declaration characters.

    Dim avar

    Object Data Type

    Object variables are stored an 32 bit addresses that refers to objects. Using the set

    statement a variable declared as an Object can have any object reference assigned to it. Avariable declared as Object can be assigned to any object recognized by the application.

    12) What are variables ? Explain the variable naming convention ?While performing calculations one may need to store values temporarily . One may also

    need to store the values calculated by more than one method and then have to compare

    the values. Variables are used to store values like numbers, strings and dates.A variable is

    Neeraj Chopra 15

  • 8/3/2019 Vb Contents

    16/39

    Question Bank for Visual Basic

    a named temporary storage location. A variable is capable of containing a certain type of

    data that can be modified during program execution.

    Variable naming convention

    Must begin with a letter

    Cannot contain an embedded period

    Cannot exceed 255 characters.

    A variable has a variable name by which it is referred to and can store a value into it. For

    example there is variable name Radius to store a value in it as

    Dim Radius as floatRadius=4.5

    A variable has to be created first only then one can use it

    Empty variables

    If a variable has been declared but not value is assigned to it , it is said to empty variables

    Static Statements

    Variables declared with the static statement retain their values as long as the code is

    running

    Public Statement

    Used at module level to declare public variables and allocate storage space. Variable

    declared using the Public statement are available to all procedures in all modules in allapplication

    Private StatementUsed at module level to declare private variables and allocate storage space. Privatevariables are available only to the module in which they are declared.

    Scope of Variable

    The scope of variables refers to the accessibility or visibility with in the project. The level

    at which the variable is declared determines the accessibility of a variable.

    It is important for variables used with in procedures :

    Procedure level variables are recognized only in the procedure in which they are

    declared Local variables declared with static statement exist as long as the code is running

    while the variable declared with Dim statement exist only as long as the

    procedure in the module but is not available to code in other modules.

    A module level variable is available to all procedures in the module but is not

    available to code in other module

    If public variables in different modules share the same name, it is possible todifferentiate between them in code. For example if integer variable Myint is

    Neeraj Chopra 16

  • 8/3/2019 Vb Contents

    17/39

    Question Bank for Visual Basic

    declared in Form1 and Module1 one can refer to it as Module1.Myint and

    Form1.Myint

    Converting Variable Types

    Visual Basic provides certain conversion functions one can used to convert values from

    one datatype to another.Function Description

    Asc Returns the character code corresponding to the first letter in a

    string

    Chr Returns the character associated with the specified character code

    Cbool Converts an expression to a Boolean

    Cbyte Converts an expression to a Byte

    Ccur Converts an expression to a currency

    Cdate Converts an expression to a date

    Cdbl Converts an expression to double

    Cint Converts an expression to int

    CLng Converts an expression to longCSng Converts an expression to string

    CStr Converts an expression to string

    Cvar Converts an expression to variant

    13) Write Short note on User Defined Data type

    Any data type one define using the Type statement is called user defined datatype. User-defined data types can contain one or more elements of a datatype.

    Declaring a userdefined datatpye

    Type StudenttypeRollno as string

    Name as string

    Class as stringTmarks as integer

    End type

    Now declare variable of the user defined datatype

    Dim student1 as studenttype

    Storing values in user define datatype

    Student1.rollno=A45

    Student1.name=RahulStudent1.class=BBA(CAM)

    Student1.tmarks=345

    14) What is Constant ?

    Neeraj Chopra 17

  • 8/3/2019 Vb Contents

    18/39

    Question Bank for Visual Basic

    A constant is meaningful name that takes the place of a number or string that does not

    change. A constants value cannot be changed.

    For exampleConst pi=3.14

    What is an operator ? Explain the various types of operators available

    in Visual Basic with the help of an example ?

    Operators are special symbols or words used to describe an operation or an action which

    is to take place between two or more or among more than two values.Operators are available in Visual Basic for performing arithmetic,comparison and logical

    operations.

    The different categories of operators in Visual Basic are

    Arithmetic operator

    Comparison operator

    Logical operator Concatenation operator

    Arithmetic operators

    These operators are used to perform mathematical operations on two numbers or numericexpression. The list of the arithmetic operators are

    +,-,*,/,Mod

    Comparison Operator

    The comparison operators are used to compare expression. They compare expressionsand return a Boolean value.

    Operator Description

    > Greater than

    < Less than

    >= Greater than equals to

  • 8/3/2019 Vb Contents

    19/39

    Question Bank for Visual Basic

    *:for matching more than one characters in string

    Program of Like operator

    Private Sub Command1_Click()Dim x As String

    x = "hello"

    Dim yy = x Like "m*"

    MsgBox y

    End Sub

    IS Operator

    It is used to compare two object reference variables and returns two if both the objectsnames refers to the same object.

    Syntax result = object1 is object 2

    Program of IS operator

    Private Sub Command1_Click()Dim x As CommandButton

    Dim y As CommandButton

    Dim z

    z = x Is yMsgBox z

    End Sub

    Logical operator

    Logical operator are used to combine conditions and returns a Boolean value. Commonly

    used logical operator are AND,OR and NOT

    Private Sub Command1_Click()

    Dim a, b, c As IntegerDim d

    a = 10: b = 8: c = 6

    d = a > b And b > c

    MsgBox dd = a > b Or b > c

    MsgBox d

    d = Not (a > b)MsgBox d

    End Sub

    Concatenation operators

    These are used to join to expression

    Neeraj Chopra 19

  • 8/3/2019 Vb Contents

    20/39

    Question Bank for Visual Basic

    Private Sub Command1_Click()

    MsgBox "hello" & "Visual Basic"

    End Sub

    15) What is Loop Statements ? Explain the various types of Loop

    statementsLoop structures of Visual Basic are used for iteratively performing a statement /

    statement block. They are used when a group of statements have to be executed

    repeatedly based on a condition.

    FOR.LOOP

    This is used when the repetition is to be done for a certain number of times and a countermay be used.

    Private Sub Command1_Click()

    Dim i As Integer

    For i = 1 To 10MsgBox "i=" & i

    Next iEnd Sub

    Another Example of FOR LOOP

    Private Sub Command1_Click()

    Dim i As Integer

    For i = 1 To 10 step 2

    MsgBox "i=" & iNext i

    End Sub

    DO While Loop

    This loop test the condition first and if true executes the statement which are given in the

    loopPrivate Sub Command1_Click()

    Dim i As Integer

    i = 1Do While i

  • 8/3/2019 Vb Contents

    21/39

    Question Bank for Visual Basic

    While i 10

    MsgBox "i= " & ii = i + 1

    Loop

    End Sub

    16) What is an Array ? Explain with the help of an example ?

    An array is a contigous area in memory referred to by a common name. All elements in

    an array have the same data type. The size of the array is a specified at the time of

    definition of the array. An array allows us to set variables by the same name and anumber to tell them apart. The memory occupied by the data can be calculated by

    multiplying the number of data elements by the size of each elements.

    Syntax : Dim x(5) as integer

    Private Sub Command1_Click()

    Dim x(5) As IntegerFor i = 0 To 4x(i) = InputBox("Enter value")

    Next i

    For i = 0 To 4MsgBox (x(i))

    Next i

    End Sub

    Dynamic Arrays

    A dynamic arrays can be resized at any time. It is possible to change the size of array at

    run time using ReDim statement. If you create a dynamic array. A dynamic array can becreated by giving an empty dimension list.

    For example

    Dim x() as integerRedim x(5)

    Example of Dynamic Arrays

    Private Sub Command1_Click()

    Neeraj Chopra 21

  • 8/3/2019 Vb Contents

    22/39

    Question Bank for Visual Basic

    Dim x() As Integer

    Dim i As Integer

    i = InputBox("Enter the size")ReDim x(i)

    For a = 1 To i

    x(a) = InputBox("enter the number")Next a

    For a = 1 To i

    MsgBox (x(a))Next a

    End Sub

    17) Difference between an Event and General Procedure

    In Visual Basic event procedures are invoked in response to keyboard , mouse or system

    action. Our code can also explicitly invoke event procedures. The maximum number of

    events a control can have is fixed . Event procedures are stored in a form module and areprivate by default.

    A general procedure is not executed unless explicitly invoked. One can create a general

    procedure either by choosing the procedure from the insert menu or by typing the

    procedure heading Sub followed by the procedure name on a blank line.

    18) What is an Event ? Explain the Event Driven programming model ?

    Explain the various types of events?

    Events : Events are the actions recognized by a form or control. Events occur a user,

    operating system or application interacts with the objects of a program. Any actionperformed by pressing a key one the keyboard or clicking a mouse for which code can bewritten is an event procedure that runs whenever the event occurs as a result of the user

    actions or program code, or they can be triggered by the system. Depending on the event

    the corresponding procedure is executed but some events recognized by one object mightnot be the same as recognized by other objects.

    Event Driven Programming : When a program is event driven its code is executed inresponse to events invoked by the user, operating system or application. This differs from

    procedural programming where the program starts at the first line of code and follows a

    defined pathway calling procedures as needed. In traditional or procedural applications

    the application itself determines which portion of code is to be executed and in whatsequence. Execution starts with the first line of code and follows the coding sequence

    defined in the application. At times controls are transferred to other parts of the program

    through statements and procedures. Whereas application written in Visual Basic are eventdriven. In an event driven application the code does not follow a predetermined path it

    executes different code sections in response to events. Events can be triggered itself by

    the user actions, by messages from the system or other application or even from the

    Neeraj Chopra 22

  • 8/3/2019 Vb Contents

    23/39

    Question Bank for Visual Basic

    application itself. The sequence of these events determine the order in which the code

    executes thus the path differs each time the program runs.

    Event Driven Programming Model

    1. The application starts and a from is loaded and displayed2. The form receives and event. The event would have been caused by the user

    called as user initiated events. The event would have been caused by the system

    itself is called system initiated events3. If there is code in the corresponding event procedure it executed

    4. The application waits for the next event

    Types of events

    In Visual Basic program basically two types of events can occur :

    1. User Initiated Events: These are those that occur in response of an action takenby the user. It includes keystrokes and mouse clicks but other events are also

    carried out by the user, either directly or indirectly. For example when the userclicks on aTextbox to start editing the information on the Textbox the click event

    is fired to the textbox. Along with it several other events are also fired such as

    GotFocus which occurs every time the user moves to the textbox either by

    clicking the mouse or using the Tab key. Similarly when the textbox gets the programs focus another control must lose the focus. This action causes a

    LostFocus event to fire another control. The GotFocus and LostFocus events are

    caused by the users action just as the Click event.2. System Initiated Events: Even though we design and code the programs with

    utmost care, run time errors can always occur in our program. A run time error

    occur when the user tries to open a file when the file does not exists or when hetries to read a from the disk without inserting a disk in the floppy drive. These

    error generates an event and these handled by operating system. The events which

    are caused by the system itself are known as System initiated events.

    19) What is an object ? Why do we require them ? Explain in detail ?

    When we create an application in Visual Basic we work with objects. We can use objects

    provided by Visual Basic Such as controls, forms and data access objects. We can also

    control other applications objects within our visual basic application. We can even createour own objects and define additional properties and methods for them.

    An object is a combination of code and data that can be treated as a unit. An object canbe a piece of an application like a control or a form. An entire application can also be an

    object. Software objects are often used to model real world objects we find in everyday

    life. As the name implies Objects are key concept in understanding object orientedtechnology. We can look around ourself and see many examples of real world objects :

    Neeraj Chopra 23

  • 8/3/2019 Vb Contents

    24/39

    Question Bank for Visual Basic

    dog , lion etc. These real world objects share two characteristics : they all have a state and

    they all have a behavior. For example dog have state (name, color, breed) and behavior

    (barking and fetching) . Software objects are modeled after real world objects in that theytoo have state and behavior. A software object maintains its state in variables and

    implements its behavior with methods. The following table describes examples of the

    types of objects we can use in Visual Basic :

    Example Description

    Command Button Controls on a form such as command button and frames are

    object

    Form Each form in a Visual Basic project is a separate object

    DataBase Database objects are objects and contain other objects likefields and indexes

    Chart A Chart in Microsoft Excel is an object.

    Each object in Visual Basic is defined by a class. For example The controls on the Toolbox in Visual Basic represents classes. The objects

    known as control doesnt exist until we draw it on a form. When we create acontrol we are creating a copy or instance of the control class. That instance of the

    class is the object we refer to in our application.

    The form we work with at design time is a class. At run time Visual Basic createsan instance of the forms class.

    An object provides code we dont have to write. For example we could create our

    own File Open and File Save dialog boxes. Instead we can use the common dialogcontrol provided by Visual Basic. We could write our own scheduling and

    resource management code. We can use the Calender , Resources and Task

    objects provided by Microsoft Project. Visual Basic provides the tools to allow us to combine objects from different

    sources. We can now build custom solutions combining the most powerful

    features of Visual Basic and applications that support Automation. Automations is

    a feature of the Component Object Model (COM) an industry standard used byapplications to expose objects to development tools and other applications.

    20) What is a Class ? Explain the Various features of OOPS

    A class is a blueprint or prototype that defines the variables and the methods common to

    all objects of a certain kind. In the real world we often have many objects of the same

    kind. For examples our car is really just one of the many cars in the real world. Usingobject oriented terminology we say that our car object is an instance of the class of

    objects known as cars. All cars have some state and behavior. However each cars state is

    independent of and can be different from other cars. While producing cars ,manufacturers take advantage of the fact that cars share characteristics and they build

    many cars from the same blueprint it would be inefficient to produce a new blueprint for

    every individual car manufactured.

    Neeraj Chopra 24

  • 8/3/2019 Vb Contents

    25/39

    Question Bank for Visual Basic

    Features of OOPS

    1. Abstraction : It is the process of selecting essential features of an entity thatdescribe it completely. Humans manage complexity through abstraction. For

    example people do not think of a car as a set of thousands of individual parts.

    They think of it as a well defined objects with its own unique behavior. Thisabstraction allows people to drive the car without being overwhelmed by the

    complexity of the parts that form the car. The can ignore the details of how the

    engine , transmission and braking system works. Instead they are free to utilizethe object as a whole.

    2. Encapsulation : This refers to the fact that objects hide the details of how they

    internally work. For example when we set the Text property of a toolbox, we as a

    user do not know how the textbox internally repaints the characters. This can alsobe termed as information hiding.

    3. Inheritance It is the idea that a class can gain the pre-existing interface and

    behavior of an existing class. This is done by inheriting these behaviors from the

    existing class through a process known as sub classing. The class from whichanother class is derived is the super class and the class that inherits the code from

    the super class is known as sub class.4. Polymorphism : It is the ability to write one procedure that can operate on objects

    from more than one class treating different objects from different classes in

    exactly the same way. For example an operation may exhibit different behavior in

    different instances. The behavior depends upon the types of data used in theoperation. For example consider the operation of addition. For two numbers the

    operation will generate a sum . If the operands were strings then the operation will

    be concatenation.

    21) What is an API ? Explain them in detail

    An API is simply a set of functions available to an application programming. This term is

    most often used to describe a set of function that are a part of one application but are

    being accessed by another application. When a Visual Basic program uses OLEautomation to execute an Excel spreadsheet function we can say that is accessing the

    Excel API. API is one of those acronyms that seems to be used primarily to scare people.

    The DOS interrupt function can technically be considered the DOS APT. The Windows

    API refers to the set functions that are a part of windows and are accessible to anyWindows application. When we consider that the windows API has literally thousands of

    functions. From the point of view of Visual Basic programmer , the windows API

    functions can divided into four categories1. API functions that correspond to VB feature : Many API functions are already

    built into VB so that there is no need to access them via the Declare statement.

    2. API function that cannot be used from VB : There are number of API functionsthat simply cannot be accessed from VB. In most cases this is because they

    require parameters that incompatible with VB

    3. API functions that are useful for VB programmers

    Neeraj Chopra 25

  • 8/3/2019 Vb Contents

    26/39

    Question Bank for Visual Basic

    4. API functions that cannot be directly called from VB but can be accessed through

    a simple interface that performs certain parameters conversions or allows access

    to information that cannot be obtained directly

    22) What are Dynamic Link Libraries (DLL) ? What are the benefits ofusing DLL?

    When we need capabilities that do beyond the core language and controls provided withVB we could make direct calls to procedures contained in DLLs. By calling procedures

    in DLLs we can access the thousands of procedures that form the backbone of Microsoft

    Windows operating system as well as routines written in other languages.

    As their name suggests, DLLs are libraries of procedures that applications can link to and

    use at run time rather that link to statically at compile time. This means that the libraries

    can be updated independently of the application and many applications can share a single

    DLL. Microsoft windows itself is comprised of DLLs, and other applications call theprocedures within these libraries to display windows and graphics, manage memory or

    perform other tasks. These procedures are sometimes also referred to as the WindowsAPIs or application programming interfaces.

    Benefits of DLLs

    1. Accomplish tasks not available in VB DLLs can perform tasks that are not

    possible in VB directly. For example we can invoke a DLL procedure that causes

    our application to remain the topmost window.2. Improve performance -- DLLs execute much faster than VB code. If we have a

    procedure that requires maximum performance, we can write a DLL procedureand then invoke the DLL from VB

    3. Get Update independently of the application DLLs can be updated without

    recompiling the application that invoked the DLL. This provides greater

    modularity and application maintenance.

    23) What are Dialog Boxes ? Explain it ?

    Dialog boxes are used to display information for the user or to prompt the user for typing

    appropriate data. The easiest way to add a dialog box to application is to use a predefined

    dialog because we dont have worry about designing , loading or showing the dialog box.

    However our control over its appearance is limited. Predefined dialog boxes are alwaysmodal which they must be closed before we can continue working with the rest of

    applications. MsgBox and InputBox are the functions used for creating such dialog

    boxes.

    24) Differentiate between MsgBox and InputBox ?

    Neeraj Chopra 26

  • 8/3/2019 Vb Contents

    27/39

    Question Bank for Visual Basic

    Message Box displays a message in a dialog box waits for the user to click a button and

    returns an integer indicating which button the user clicked. We can use the MsgBox

    function to get Yes or No responses from users and to brief messages such as errors,warnings or alerts in a dialog box. After reading the message the user chooses a button to

    close the dialog box.

    Syntax :

    Msbox (prompt,[button][,title])

    Prompt Required : Sting Expression displayed as the message in the dialog box. The

    maximum length is approximately 1024 characters depending on the width of the

    characters used.Button (optional) : Numeric expression that is the sum of values specifying the number

    and type of buttons to display , the icon style to use , the identify of the default button and

    the modality of the message box. If omitted the default value for buttons is 0.

    Title (optional) : String expression displayed in the title bar of the dialog box. If we omittitle the application name is placed in the title bar.

    InputBox : 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 :

    InputBox (prompt[,title])

    Prompt Required : String expression displayed as the message in the dialog box. The

    maximum length of prompt approximately 1024 characters depending on the width of the

    characters used.

    Title (Optional) : String expression displayed in the title bar of the dialog box. If we omit

    title the application name is placed in the title bar.

    25) What are menus ? Explain the various types of Menus ?

    Visual Basic provides a feature that increases the functionality of an application byadding the menu bar. Once these menus are created they can be individually programmed

    to respond when selected. Another type of menu that has become popular with users is

    the pop-up menu. This menu can be very specific to certain control areas of theapplication . Pop-up menu is also referred to as context sensitive menus.

    Menu bars are used in applications to provide an organized collections of commands thatcan be used by the user. In visual basic there are two different methods to create menus-

    first is the built in menu editor dialog box. It provides an easy and simple way to generate

    menus. Once created all menu objects can set their properties through the program code.Another method used to create menus in Visual Basic involves using the Win32

    Neeraj Chopra 27

  • 8/3/2019 Vb Contents

    28/39

    Question Bank for Visual Basic

    application programming interface. The win32 API is a series of functions that are

    extremely called by Visual Basic and are provided by the operating system.

    Types of Menus

    Drop Down Menus

    The menu that have a single level menu.

    Nested Menus

    The nested menus can be created the way we have created normal menus by simply

    adding new to the list and shifting them to the right of the one we want them to be nested.

    Pop Menus

    These are also context menus and it provides the user another way to control theapplication. In Excel the user has the option to use the main menu bar or shortcut keys or

    pop-up menus. These menus are created as part of the main menu system but they arevisible only when they are needed and invoked through program code.

    Properties of Menus

    Property Description

    Caption The text of the menu that the user will see

    Name The name that we will use in our code to refer to this menu and toidentify the event code for each menu item

    Index Used to from menu control arraysShortcut The menu can be invoked either by clicking it with the mouse in a

    normal way or by pressing the short cut key.

    Visible Clicking the check box to set this property to true causes the menu

    item to be visible at run time

    Enabled If this is clicked or set to true , then the user can select the menu

    item setting it to false by clearing the check box causes the menu

    item to appear the grayed out meaning the user cant select it

    26) What are Errors ? Explain its types.?

    Even though we design and code the programs with utmost care run time errors canalways occur in our program. A run time errors can occur when the user tries to open afile when the file does not exist or when we tries to read from the disk without inserting

    a disk in the floppy drive. Visual Basic does not handle errors automatically . It simply

    notifies our program of the error. A good programmer will always handle the error in the

    code to provide understandable information to the user , allow the user to correct a valuea value and retry an operation or exit the program.

    Neeraj Chopra 28

  • 8/3/2019 Vb Contents

    29/39

    Question Bank for Visual Basic

    When our code and run the programs, we might encounter three types of errors :

    Syntax Errors: When code is constructed incorrectly Syntax error occurs. An incorrectlytyped keyword, omission of required punctuation or an incorrect construct such as Next

    statement without a corresponding For statement.

    Run Time Errors: A run time error occurs at the time of running a program. Forexample if the program tires to open a file that does not exist or the user forgets to put a

    floppy disk in the floppy disk drive. If a run time error occurs and the program contains

    code for handling that error. Visual Basic displays a message and lets us enter the debugmode or Help or end the application.

    Logical Errors: It usually occurs when an application does not perform the way it

    should. It may contain syntactically valid code. Finding logical errors is especiallydifficult . The programmer needs to verify and analyze the results to trap the logical

    errors.

    27) What is Debugging ?No matter how carefully a programmer designs and codes application, the programs aresure to have a few errors. These errors are generally detected when the program is tested.Debugging basically means finding and removing errors from the programs. These errors

    in the program can be in their syntax or logic. Visual Basic not only assists us in tracing

    what is happening in the application while it is running, it also helps in diagnosing theprogram errors as you write through its automatic syntax checker and various other tools

    which help in remembering the keywords and syntax as you type in the code.

    28) What is Visual Database Architecture ?

    A Visual Database application consists of three components :1. User Interface and Application code-it is the part what the user interacts with. It

    contains forms that display the data enable the user to view or update it

    2. Database Engine-This part is contained in a set of Dynamic Link Library files and

    is linked to our Visual Basic program at run time. The engine is responsible forreading and modifying the database. Data store is the file or files containing the

    database tables. A database application can be categorized into two types :

    Client Server is a system which both the database engine and the datastore are located on a central server. Multiple client applications can

    simultaneously request the services of the engine. The engine can access

    the data store and return the requested records to local application.

    Remote is a system in which database engine resides on the samecomputer as the user application while the data store is located on a

    remote machine.

    3. Programmatically, using Visual Basic Data Access Object (DAO) Creatingdatabase programmatically using Data Access objects gives our program

    complete control how the database is created and structured.

    Neeraj Chopra 29

  • 8/3/2019 Vb Contents

    30/39

    Question Bank for Visual Basic

    4. Using the Visual Data Manager application provided with Visual Basic Using

    this Visual Basic add-in one can create databases, as well as create , modify and

    delete tables , indexes and relations with a database.5. Using Microsoft Access This tool is probably the most widely used to create Jet

    databases. It provides the added advantage of enabling us to create queries and

    relations using a Visual drag and drop interface6. Using the Third party database management programs Many other programs ,

    both commercial and shareware are available to manage Jet and other types of

    database. Some are highly specialized where as others general purpose ultimatelike Visual Data manager.

    29) What is Data Manager ?

    The Data manager is Visual application included with Visual Basic that we can use to

    create a Jet Database. Once the database is created, we can manipulate it using data

    controls and data access objects.

    30) What is Data control ? Define Tables, Fields, records.

    The data control provides a relation interface to database files, Basically a relational

    database is one that stores data of tables made up of columns and rows of data. In Visual

    Basic columns are referred to as fields and rows are referred to as records. The MicrosoftJet Database engine that powers the data control view all database as a set of relational

    tables, regardless of their physical file format. This means that when we use data from

    external databases (Such as Foxpro and Oracle), we can use the same relational terms.

    Tables : A table is a logical grouping of related information arranged in rows and

    columns similar to a spreadsheet table. For example a table might contain a list ofinformation about authors such as their names, date of birth, addresses etc.

    Fields : Each column in a database table is called a field. Tables are defined by

    the fields they contain with each field describing the data it is to hold. When

    creating a database we assign a data type, maximum length and other attributes toeach field. Fields can contain characters , numbers or even graphics.

    Records : It is a collection of fields

    31) What is Structured Query Language ?

    Once the data is stored in the database , retrieving it is made easier by using an Englishlike language called Structured Query Language (SQL). It has evolved into the most

    widely accepted means to converse with a database. Basically the user asks a question

    in the SQL language, this question is called a query. The database engine answers byreturning any database rows that meet the requirements of the query. The query usually

    contains the names of the tables to search, the names of the columns to return and other

    information that sets the scope of the search.

    Neeraj Chopra 30

  • 8/3/2019 Vb Contents

    31/39

    Question Bank for Visual Basic

    32) What is Data control ? Explain the concept of Databases in details ?

    What the user can perform with the help of data control ?All business applications need to store large volumes of data organized in a format so thatinformation can be retrieved efficiently and quickly as and when required. With the help

    of a DBMS (Database Management System) managing data becomes easy. A DBMS is a

    system that manages the storage and retrieval of data in a database. It helps theprogrammer in concentrating on managing information. Microsoft Visual Basic provides

    tools for creating and accessing a variety of Relational Database Management System

    (RDBMS). An RDBMS stores and retrieve information according to a set of definedrelationships. In an RDBMS the database is the container of tables in which all data is

    stored and the relationships are formed by data values.

    A database is a collection of data that are related to one another to support a commonapplication. Employee details, Names and addresses- each of these collections of data

    constitutes a database. In a database data is organized and stored in a table comprising of

    rows and columns. Rows in a table are called records and columns are called fields. Each

    record in a table has a unique key field that identifies it and are used to link with other

    tables. This key field is termed as Primary key. The primary key of a table is added as afield in another table to establish the relationship between the two tables and it becomes a

    Foreign Key in the second table. For example employee records have employee numberand department record have department number both in employee table and in the

    department table. In the employee table the primary key is employee number and foreign

    key is deptno.

    The Data control can perform the following task without the use of code :

    Connect to a local or remote database

    Open a specified database table or define a set of records based on Structured

    Query Language (SQL) query of the tables in that database.

    Pass data fields to bound controls, where we can display of change the values Add new records or update a database based on any changes we can make to data

    displayed in the bound controls.

    Trap errors that occur as data is accessed

    Close the database.

    33) What are the Various categories of accessing database is available in

    Visual Basic ?

    Visual Basic can access three categories of databases:

    1. Jet Databases: Databases are created and manipulated directly by the Jet engine.The Jet engine is the data manager component of Microsoft Access and Visual

    Basic

    2. ODBC (Open Database Connectivity ): Visual Basic also allows access to adatabase on a Network. These include client server databases that conform to the

    ODBC standard such as oracle. Most databases that support ODBC can be

    accessed.

    Neeraj Chopra 31

  • 8/3/2019 Vb Contents

    32/39

    Question Bank for Visual Basic

    3. Indexed Sequential Access Method (ISAM) Databases: ISAM databases include

    dbase, Microsoft Visual Foxpro and Paradox.

    34) What is Data Access Object Model ? Explain in detail

    The Data Access Object Model is an object oriented interface to the Jet database engine.The DAO model is a collection of object classes that corresponds to the structure of a

    relational database system. Each of these classes provides properties and methods that

    allow us to perform like creating databases, defining tables, fields and indexes andestablishing relations between tables, querying the database. At the top of the hierarchy is

    the DBEngine object that represents the Microsoft Jet Database engine. The DBEngine

    object contains and controls all other objects in the hierarchy of data access objects. It has

    a collection called workspaces, which contain one or more workspace objects. TheWorkspace object defines a session for the user. In a session one can open multiple

    databases, managing transactions and establish a security level. By default the Jet engine

    creates a Workspace object DBEngineWorkSpace(0) Additional workspace objects can

    be created if required . Each workspace has a user ID and a password associated with it.Each workspace has a database collection contains one or ore Database objects. Each

    database object has TableDefs collection which contain one or more TableDef object andso on.

    35) What is Recordset ? Explain the various types of Recordset.

    Recordset is an object that contains a set of records from the database. Using a Recordset

    object one can programmatically manipulate the data in a database. There are three types

    of Recordset objects

    1. Tables type Recordset: The table type Recordset object is a set of records thatrepresents a single table that represents a single table that can use to add, changeor delete records. One cannot create a table-type Recordset on an attached table.

    An attached table is another table in another database. Some operations such as

    indexing and using the seek method are only allowed on a table type Recordset.Table are the fastest type of Recordsets.

    2. Dynaset type Recordset: The dynaset-type recordset object is a set records that

    represents or attached tables or the results of queries containing fields from one ormore tables. A dynaset contains keys to the underlying tables. A dynaset enables

    us to extract and update data from more than one table.

    3. Snapshot-type Recordset: This object is a fixed set of records that one can use to

    find data or generate reports. A snapshot type Recordset can refer to any table,attached table or query. A snapshot cannot be updated and does not reflect

    changes to data made by other users.

    36) Explain the Data Access methodology in context to Visual Basic ?

    Today companies building database solutions face a number of challenges as they seek togain maximum business advantage from the data and information distributed throughout

    Neeraj Chopra 32

  • 8/3/2019 Vb Contents

    33/39

    Question Bank for Visual Basic

    their corporations. Universal Data Access provides high performance access to a variety

    of information sources, including relational and non relational and an easy to use

    programming interface that is tool and language independent. These technologies enablecorporations to integrate diverse data sources, create easy to maintain solutions and use

    their choice of best of breed tools, applications and platform services. Universal Data

    Access is based on open industry specifications with broad industry support and workswith all major established database platforms.

    Universal Database Access Architecture (UDA)

    The strategy of UDA is to enable developers to access diverse types of data, from both

    relational and non relational data sources. Non relational data sources are data such as

    email , Internet explorer and file systems.

    The UDA architecture consists of three kinds of database components : Providers ,

    Services and Consumers

    Data Providers:

    Data providers are components that represent data sources such as SQL databases,

    indexed sequential files and spreadsheets. ActiveX Data objects uses general OLE DB

    providers to access unique features of specific data sources. It also uses native OLE DB

    providers including a specific OLE DB provider that provides access to Open DatabaseConnectivity drivers

    Service Components:

    These components provide an interface between the Data providers and Data consumers.

    The service components process the data and transmit OLE DB data to data consumers.They consist of Cursor Engine and Query Proceessor

    Data Consumers:

    The Data consumers can be an application written in Visual Basic or VC++ or Java

    which can consume OLE DB data. For example an application written in Visual Basic

    that displays the data after retrieving it using ADO is a data member.

    37) What are various components of Microsoft Data Access?

    The Microsoft Data Access Components is the practical implementation of UniversalData Access

    1. ODBC: Open Database Connectivity is a widely used accepted applicationprogramming interface (API) for database access and it uses Structured Query

    Language (SQL) as its database access language.

    Neeraj Chopra 33

  • 8/3/2019 Vb Contents

    34/39

    Question Bank for Visual Basic

    2. OLEDB: OLEDB is a set of interfaces for efficient access to Microsoft and third

    party data stores. It provides an open standard for accessing and manipulating all

    types of data.

    38) What are ActiveX Data Object ? Explain in Detail

    ADO is Microsofts strategic high level interface to all kinds of data. ADO provides

    consistent , high performance access to data, whether we are creating a front end database

    client or middle tier business object using an application, tool , language or even anInternet browser. ADO is the single data interface we need to know 1-to n-tier client

    server and web based data driven solution development.

    Neeraj Chopra 34

  • 8/3/2019 Vb Contents

    35/39

    Question Bank for Visual Basic

    Remote Data Services

    It is a feature of ADO. RDS delivers a new Web data access technology that allows

    developers to create data-centric applications within ActiveX-enabled browsers such asMicrosoft Internet explorer. It is a service used to transport ADO recordsets from a server

    to a client computer. The resulting recordset is cached on the client computer and

    disconnected from the server.

    The future of data access is ADO. Its goal is to supersede the Data Access Object

    (DAO), and Remote Data Object (RDO) models by providing flat and easy to learnobject hierarchy that is similar to the other objects used in DAO and RDO.

    The ADO model is flat and small unlike other programmable object models, which rely

    on the hierarchy to provide order and structure. The ADO object model consists of sevenobject and four collections, each of which has very specific role relating to the

    functionality of the service provider.

    39) What is an ADO object and Explain it in detail?

    ADO object comprises of the following objects:

    Connection Object: A connection object is used to establish a connection to a data source

    based on the information that includes the connect string, username and password, cursortype and location , time-out values etc.

    Command Object: A command object adds, deletes or updates data in the data source or

    retrieves data. It stores information about a SQL command or reference to a stored

    procedure. Parameterized commands are also available that allow the values in the queryto be changed at runtime

    Recordset object: A Recordset object represents the entire set of records from a base tableon the result of an executed command. At any time the Recordset object refers to only asingle record within the set as the current record. All the recordset objects are constructed

    using records and fields . When we use ADO, we manipulate data almost entirely using

    recordset objects.The Recordset is the primary means of examining and modifying data in the rows. The

    Recordset object allows us to:

    1. Specify which rows are available for examination

    2. Traverse the rows3. Specify the order in which the rows may be traversed

    4. Add, change or delete rows

    5. Update the data source with changed rows6. Manage the overall state of the Recordset.

    40) Write short notes ADO Collection and ADO Events

    ADO Collection: ADO provides collections, a type of object that contains other objects

    of a particular type. The objects in the collection can be retrieved with a collection

    Neeraj Chopra 35

  • 8/3/2019 Vb Contents

    36/39

    Question Bank for Visual Basic

    method either by name, as a text string, or by ordinal as an integer. ADO provides four

    types of collections:

    1. Errors Collection: The collection object has the Errors collection which containsall Error objects created in response to a single failure involving the data source.

    It contains all of the extended information about the error that is available from

    the OLE DB service provider. Any operation involving ADO objects can generateone or more errors. As each errors occurs one or more error objects can be placed

    in the Error collection of connection object. When another ADO operation

    generates an error, the Errors collection is cleared and the new set of Error objectscan be placed in the Errors collection.

    2. Parameters Collection: The Command object has the Parameters collection

    which contains all Parameters objects that apply to that command object. Often

    commands require variables parts parameters that can be altered before we issuethe command.

    3. Fields Collection: A row of Recordset consists of one or more fields. If we vision

    the Recordset as two dimensional grid, the fields line up to form columns. Each

    field has among its attributes a name, a data type and a value. It is this value thatcontains the actual data from the data source. A Field is also one of the objects in

    the object model.4. Properties collection: A properties collection contains all the property objects for

    a specific instance of an object.

    ADO Events: ADO 2.0 introduces the concept of events to the programming model.Events are notifications issued by certain operations that an operation is about to occur,

    or has already occurred. An event is actually a call to an event handler routine that we

    define in our application. Event handlers called before the operation starts offer you theopportunity to examine or modify the operation parameters then either cancel or allow

    the operation to complete. Event handlers called after an operation completes notify you

    at the completion of an asynchronous operation.

    41) Difference between DAO, RDO and ADO objects

    DAO RDO ADO

    DBEngine RdoEngine -

    Workspace rdoEnvironment -

    Database (Connection for

    ODBCDirect workspace)

    rdoConnection Connection

    TableDef rdoTable -

    QueryDef rdoQuery CommandRelation - -

    Recordset rdoResultSet Recordset

    Field rdoColumn Field

    Neeraj Chopra 36

  • 8/3/2019 Vb Contents

    37/39

    Question Bank for Visual Basic

    42) What is an Array ? Explain its various types ?

    Arrays are used to refer to a serie