Sie sind auf Seite 1von 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 a complete 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 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 prebuilt into 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 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 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 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 ActiveX and Internet controls. 3. Enterprise Edition : In incorporate environment benefit by using the advanced features in the Enterprise Edition to create robust distributed applications in a team 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

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 as dialog 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 purpose procedures. 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 by the 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 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 what sequence. 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 event driven. 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 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

Question Bank for Visual Basic


Standard EXE A Standard EXE project is a typical and commonly used project type. ActiveX EXE These types of projects are available with the Professional ActiveX DLL Edition. ActiveX components are basic code building components. These are identical in functionality, but are packed differently ActiveX 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 command button control which are basic element of the user interface ActiveX Document Exe ActiveX documents are in essence Visual Basic applications ActiveX Document DLL that can run in the environment of a container that supports hyperlinks. VB Application Wizard The Application Wizard provides a series of steps for setting VB Wizard Manager 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 information from the user. After the user fills out all the windows, the wizard proceeds to build an application , install software or carry 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 are used 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 and manipulating 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 computer IIS 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 Edition This is not a new type of project but it simply creates a new Control standard 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 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 a complete set of tools to simplify rapid application development, whether we are an experienced programmer or new to windows programming. Visual Basic consists of two

Neeraj Chopra

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 prebuilt into 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 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 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. 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 be invoked without explicitly creating an instance of the global objects. 2. Portable : Both 16 bit application for windows 3.1 or 32 bit applications for windows 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 architecture which 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 multiple interfaces. 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 Unblock comments 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 Migration Wizard , 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 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 a complete set of tools to simplify rapid application development, whether we are an experienced programmer or new to windows programming. Visual Basic consists of two

Neeraj Chopra

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 prebuilt into 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 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 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, procedures and activities we are planning in our application Toolbox : The toolbox contains the objects and controls that can be added to forms 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 to window explorer which allows us to expand and collapse the subfolders.Project explorer is a quick reference to various elements forms, classes and modules in our project.

Neeraj Chopra

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 is also 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 form layout 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 form and 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 certain common 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 module containing 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 that can 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 for procedures and declarations commonly used by other parts of the application. They can contain global or module level declarations of constants, variables, external procedures and global procedures.

Form Modules: Form modules (.FRM filename extensions) are the foundations of
any 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 general procedures. 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 to create 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

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 Properties 3. Coding Creating an Interface Forms 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 can have 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 that occurs 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 to the 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-left corner 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 the container. 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. For example 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 make sure the form would fit on the screen.

Neeraj Chopra

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 we see 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 default set 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 other window applications. The form can be resized by dragging borders 3-Fixed Dialog It can include control menu box and title bar 4-Fixed It displays a nonsizeable window with a close button Toolwindow 5-Sizeable It displays a sizeable window with a close button, but does not ToolWindow include a maximize or minimize button . 2. Caption Property : It is a text that appears on the title bar of the form. The caption can 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 property window. It can set to true or false. When we set to true then also set the Border style 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

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 setting any of the three options the display of the form can be determined. Options Effect 0-Normal Opens form in the normal state 1-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 form 3. 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 created 6. 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 be added 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 followed by 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 the toolbox. 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 change directly. 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

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 is transparent 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 text specified in its caption property. Textbox To obtain fill-in-the-blank information from the user or to display information provided by 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 specifies the 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 can accept 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

Question Bank for Visual Basic


Frame Control A Frame control provides an identifiable group of controls. It acts as container for other controls 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 a command 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 off Commonly used checkbox properties are :

Neeraj Chopra

11

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. It represents 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 Vertical scrollbar 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 are normally 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 properties Interval : The interval property is measured in milliseconds and is represented by a 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 software architecture 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 information among 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

Question Bank for Visual Basic


Common ActiveX controls
Status Bar It is a control that is displayed at the bottom of application window and displays information 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. Date It 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 are related 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 icon associated 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 can viewed using the property window.The property page in addition to the general tab has the following 1. ImageList Tab to associate to a particular ImageList 2. Sorting Tab to display fields that expose the properties related to storing in a ListView 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

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 the control 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 properties can 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 supports most of the fundamental data types used in several programming languages. Data Type Byte Boolean Integer Long Single(floating point) Double(floating point) Currency Decimal Date Object String (variable length) String (Fixed length) Variant User Defined Storage size 1 bytes 2 bytes 2 bytes 4 bytes 4 bytes 8 bytes 8 bytes 14bytes 8 bytes 4 bytes 10 bytes + string length Length of string 16 bytes 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

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 long Fraction-Single, Double or Currency Example : Dim age as integer Dim ID as long Dim sum as single Dim price as currency Date Data Type Data 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 characters A 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 as some 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. A variable 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

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 float Radius=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 all application Private Statement Used at module level to declare private variables and allocate storage space. Private variables 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 to differentiate between them in code. For example if integer variable Myint is 16

Neeraj Chopra

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 long CSng 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. Userdefined data types can contain one or more elements of a datatype. Declaring a userdefined datatpye Type Studenttype Rollno as string Name as string Class as string Tmarks 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=Rahul Student1.class=BBA(CAM) Student1.tmarks=345

14) What is Constant ?

Neeraj Chopra

17

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 example Const 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 numeric expression. The list of the arithmetic operators are +,-,*,/,Mod Comparison Operator The comparison operators are used to compare expression. They compare expressions and return a Boolean value. Operator Description > Greater than < Less than >= Greater than equals to <= Less than equals to = Equals to <> Not equals to Like Operator It is used to compare two strings and returns a Boolean value. If strings matches pattern results is True, if there is no match result is False. If either string is Null, result is Null. Syntax Result = string like pattern Pattern may include following wildcards ? : for matching any single character in string

Neeraj Chopra

18

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 y y = x Like "m*" MsgBox y End Sub IS Operator It is used to compare two object reference variables and returns two if both the objects names 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 y MsgBox 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 Integer Dim d a = 10: b = 8: c = 6 d = a > b And b > c MsgBox d d = 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

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 statements
Loop 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 counter may be used. Private Sub Command1_Click() Dim i As Integer For i = 1 To 10 MsgBox "i=" & i Next i End Sub Another Example of FOR LOOP Private Sub Command1_Click() Dim i As Integer For i = 1 To 10 step 2 MsgBox "i=" & i Next i End Sub DO While Loop This loop test the condition first and if true executes the statement which are given in the loop Private Sub Command1_Click() Dim i As Integer i=1 Do While i <= 10 MsgBox "i= " & i i=i+1 Loop End Sub While Loop This loop test the condition first and if true executes the statement which are given in the loop Private Sub Command1_Click() Dim i As Integer i=1

Neeraj Chopra

20

Question Bank for Visual Basic


While i <= 10 MsgBox "i= " & i i=i+1 wend End Sub DO Until Loop This loop test the condition first and if false executes the statement which are given in the loop Private Sub Command1_Click() Dim i As Integer i=1 Do Until i > 10 MsgBox "i= " & i i=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 a number 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 Integer For i = 0 To 4 x(i) = InputBox("Enter value") Next i For i = 0 To 4 MsgBox (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 be created by giving an empty dimension list. For example Dim x() as integer Redim x(5) Example of Dynamic Arrays Private Sub Command1_Click()

Neeraj Chopra

21

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 are private 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 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 by the 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 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 what sequence. 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 event driven. 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

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 displayed 2. 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 events 3. 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 taken by 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 user clicks 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 he tries 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 create our 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 can be 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 oriented technology. We can look around ourself and see many examples of real world objects :

Neeraj Chopra

23

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 they too 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 Command Button Description

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 like fields 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 a control 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 creates an 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 dialog control 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 by applications 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. Using object 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

Question Bank for Visual Basic


Features of OOPS 1. Abstraction : It is the process of selecting essential features of an entity that describe 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. This abstraction 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 utilize the 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 also be 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 which another 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 the operation. 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 OLE automation 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 any Windows 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 categories 1. 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 functions that 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

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 of using DLL?
When we need capabilities that do beyond the core language and controls provided with VB 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 the procedures within these libraries to display windows and graphics, manage memory or perform other tasks. These procedures are sometimes also referred to as the Windows APIs 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 procedure and 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 always modal 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

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 omit title 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 by adding 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 the application . Pop-up menu is also referred to as context sensitive menus. Menu bars are used in applications to provide an organized collections of commands that can be used by the user. In visual basic there are two different methods to create menusfirst 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

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 the application. 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 are visible only when they are needed and invoked through program code. Properties of Menus Property Caption Name Index Shortcut Visible Enabled Description The text of the menu that the user will see The name that we will use in our code to refer to this menu and to identify the event code for each menu item Used to from menu control arrays The menu can be invoked either by clicking it with the mouse in a normal way or by pressing the short cut key. Clicking the check box to set this property to true causes the menu item to be visible at run time 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 can always occur in our program. A run time errors can occur when the user tries to open a file 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 value a value and retry an operation or exit the program.

Neeraj Chopra

28

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 incorrectly typed 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. For example 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 debug mode 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 especially difficult . 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 are sure 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 the program 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 for reading 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 data store 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 same computer as the user application while the data store is located on a remote machine. 3. Programmatically, using Visual Basic Data Access Object (DAO) Creating database programmatically using Data Access objects gives our program complete control how the database is created and structured.

Neeraj Chopra

29

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 interface 6. 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 ultimate like 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 Microsoft Jet 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 of information 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 to each 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 English like 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 by returning 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

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 that information 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 the programmer 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 defined relationships. 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 common application. 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 a field 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 number and 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 a database 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

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 and establishing 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. The Workspace 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 and so 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 that represents a single table that represents a single table that can use to add, change or 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 or more 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 to gain maximum business advantage from the data and information distributed throughout

Neeraj Chopra

32

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 enable corporations 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 works with 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 Database Connectivity 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 Universal Data Access 1. ODBC: Open Database Connectivity is a widely used accepted application programming interface (API) for database access and it uses Structured Query Language (SQL) as its database access language.

Neeraj Chopra

33

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 an Internet 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

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 as Microsoft 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 learn object 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 seven object 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, cursor type 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 query to be changed at runtime Recordset object: A Recordset object represents the entire set of records from a base table on the result of an executed command. At any time the Recordset object refers to only a single 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 rows 3. Specify the order in which the rows may be traversed 4. Add, change or delete rows 5. Update the data source with changed rows 6. 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

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 contains all 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 generate one 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 objects can 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 issue the 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 that contains 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 the opportunity 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 DBEngine Workspace Database (Connection for ODBCDirect workspace) TableDef QueryDef Relation Recordset Field RDO RdoEngine rdoEnvironment rdoConnection rdoTable rdoQuery rdoResultSet rdoColumn ADO Connection Command Recordset Field

Neeraj Chopra

36

Question Bank for Visual Basic

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


Arrays are used to refer to a series of variables by the same name. They use an index to refer to the individual elements. Some important points to be noted about arrays are : All the elements in an array have the same data type. If we declare an array as a Variant, the individual elements can contain different kinds of data. We can declare an array of any of the fundamental data type, including user defined types. Types of arrays Fixed size arrays There are three ways to declare a fixed size depending on the scope we want the array to have. To create a public array , we must use the Public statement in the declaration section of a module to declare the array To create a module level we must use the Dim statement in the declarations sections of a module to declare the array To create a local array we must use the Dim statement in a procedure to declare the array. Dynamic Arrays At times, it may be possible that we dont know how large the array is to be made and in that condition we can declare an empty array. An array that starts its life with no elements is called a dynamic array. After the array is initially declared it can be resized at any time or new elements can be added as needed, rather than establishing the size of the array at the time the code is written. Multidimensional Arrays A two dimensional array or multidimensional array two index the first identifies the row and the second identifies the column. Control Arrays A control array is a group of controls that share name and type. They also share the same event procedure. A control array has at least one element and can grow to as many elements as our system supports. The maximum index we can use in the control array is 32767. Elements of the same control array have their own property setting and control arrays are used in menu control and option button settings They need fewer resources

Neeraj Chopra

37

Question Bank for Visual Basic


than simply adding multiple controls of the same type to a form at design time. They are used if we want several controls to share code. If we want to create an instance of the control at run time the control should be a member of the control array. With control array each new element inherits the common even procedures of the array.

43) Write Short note on Control Array.


A control array is a group of controls that share name and type. They also share the same event procedure. A control array has at least one element and can grow to as many elements as our system supports. The maximum index we can use in the control array is 32767. Elements of the same control array have their own property setting and control arrays are used in menu control and option button settings They need fewer resources than simply adding multiple controls of the same type to a form at design time. They are used if we want several controls to share code. If we want to create an instance of the control at run time the control should be a member of the control array. With control array each new element inherits the common even procedures of the array. Removing elements from a Control Array At design time one can remove control array elements from a form in several ways Select the control elements and press the delete key Select the control and choose delete from the edit menu Right click on the control and select delete from the context menu

44) Write Short note Collections


Arrays are basically used for storing related data but to access individual elements in an array is a problem. Lets say if we want to print the Qty of Hard disk then we have to known the index that corresponds to Hard Disk otherwise we have to scan each element in the array till we find the Hard disk. Visual Basic provides an alternative solutions : Collections which is similar to array ,a collection stores related items. The advantage of a collection over an array is that the collection allow us to access its items via key. The collection object provides three methods and one property Add method : Adds items to the collection Remove method : Deletes an item from the collection by index or key Item method : Returns an item by index or by key Count method : Returns the number of items in the collection

45) What is TypeOf statement


The TypeOf statement is used to determine the type of control that is being accessed in the controls collection.

Neeraj Chopra

38

Question Bank for Visual Basic


46) Difference between control arrays and control collection
The controls collection has controls of different types, whereas the controls arrays consist of controls of the same type The elements of the controls collection are referred by different names, but all the elements in a control array have the same name.

47) What is MDI ( Multiple Document Interface) ? Explain


When an application is designed it might contain a number of forms and each of these forms are displayed separately on the screen and moved , maximized or minimized separately from any other form. These forms can be organized as a group using MDI. The Multiple Document Interface is another class of the form that allow us to open Windows within a parent window container window. In an MDI an application there is one container form called an MDI form that provides a main workspace that can contain childe form. Applications such as Microsoft Word and Microsoft Excel are best examples of MDI where many documents can be opened simultaneously within the main window. If we maximize an MDI child form which is displayed on the parent MDI form, its caption is combined with the caption of the parent form. On minimizing the MDI parent form, the child form also get minimized.

Neeraj Chopra

39

Das könnte Ihnen auch gefallen