You are on page 1of 45

1

Qn. What is an Array? How do we create an Array in VB Program? Also write the syntax for creating a Multidimensional Array & Dynamic Array with suitable example.
Ans. Array is a linear collection of same type variable which allocates contiguous memory in the primary memory RAM. Alternately, we can say that Array is a common name shared by various variable of same type which allocates linear contiguous memory in the primary memory RAM. The main importance of array is to handle huge number of variables of same type very easily & efficiently by using index or, subscript of array blocks. It is also possible to declare huge number of same type variable using a single statement. Since, array allocates contiguous memory in the primary memory RAM. So, the access time of array variable is minimum. Consequently, the processing speed of program will be very fast. In Visual Basic, array is declared using the Dim keyword and the Redim keyword according with the name of the array & appropriate size.

The general syntax of array declaration in visual basic isDim ArrayName(Size) as DataType The ArrayName is any legal identifier allowed in visual basic that should be start with an alphabet and can be up to 256 characters. The special symbols Underscore (_) and Dollar($) can be allowed in identifier name. The size can be any positive integer number greater than zero(0) & can be any extend. The DataType can be any type allowed in visual basic. It may be any standard datatype like- int, double, single etc. or, it may be any control array as array of command button, array of listbox, array of textbox etc. By default, the index number of array blocks starting from 0 can be up to the size. A single block is represented using the arrayname and appropriate index within pair of parenthesis. So, array is also called Index Variable or, Subscripted Variable. For exampleDim A(5) as Integer The above declaration declares an array A of integer type asA 0 1 2 3 4 5

User also can specify own index range at the time of declaration of array. The general syntax to specify range of index in visual

basic asDim ArrayName (Starting Index to Ending Index) as DataType The starting index can be any positive integer less than the ending index. The ending index must be any integer number greater than the starting index. For exampleDim A (5 to 10) as Integer The above declaration declares an array as5 6 7 8 9 10 A User can also declare multidimensional array in visual basic by specifying number of rows and columns. It is possible to declare TwoDimensional, Three-Dimensional or, more dimensional array in visual basic. In visual basic, generally no upper limit of dimension is present but practically maximum 256 dimension can be implemented. In visual basic

Two-Dimensional array can be declared asDim ArrayName(Number of Rows, Number of Columns) as DataType The number of rows must be any positive integer number greater than zero & number of columns also must be a positive integer number greater than zero. For exampleDim A(5,4) as Integer The above declaration declares a 2D array asA 00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33 40 41 42 43 It is also possible to specify index range in 2D array. For exampleDim A(2 to 4,6 to 9) as Integer

The above declaration declares a 2D array of integer type asA 26 27 28 29 36 37 38 39 46 47 48 49 All the above array allocates their memory statically before execution and automatically initialized by their respective 0 value. User can also create array dynamically in visual basic. It is also possible to create single dimensional as well as multidimensional array dynamically in visual basic using the REDIM keyword. Using REDIM keyword an existing array can be increased in size by keeping the existing values unchanged by applying the keyword preserve. If the preserve keyword is not present then the existing value of an existing array will be deleted and initialized by zero.

In visual basic, single dimensional array can be created dynamically using the following syntaxRedim ArrayName (Size) as DataType For exampleDim N as Integer N=CInt (Inputbox(Enter Size :)) Redim A(N) as Integer In the above example user supply the size at the time of execution. After that, the array is created at the time of execution. This type of array is called Dynamic Array. The array will automatically initialized with their respective zero values.

It is also possible to create multidimensional array dynamically asDim R as Integer Dim C as Integer R=CInt (Inputbox(Enter Rows :)) C=CInt (Inputbox(Enter Columns :)) Redim A (R,C) as Integer

In the above example row and column value is inputted at the time of execution and the 2D array A is created using the (R+1) rows & (C+1) columns and all the blocks are of integer type. It is also possible to increase or, decrease the size of an existing array by preserving the existing values dynamically at the time of execution. For exampleDim A(10) as Integer Redim Preserve A(20) In the above example an integer type array A is created of 10 blocks and handled using appropriate statements. The last statement increase the size of the existing array A from 10 blocks to 20 blocks by unchanging the existing value. The same process can be applied on multidimensional array asDim A(4,5) as Integer Redim Preserve A(6,7) In the above example an integer type 2d array A of 4 row and 5 columns are created and handled by appropriate statements. The last statement reallocate memory for the same array by using new rows 7 & new columns 8 and preserve the existing values. The Redim keyword always allocates new memory and copies the existing array in new memory.

Qn.What is Visual Basic IDE? What are the components of Visual Basic IDE? Describe all the components briefly.
Ans. The abbreviated form of IDE is Integrated Development Environment. Integrated represents the added form of different components to form a proper system. The Visual Basic IDE is the development environment to develop any type of Visual Basic Application. In Visual Basic an IDE is present in which different independent components are present to develop

application as the requirement of the user. All the components are present in the IDE as integrated (added) form.

In Visual Basic IDE the following components are present:1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. Title Bar Standard Menu Bar * Standard Toolbar * Form Design Window * Project Explorer Window * Properties Window * Toolbox * Code Window Object Browser Window Form Layout Window Immediate Window

Title Bar
The Title Bar is the top most horizontal line present in the VB IDE. The Title Bar contains the project name which is under development and the form name which is currently active in the under development application. In VB whole program is present under a project which contains all the forms as well as the internal coding system of application. A single project can contain more than one forms as the requirement of the application.

Standard Menu Bar


The second horizontal line from the top is called Standard Menu Bar which contains standard menu to design as well as execute the application. All types of options are present under appropriate menu in the form of menu item. The menus present in the standard menu bar are the group name of a specific group of menu item. User can use appropriate menu item present under menus or, using mouse or, using standard shortcuts. Generally, the menu bar contains the following popular menus-

File, Edit, View, Project, Format, Run, Query, Diagram, Tools, AddIns, Window etc. The File menu is used to create new project as well as save a new project. It is also possible to open existing project using open project menu item. This menu also contains form saving option, remove project option, print option, exit option etc. It is also possible to create .exe file using the make .exe menu item present under file menu. The Edit menu is generally used to provide appropriate format on the components present in the current application by using Cut, Copy, Paste, Remove, Delete, Delete Table from Database, Find, Replace, Indent etc. This menu also contains Undo and Redo option. The View menu is used to activate or, deactivate the different components present in the VB IDE. User can open the code window, Object Browser Window, Immediate Window, Form-Design Window, Properties Window, Form-Layout Window, Toolbox, Toolbar etc. It is also possible to open appropriate form using the object option present under view menu. User can also view the tables present in the current application as well as provide appropriate properties to the fields present in the table. The Project menu is used to add new forms as well as new modules in the current application. It is also possible to add new controls in the toolbox using the components menu item present in the project menu. User can also set a reference with a table columns to appropriate object present in the application. For example- User can link a textbox with a table column to view content of the columns sequentially. User can remove existing form from the current application as the requirement of the user. The Format menu is used to provide vertical and horizontal spacing of characters as well as same height and width of the components of the application. It is also possible to set order of components in respect of viewing the components. For example- User can combine list of radio buttons under a frame. The frame should be in the back of the radio buttons, otherwise the buttons are invisible. The order of viewing of components is set using the order menu item present in the Format menu.

The Run menu is responsible to execute an application. The start menu item is used to start execution of a Visual Basic Application. It is also possible to start execution by pressing the key F5. The start with full compile menu item is also used to execute a Visual Basic Application after full compilation of the application but the previous one does not compile the whole application before execution. User can activate this menu item by pressing Ctrl+F5. It is also possible to restart the execution by selecting restart or, end menu item present in the Run menu. The Query menu is responsible to execute SQL(Structured Query Language) statements to retrieve information from the database present in the Oracle or, SQL Server or, Access or, any other DBMS present in the system and connected with the application. Generally, Visual Basic is used as a front-end tool to accept data values and viewing information as the requirement of the user. All the inputted information are stored by the VB in back-end DBMS. Such as- MS-access, SQL Server, Oracle, Sybase, Informics etc. The DBMS provide high security to the data values present in the database. The query menu is responsible to retrieve appropriate information from the database and view the retrieved information on the forms. The Tools menu is responsible to add new procedure or remove existing procedure present in the code window. It is also possible to format code window by clicking the options menu item and selecting editor format. It is also possible to create own menu bar, menus and menu items using the Menu Editor menu item present in the Tools menu. The Add-Ins menu is responsible to connect database visually with the current application. It is also possible to create new table in the database according to the requirement of the user and automatically connect the database with the application as the requirement of the user. The form is automatically designed according to the number of fields present in the database. User can add new records and can view existing records using the application. The Window menu is responsible to arrange more than one forms horizontally, vertically, cascade. The horizontally and vertically menu item is

based on tiled arrangement. The Tiled arrangement is those type of arrangement in which one form is present besides the another form, no overlapping is present. Tiled horizontally arrangement arranges row-wise form & tiled vertically arrangement arranges column-wise form. The cascade arrangement arranges the forms one upon another but the existence of previous form is viewed partially.

Standard Toolbar
Standard Toolbar is the third horizontal line from the top of VB IDE. Standard Toolbar contains symbolic representation which are popularly used in VB application development and present under different menus. Standard Toolbar is the easy way to perform appropriate action on the application without searching the menu item present under menu, only by clicking on appropriate symbol. Generally, Standard toolbar contains symbolic representation of new project, add form, menu editor, open project, save project, cut, copy, paste, undo, redo, start execution, stop etc. This toolbar also contains other components of the IDE. Such as- project explorer, properties, form-layout, object browser window, toolbox, visual component manager etc. The toolbar also contains the co-ordinates of the form starting from (0,0) up to the size which are currently selected on the current application. The standard .exe project symbol is used to create new application as the requirement of the user. The add form symbol is used to add new form in the current application. User can add any number of form as the requirement of the user. The menu designer tool is used to design user-defined menu bar, menu-items as the choice of the user. Visual Basic also provide facility to add shortcut with the menu items as the choice of the user. The open project tool is used to open existing project which are currently present in the system. The save project tool is used to save the current application under a particular name supplied by the user. The Cut, Copy, Paste tools is used to implement cut, copy of the selected text and insert the selected text at appropriate position as the choice of the user. The start tool is used to start the execution of a Visual Basic Application. The project explorer tool is used to re-display the project explorer component of Visual Basic IDE in the current application. It is also possible to Off & On the properties window of a selected component of Visual Basic Application. The form-layout tool is

used to display this component in Visual Basic Application. The object browser tools is used to open the object browser window to see the methods, events and fields present in a selected class or, object. The toolbox tool is used to again display the toolbox in the application at the time of development.

Form-Design Window
The Form Designer Window is used to design appropriate interface required for the application. Generally, Visual Basic is used as a front end application tools for real life application. That means the only use of visual basic is to provide appropriate interface to the user to interact with the application. The form-designer window is the place where the application interface is created by the user with the help of toolbox. The form is the main container to contain the controls supplied from the toolbox to interface the application data stored in the back-end DBMS. In real application the inputted data of Visual Basic program is generally stored in the back-end database present in MS-access. Oracle, SQL server or, any other DBMS present in the system. The form-designer window can be designed externally at the time of development of the application using the toolbox. User can also add components by clicking on component menu bar present under project menu or, right clicking on toolbox or, by pressing Ctrl+T & select appropriate component as the requirement of the user. It is also possible to add components in the form using appropriate code written in the code window.

Project Explorer Window


The Project Explorer Window shows the hierarchical display of the application and the forms. This window show the project name which is under development. This window also shows the number of forms and name of forms currently present in the application. When the number of forms are large then user can display appropriate form by double-clicking on the form name under the Project Explorer Window.

10

The Project Explorer Window also contains three tool on the top border of the window. The 1st tool is used to display the code window for the current application. The 2nd tool display the forms present in the current application. The 3rd tool is used to off the previous two tools action.

Properties Window
The Properties Window displays the field name and their current value of the selected object on the form-design window in two-column format. The properties windows is used to navigate all the properties (identifying properties) present in the selected object or, control in the application. Generally, the properties window displays properties alphabetically. It is also possible to display categorisely. User can change the properties values of the properties by selecting the property and supplying new value using keyboard or, mouse. The properties window also displays the name of the control thats properties are currently displayed in the properties window.

ToolBox
The toolbox is the most important component of Visual Basic IDE. The toolbar is present in the left side of the form-design window and contains popular controls for Visual Basic Application development. The toolbox generally contains textbox, picture box, label, command button, option button, checkbox, listbox, combobox, scroll bars, timer, drive list box, directory list box, shapes, image box, data control etc. The Picture box & Image box is used to display pictures and can show picture. The label is basically used to display message as a label which is displayed permanently on the application. The text box is used to take input values from keyboard and all the values are treated as a string. The command button is used to take action on the application by clicking on the button by mouse. The radio button is used to select from a group of buttons to take appropriate action according to the state of radio button. More than one radio button cannot be selected at a time of a group. To form a group of radio buttons all the buttons are positioned on a frame. The checkbox also has two states True or, False. More than one checkbox can be selected as the choice of the user. Generally, checkboxes are used to check conditions as the requirement of the user but radio button can check only single condition. The

11

listbox contains list of items which are displayed any time in the box. If the items are large enough then the scrollbars will automatically arise. Listbox is generally used to display few number of items. The combo box is same as listbox which can contain any number of items but display only one at a time which is currently selected. So, for huge number of item combobox is a better choice than the listbox. The scrollbars are used to scroll a particular component or, contents horizontally or, vertically. Drivelistbox, directorylistbox and filelistbox are used to handle drives present in the system, directories present in the current selected drive & list of files present in the currently selected directories. The shape control is used to display general shapes like rectangle, square, oval, circle etc. The data control is used to connect database with the current application.

Code Window
The Code Window is used to write codes which are internally executed to perfectly execute the program and displays required information. The code window can be opened by double-clicking on any component of the form or, by clicking the first tool View Code present in the top border of project explorer window. It is also possible to open code window by clicking on the code menu item present under view menu.

Form-Layout Window
The Form-Layout Window is the preview of the forms of the current application. This window provides an idea to the user about the viewing size, colors of the forms of the application which is under development. This window is non-interactive. User can set the position of forms on the screen by dragging the forms in the form-layout window.

Object Browser Window


The Object Browser Window displays the classes and their members & events associated with the class. This window also displays the methods present in the class. The object browser window contains all the classes

12

present in visual basic and their associated properties, methods & events. This window also contains list of objects present in the current application in bold letter.

Immediate Window
The Immediate window is generally used to debug logical errors related to variables. This window displays the immediate values of variables which are under debug. Visual Basic automatically recognize syntax errors at the time of editing logical errors can be removed by checking the value of variables using the immediate window.

13

Qn. How to connect Oracle with Visual Basic?


Ans. Steps to connect Oracle with Visual Basic are as followsStep 1: Click on Start & go to Control Panel. Click on Administrative Tools and then click on Data Source (ODBC). Click on System DSN, then click on Add button. Select Microsoft ODBC for Oracle & click on Finish (a dialog box appears). Fill some value in the box & then click OK, after that once more click on OK. Step 2: Open Visual Basic IDE (Integrated Development Environment), right click on toolbox, click on Components & select Microsoft ADO Data Control 6.0 (OLEDB). Now click on apply & then click on Close. Step 3: Select Adodc from toolbox, drag it on the form & set the control. Right click on Adodc1 & click on Adodc properties. Select Use Connection String under general option & click on build button. Select Microsoft OLEDB provider for Oracle in the tag Provider. Supply user-name & password & click on test connection, after that click on OK. Enter user-name and password again under the tag authentication. Under resource select 2adcmdTable under the table option, click on Apply & finally click on OK. Step 4: Right click on toolbox & select Components, select Microsoft DataGrid Control 6.0 (OLEDB). Click on Apply & then Close. Double-click on DataGrid & arrange on the form. Set all the properties of datagrid related to records true. Such as- Allow addnew, Allow delete, Allow update etc. Set datasource name adodc1.

14

Qn. What is Event Driven Programing? What are its properties? How does it take place in Visual Basic? Explain with example.
Ans. Event Driven Programing is those type of programming in which a particular event is fired automatically when that type of event is occurred. In Event Driven Programing various event actions are present. Such as- Click, DblClick, mousemove, mousedrag, gotfocus, lostfocus, keypress, keyrealised, keyup etc. & appropriate action is automatically performed by the Visual Basic. In Event Driven Programing a particular action event is performed by the user and internally appropriate code block written under that event is automatically fired & executed & required task is performed. Visual Basic is an Object Based Programing language in which the form is the main object which contains the other objects necessary for an application. Every object has three components in Visual Basic. The first component is the properties of the object which are displayed in the properties window with name and values. The properties values can be set by the user in the properties window or, by using appropriate code. The Second component is the method or, function present in that object. The methods cannot be automatically invoked or fired from the external action. The method is activate using appropriate events and perform appropriate task. For example- The form object has Circle, cls, line etc. methods to draw appropriate figure on the form which can be active by supplying some event. The Third components of any Visual Basic object are the events associated with the object. Events are automatically called same as interface function of Java when appropriate event action is arised. For example:- The form object has the popular events activate, deactivate, click, dblclick, gotfocus, lostfocus, keydown, keypress, keyup, load, mousedown, mousemove, mouseup, paint, resize, unload etc. The events has fixed properties. User cannot change the name of the events as well as the argument list and argument type of events. It is possible to link more than one events internally. Events are automatically fired or, invoked when such type of action event will arise. For example- The click event of a

15

form will automatically invoked when a double-click action is arise on the form. The events are listed in the combo box present in the upper right corner of the code window. User can define any event associated with created objects present in the combo box upper left side of the code window. The Object Browser Window displays all the components present in the objects. The events are marked using the mouseclick sign with yellow colors. In Visual Basic every component contains huge number of events but few are unable for a particular application. User define the events in the code window which are necessary for a particular application. It is possible to define more than one events related to a particular action. The defined events are automatically active or, fired when such type of action event is performed by the user.

For exampleWrite a Visual Basic Application to change the Background color of a form when a MouseMove action event is arise on the form. Step 1: Design a form such as form1 and set the Caption COLOR EXAMPLE in the properties windowStep 2 : Open code window and select the MouseMove event & set the BackColor property of form1 randomly asPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Form1.BackColor = RGB(CInt(255 * Rnd), CInt(255 * Rnd), CInt(255 * Rnd)) End Sub The background color of form1 will automatically changed when the mousemove action event is arise on the form.

16

Qn. Explain the difference between Combo Box & List Box. Write down the method showing that a particular list box item is selected.
Ans. The List Box control is very popular control present in the toolbox to display list of elements. The list box displays one element in a row and can display more than one element at a time. Alternately, we can say that list box is a matrix of single column & multiple rows. When the display area is filled then a vertical scrollbar will automatically arise. By default, single element can be selected from a list box but it is possible to select more than one element from a listbox by changing the properties multiselect of the list box. The Combo Box is same as list box but only one element is displayed at a time in the combo box. In combo box multiple selection of element is not allowed. So, multiselect properties is not present. Combo box is useful to store huge number of elements.

List Box
1. List Box is arised using the list box control. 2. List Box displays more than one element at a time. 3. In list box, multiple elements can be selected. 4. List Box is useful for few number of elements.

Combo Box
1. Combo Box is arised using the Combo box control. 2. Combo Box displays only one element at a time. 3. In combo box, multiple elements cannot be selected. 4. Combo Box is useful for huge number of elements.

17

Qn. Write methods to connect any type of database using Add-In manager.
Ans. Methods to connect any type of database using Add-In manager are as followsStep 1: Click on Add-Ins on standard menu bar & go to Add-In manager and click. Step 2: Select VB6 Data Form Wizard and click on the check box loaded/unloaded under load behavior & click on Ok. Step 3: Click on Data-Form Wizard under Add-Ins menu & click on Next. Step 4: Select Remote(ODBC) and click on Next. Step 5: For Oracle DatabaseSupply DSN name created using Control Panel for Oracle Database. We must supply UserId as SCOTT, SYSTEM, INTERNAL etc. It is also possible to supply username created by the user itself. We must supply corresponding password according to the username-

System Manager Scott Tiger Internal Oracle


It is also possible to supply password of user created user. For Other DatabaseOnly supply DSN name created by the user using Control Panel. And click on Next. Step 8: Step 9: Step 10: Step 11: Select appropriate layout of the form and click on Next. Select Table Name under the record source. Select fields for the form and click on Next. Delete extra forms under the project.

18

Qn. What is Common Dialog Box? Explain Message & Input Box with a suitable example. Is form may be created as a dialog box, if yes how? Ans. Dialog Boxes are generally pre-defined interface which are used
to take input values or, display messages in Visual Basic Application. Alternately, we can say that the Common Dialog Boxes are a custom control that displays the commonly used dialog boxes such as- Open, Save As, Color, Font, Print, Help etc. When a Common Dialog Box is created on a form it automatically resizes itself & it is invisible at run-time. Common Dialog Boxes are generally present in the Microsoft Common Dialog Control 6.0 under the components. By supplying the action property appropriate dialog box can be displayed as the requirement of the user. If the action value is 1 then Open dialog box will be arise, if the action value is 2 then Save As dialog box will be open, if it is 3 then the Color dialog box will be open, if it is 4 then the Font dialog box will be opened and so on. In Visual Basic two types of dialog boxes are present according to the interaction with the user and the display behavior of the dialog boxes. Generally, The Dialog boxes are divided in two categories1. Model Dialog Box 2. Modeless Dialog Box A Model Dialog Box does not allow the user to continue with other application unless it is close. The Modeless Dialog Box allow shifting of focus between the Dialog Box & another form without closing the dialog box. Message Box & Input Box are Model Dialog Box. It is also possible to display a form as a dialog box in Model or, Modeless form. In Visual Basic three types of dialog boxes are present according to the creation of the dialog boxes:1. Pre-Defined Dialog Boxes 2. Standard Dialog Boxes 3. Custom Dialog Boxes

19

Pre-Defined dialog boxes are generally Message Box and Input Box which can be displayed anywhere and in any application as the choice of the user. It is not necessary to add any control to handle dialog boxes. Common Dialog Boxes are those dialog boxes which are created by the user using form & appropriate control & which can be used in Visual Basic Application as a Model or Modeless form. The Message Box is a pre-defined model dialog box to display anything as a pre-defined form. The general form of Message Box isMsgbox (Prompt,dialog type,Title) The message is a string which is displayed on the Message Box and should be supplied by the user. The dialog type specify which buttons are displayed on the message box. The default value is VBOKONLY. Any dialog type can be used in Message box which are allowed in Visual Basic. It is also possible to supply integer values corresponding to dialog type. The title is also a string which should be supplied by the user. If the dialog type is provided by the user then the message box return an integer value corresponding to the clicked button on the message box. User can test the clicked button which is clicked by the user according to the returned value of the user. Input box is also a pre-defined dialog box of model type. The Input box always returns a string value and can take two string type arguments. The first argument is displayed as a message to the user and the second argument is displayed as a title on the caption of the form. Yes, it is possible to display a form as a dialog box in Visual Basic Application:User can add a form in any visual basic application using the add form tools present in standard toolbar or, under the project menu. The form should be hidden in the load event of the main form. User can display the form by calling any sub-routine or, function and write the statement:Form1.show <For Model Dialog Box> Form1.show (1) <For Model Dialog Box>

20

Qn. What do you mean by Control? Explain 5 important controls with their properties and event. How can you set in the control properties with the help of code? Ans. Controls are system-defined object present in the toolbox to handle Visual
Basic program. Generally, popularly used controls are present in the toolbox. Every control present in the toolbox is pre-defined object and so, it has three types of componentsIdentifying properties or, Data member which are displayed in the properties window after selecting the object. The next components are the events associated with the control. The events are automatically fired when appropriate action event is arised. User can define any events as the requirement of the user. The last property of control are the methods present in the object which can be called by supplying appropriate arguments associated with the object.

In Visual Basic the most popular controls are present1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. Command Button Text Box Picture Box Label Frame Check Box Option Button Combo Box list Box Horizontal Scrollbar Vertical Scrollbar Timer Drive List Box Directory List Box File List Box Shape Line Image Box Data Control OLE

21

Command Button
Command Button is the most important control present in the toolbox to handle visual basic application. Using command button user can invoke any event associated with the command button and can perform any task.

The Command properties: Name Appearance Backcolor Caption Enabled Font Picture Style Tool Tip Text Visible etc.

Button

has

the

following

popular

The name of command button which is generally command1,command2, Command3.. etc. is the internal identifier which can be used in coding to perform appropriate task associated with the command button. The Appearance property is used to set the appearance of the command button. Its value is 0 & 1. The 0 indicates flately appearance and 1 indicate 3D appearance. The BackColor property is used to set the Background Color of the command button. The color can be active if the style is graphical. The caption property is used to set the label of the command button which is displayed on the command button. It is also possible to highlight a character on the caption by a preceding ampersand (&) symbol. The enabled property is used to activate or, deactivate the command button. If the value is True(default) then it is Active. If it is False then it is Deactivated. The Font property is used to set the font property of the caption of the command button. The picture property is used to set picture on the command button, if the style property is graphical. Style property is used to set the looking of the command button which is by default 0(standard). User can set the graphical style by setting value 1 in the style. The TabIndex property is used to set the sequence order of the command

22

button during execution. The TabIndex value is automatically started from 0. The Tool Tip Text property is used to set a pop-up text when the cursor is on the command buton. The visible property is used to set the visibility of the command button which is by default True. If it is false then the button will be disappear.

The Command Button has the following popular Events: Click GotFocus LostLocus KeyDown KeyPress KeyUp MouseDown MouseMove MouseUp etc.
The Click event will automatically invoked when user click on the command button. The GotFocus event will automatically activate when the cursor or, control activate the button. Similarly, the LostFocus event will automatically activate when the control goes from the button. The KeyDown event will automatically invoked when any key present in the keyboard pressed by the user. Similarly, the KeyUp event will automatically activate when any key is released by the user. The KeyPress event will automatically called when any key printable or nonprintable is pressed by the user from the keyboard. The MouseDown event is automatically called when any button of the mouse is pressed by the user. Similarly, the MouseUp event will automatically called when the mouse buttons are released by the user. The MouseMove event will be automatically called when the mouse is moving on the button.

Text Box
The Text Box control is also a very important common control present in the toolbox. The textbox control is generally used to take input values from keyboard. It is also possible to supply values from other controls such as- listbox, combobox, checkbox or, other common dialog boxes. User can also display calculated results in textbox.

23

The general properties of TextBox are Name Alignment Appearance Backcolor Forecolor BorderStyle Datafield Dataformat Datasource Enabled Font Locked Multiline PasswordChar Scrollbars Tabindex Text Tooltiptext Visible etc. The name property is the internal name of textbox object which is generally text1, text2, Text3. etc. The Alignment property is used to set the display alignment of the box which is by default left alignment(0). 1 indicates Right alignment and 2 indicates Center alignment. The Appearance property is used to set the looking of textbox which is by default 3D(1). The 0 value indicates Flat looking. The BackColor property is used to set the background color. Similarly, the ForeColor property is used to set the foreground color. The BorderStyle property is used to set the borders or, unset borders around the textbox which is by default fixed single (1). The 0 value provide no border. The DataField property is used to set the field name of a database which is displayed during execution. The DataField can work if the DataSource is set. The DataFormat is used to set the format property of the textfield. Using this property user can specify the type

24

of the textfield which is by default string. The DataSource property is used to link a textfield to a DataBase field. The Enabled property is used to activate or, deactivate the textbox. The default value is True. The Locked property is used to set the editable true or, false which is by default false. If the value is true then it is not possible to write anything in the textbox. The Font property is used to set the fonts of the textbox with style and size. The MultiLine property is by default false that means only one line can be inputted. It is also possible to set scrollbars around the textbox. This property can be activated automatically when the multiline is true. The PasswordChar property is used to set the password character during inputting into the textbox. This character is displayed during typing. This property can be set if multiline is false. The scrollbar property is used to set scrollbars around textbox. This property can be activate if the multiline property is True. The text property is used to set text into the textbox as well as get the text present in the textbox. The visible property is by default True. If the property is false then the textbox will be disappear.

The textbox has following popular events Change Click Dblclick Gotfocus Lostfocus Keydown Keypress Keyup Mousedown Mousemove Mouseup etc.

The change event will be automatically called when any changing is performed on the textbox. The click event will automatically invoked when user click on the command button. The gotfocus event will automatically activate when the cursor or, control activate the button. Similarly, the lostfocus event will automatically activate when the control goes from the button. The keydown event will automatically invoked when any key present in the keyboard pressed by the user. Similarly, the keyup event will automatically activate when any key is released by the user. The keypress

25

event will automatically called when any key printable or, non-printable is pressed by the user from the keyboard. The mousedown event is automatically called when any button of the mouse is pressed by the user. Similarly, the mouseup event will automatically called when the mouse buttons are released by the user. The mousemove event will be automatically called when the mouse is moving on the button.

The following popular methods are present with textbox Setfocus Move Refresh etc. The setfocus method is used to move the cursor to the textbox. The refresh method is used to refresh the textbox by deleting unwanted values. The move method is used to move the textbox from one location to another.

LABEL
The label is as same as text box. The only difference is that, it is only read only property contains. Control can not focus on label. User can change the caption of label at run time by supplying some text. It is not possible to write text on label using keyboard directly. Label has no events related to keyboard. Label has the following popular properties: Alignment Appearance Auto size Back Color Border Style Caption, Font Tab Index Name etc.

26

A Label control has the following popular events: Click Dbl Click Mouse Down Mouse Move Mouse Up etc. Label control has the following popular methods: Drag Move Link Request Refresh etc.

List Box
List Box is one of the most important controls present in tool Box which contains a list of data in the form of string. User can browse the data in the list Box and select one or more items as the requirement of the user. The user can not edit the data in the list box directly. When the list box of data is to long then Visual Basic adds a vertical scroll bar. List box always displays some list of elements as the size of the list box. So, it occupies maximum space on the form container in comparison with Combo Box. So, it is suitable to display few numbers of elements using List Box. The popular properties of List box are: Appearance List Columns Data Field Data Source Enabled Font Index

27

Tab Index Multi Select Sorted Visible etc. The Appearance property set the property is used to set the looking of List Box as flat or 3D. The Back color property is used to set the Background color of the List Box. The column property is used to set the multiple columns in a List Box which is by default 1. if the user change the columns property by two or three then List Box contains two or three columns as same as news paper columns. User can select any elements from the multiple columns List Box as and when required. The Index property of elements are automatically starting from 0 (zero) and increment by 1. User can set the starting Index using the index property. The Font property is used to set the Font name and Font size of the List Box. Using the properties Data Source and Data field, a List Box can be connected with a database and with appropriate field of the Database. The List Box will automatically populated with the values of the fields which is internally connected. User can link a Database with List Box using Microsoft Data Bound List Control, Microsoft Data List Control. The Data-source property contains the Database name and the Data Field property contain the field name, thats value will populated the list box. The List property is used to supply list of element to the List Box at design time. The ListCount property returns the total number of element present in the ListBox. The ListIndex property returns the Index number of the selected items. The MultiSelect property is used to set the MultiSelect option of the ListBox which is by default false. The Name property is used to set the internal name of the ListBox. The stored property is used to set the order of element of the ListBox, which is by default false. If the property is true then list of elements will be displayed in alphabetical order. The selected property is used to test a particular element is selected or not. The Text property returns the name of the element which is currently selected. The ListBox has the following popular events: Click DblClick GotFocus LostFocus

28

KeyPress KeyUp MouseMove MouseDown MouseUp Scroll etc.

The ListBox has the following popular Methods: AddItem Remove Item Clear Set Focus etc

Combo Box
The Combo Box control is as same as ListBox, the only difference is that it displays a single element which is currently selected but can contain any number of elements. The Combo Box comes from combination box which is the combination of Text Box and List Box. A Combo Box controls allows the user to select a predefine item from a list and enter new value not in the list. The Combo Box is also known as Dropped Down Box. The Combo Box control is most suitable for a huge number of elements. In

29

Combo Box, it is not possible to select multiple elements. That means, Multi Select property is not present. The Combo Box has the following popular properties: Appearance BackColor Datasource DataField Enabled Font Index List ListIndex Sorted Style Text Visible TextVisible etc. The Style property is used to set the behavior and appearance of the Combo Box. The Style can be of three types, starting from 0 to 2.the 0(zero) style indicates drop down combo which looks like standard text box with a drop down arrow to the right side. Clicking the arrow opens a list under the Text Box. After selecting the selected item is displayed in the text box or user can enter element to select appropriate element. The style property 1indicates simple Combo Box, In which the list is permanently displayed. That means, it is a list box with Text Box. The Style value 2 indicates Drop Down List. It is a List Box rather then a Combo Box. It looks identical with a drop down Combo but it is not possible to write any thing in the Text Box. Only selected item is displayed on the Text Box. The Combo Box has the following popular Events: Click DblClick KeyPress KeyUp GotFocus

30

LostFocus Scroll etc. The Combo Box has the following popular Methods: AddItem RemoveItem Clear Move SetFocus etc.

DRIVE LIST BOX


The Drive List Box is a special type of Combo Box which is automatically populated using the drive present in the system. Using the Drive List Box user can select any drive present in the system and consequently corresponding changes can be perform on Directory List Box. The Drive List Box, Directory List Box and File List Box are combindly used to access any files from any Directory present in any drive. So, both the three list boxes should be present in a single application. The Drive List Box has the following popular properties: Appearance Drive Font Index List ListCount ListIndex Name visiable etc. The drive property is used to set the drive name which is automatically selected other wise the Drive Property can be changed by using the change events in the Drive List Box.

31

The Drive List Box has the following popular Events: Change GotFocus LostFocus KeyPress KeyUp Scroll etc. The Change event is the most popular events present in the Drive List Box which is automatically executed when it makes a selection in the Drive List Box. If the Directory List Box is also attached then corresponding changes automatically performed in the Directory List Box. The Directory List Box has the following popular Methods: Drag Move SetFocus Refresh ZOrder etc

Directory List Box


The Directory List Box extends List of directory present in the Drive List Box. That means, without Drive List Box, Directory List Box can not be work properly. The user can select any directory List Box and corresponding List of Files are displayed in the file list Box if the path is properly specified. The path should be specified in the change event in the Directory List Box. The popular properties of Directory List Box are:-

Appearance BackColor Enabled Font Index List ListCount ListIndex Name

32

Path Visible etc


The Path property is a run time property. That sets or returns the path to the Directory in the Directory List Box. It is usually accessed in the change event for the Drive List Box. the path property is also used in the Directory List Box. Directory List Box change event to update the list of files in the File List Box. The popular events present in the Directory List Box :-

Change Click KeyPress KeyUp GotFocus LostFocus MouseDown MouseUp Scroll etc.
The change event will automatically triggered or called when any changing is performed in the Directory List Box to select other Directories. The popular methods present in the Directory List Box:-

Drag Refresh Move SetFocus etc.

File list box


The file List Box is present at the list of Drive, Directory and File List Box. It is used to list the actual file names which are currently present in the selected directory in the directory list box. That means file List Box can not be work properly without directory list box. User can select any file from the file list box. To open the file or display the content of the file as then choice of the user the content of file list Box will automatically changed if the path property is set under the change event of directory list box.

33

The popular properties of File List Box are: Appearance BackColor Enable FileName Font Hidden List ListCount ListIndex Name Path Pattern Selected Visible etc. The File Name Property returns the name of the file which is currently selected. The hidden property hide the List Box same as visible property. This property is by default False this property is useful for system files. The path property is used to set the directory name thats content will be displayed in the file list box. The pattern property is used to set the pattern or type of the file which are displayed in the file list box. For Example:-

*.* indicates all file *.cpp Displayed all cpp files *.java Displayed all java files
The file list box has the following popular events :Click DblClick KeyPress KeyUp LostFocus GotFocus MouseDown MouseUp

34

Path Change PatternChange Scroll etc. The path change events occur when the file path properties changed. Similarly the pattern change event called automatically when the pattern property is changed. The popular Methods present in file list box: Move Refresh SetFocus etc.

FRAME
Frame control is a sub container as form which can contain any other control present in the ToolBox to form a new group. Generally in a particular form only one radio button can be selected at a time. It is not possible to select more then one radio button at a time in a particular form. But in some situation more then one Radio Button should be selected of different groups at a time. To implement the concept of grouping of radio button as well as check boxthe frame control is used to form different groups. User can drop any number of frames on a particular form and can design more then one groups of radio button as well as check box. It is possible to select a single radio button from each group. Ultimately more then one Radio Button can be selected at a time by grouping then using the frame control. The popular properties of Frame are: Appearance BackColor BorderStyle Caption Enabled Font Name Visible etc. The Frame control has the following popular events: Click DblClick

35

MouseMove MouseUp MouseDown etc. Frame control has the following popular methods: Drag Move Refresh etc.

Radio Button
Radio Button is a Boolean type control thats value can be true or false. Radio Button is also called option Button. If the Button is selected then the value is true other wise it is false. The default value is false. It is not possible to select more then one Radio Button in a particular group. If user wants to select more then one Radio Button then the concept of grouping should be used using the frame control. The Radio Button control has the following popular properties: Alignment Caption Enabled Font Appearance BackColor Name Picture Style Value Visible etc. Radio Button has the following popular events:Click DblClick GotFocus Lostfocus KeyPress Keyup MouseMove

36

MouseUp MouseDown etc. The Radio Button has the following popular methods: Drag Move SetFocus etc.

Check Box
The Check Box control is as same as Radio Button but more then one check box can be selected at a time of a particular group. The other difference is the check box has three value ON, Off and Grayed (neither ON nor Off). If the check box is selected then the value is 1, if it is not selected then the value is 0 (zero), if it is grayed then the value is 2. Check Box has the following popular properties: Alignment Appearance BackColor Style Caption TabIndex DataSource DataField Enabled Font Index Name Value visible etc. The Check Box has the following popular events: Click GotFocus LostFocus KeyPress KeyUp MouseMove

37

MouseUp MouseDown etc.

Check Box has the following popular Methods:Drag Move Refresh SetFocus etc

Timer
The Timer is one of the most important and popular control present in the Tool Box. Those type of task which can be automatically executed should be present under the Timer event. The Timer control has only one event- that is Timer. User should writes the codes which will be executed automatically until the Timer enabled property False. Timer control is not displayed at the time of execution on the container. Timer has the properties Enabled, Interval etc. the enabled property is by Default True. If it is False then the Timer will not work. The interval is by default 0(zero). That means the cycle will appear after 0 mili second. User can set the Interval as the requirement of the user. The Timer control has no methods.

SHAPE
The Shape control is used to draw different Shapes like square, rectangle, circle, oval etc. using this control user can display different predefine shapes by supplying value of the Shape property of the Shape Control. The Shape control can draw six types of predefine Shapes as:-

0 - Rectangle (By Default) 1 - Square 2 - Oval 3 Circle 4 - Rounded Rectangle

38

5 Rounded Square The Shape control has the following popular properties: Name BackColor BorderStyle BorderWidth FillColor FillStyle Shape Visible etc The Shape control has no events and no Methods.

Ques :- Discus the various type of application that can be created in visual basic ?
Ans :- Visual Basic is a front end programming language to design appropriate interface to interact with the data base present in other programming language like Oracle, SQL server etc. Although it is a front end tool but any type of application except system software can be developed using visual basic. Using Visual Basic stand alone application can be develop as the requirement of the user by providing attractive interface to the user it is also possible to developed web based application is Visual Basic to monitor the network system as well as the communication rate, type etc. It is also possible to embed other application in visual basic application. Using the concept of OLE and user can concurrently execute more than one program in a visual basic application. Visual Basic application are divided in various categories and they are generally standard exe, ActiveX exe, ActiveX Dll, ActiveX Control, Add-In, DHTML application etc. Standard exe application is general type of application in visual basic which is used to develop stand alone application using the visual basic control. In visual basic three types of controls are present of develop visual basic application. All the three types are commonly known as ActiveX control. ActiveX control are divided in three categories as:-

1. Control

Common ActiveX

39

2. ActiveX Control 3. Controls or Component

User Created Extra ActiveX

Common ActiveX controls are those controls which are commonly used in visual basic application and present in the tool box automatically. Common ActiveX Controls are generally pointer Picture Box, Frame, Command Button, Label etc. User can create ActiveX controls as the choice of the user by clicking on add user control menu item present under the project menu using this option user can create any type of control for their later application. An application can also be treated as a control for the later application. Besides the above two controls huge no of extra control are present in visual basic which are commonly known as components. Components can be added by clicking on components present under project menu. It is also possible to add component by right clicking on tool box and click on components. Generally extra components are Status Bar, Tool Bar, Image List Box, Flex Grid Control and all the components present in the list. ActiveX exe applications are those type of application which are used to create common classes as well as modules, which can be used in any visual basic application. That means ActiveX exe applications are created as templet and can be used in any visual basic application. Using the concept user can create common classes, functions, modules for their own and can be shared with any VB application. That means ActiveX exe are generally by default for all other application. The ActiveX Dll is same as Active exe. The ActiveX exe is used internally as a exe file. That means ActiveX exe can not be work without crating exe file. But this concept is not true for Dll, Dll components are executed by the VB interpreter when the actual application is executed. Dll statements are treated as a simple VB statement and executed as simple statement. ActiveX exe statements are directly executed without interpreting it.

Ques :- What do you understand by a tool bar. List down the various step to create a new Tool Bar? Ans :- Tool Bar is a horizontal single line container which contain different
buttons (Command Button) with images (Optional) to perform different task assigned with the corresponding buttons. Fore example in visual basic IDE

40

the second horizontal line contains different symbols for the popular operations as well as controls necessary visual basic application. This line is called standard tool bar which is given in the VB IDE. User can create this type of tool bar as the requirement of the user to perform different task assigned in the tool bar components. User can create own tool bar which is present under the component Microsoft windows common control 6.0

Step to create a Tool Bar


1. 2. 4. 5. 6. Right click on tool box Click on Component 3. Select Microsoft windows common control 6.0 and click on check box besides the option click on apply and close. All the common controls are visible in the tool box. Double click on the tool bar control. The tool bar is visible in the upper horizontal position of the form. 7. Right click on tool bar and click on properties after that click on button tool start adding buttons by click on insert button and specify caption, Keys, Style, Tool tip text, Separator etc. On the buttons present in the tool bar. It is also possible to remove existing buttons by click on remove button option. 8. Click on Ok. If user wants to assign images on the button then double click on image list control present in the tool box. 9. Right click on image list and click on images button. 10. picture for the list To insert picture in the image list. Click on insert picture button and select at last click on apply and Ok. 11. Right click again on tool bar and click properties. Under general operation select the image list menu. Beside image list and click on apply and Ok.

Ques :- What do you mean by user interface. Discus the various uses of user interface and their use?
Ans :- User interface is the interaction point on which user can interact with the application and can perform various operations associated with the interaction point user generally interact with the controls present in the main container form and active other interfaces. In visual Basic two types of interfaces are present. 1. 2. Modal Modeless

41

Modal interfaces are those interfaces before closing it other interfaces cannot be work. Modeless interfaces are those interfaces in which user can work concurrently. Generally MDI applications are modeless and SDI applications can be modal as well as modeless as the choice of the user. A modal dialog box does not allow the user to continue with other application unless it is closed. The modeless dialog box allows shifting of focus between the dialog box and another for without closing the dialog box. Message box and input boxes is modal dialog box. It is also possible to display a form as a dialog box in modal or modeless form. In Visual basic three types of dialog boxes are present according to the creation of the dialog boxes. 1. Predefined dialog box 2. Standard dialog box 3. Custom dialog box Predefined dialog boxes are generally message box and input box which can be displayed any where and in any application as the choice of the user. It is not necessary to add any control to handle dialog boxes. Common dialog boxes are also predefined dialog boxes which can be arise in any application with the help of common dialog box. It is not possible to open common dialog boxes without using common dialog control. Common dialog boxes are also modal dialog boxes. Custom dialog boxes are those dialog boxes which are created by the user using form and appropriate control and which can be used in visual basic application as a modal or modeless form. Message box is a predefined modal dialog box to display any thing on a predefine form to general form of message box. msgBox(message, dialog type, title) The message is a string which is displayed on the message box and should be supplied by the user. The dialog type specifies which buttons are displayed on the message box, that default value is VbOk. Any dialog type can be used in message box which are allowed in Visual Basic. It is also possible to supply integer values corresponding to dialog type. The type is also a string which should be supplied by the user. If the dialog type is provided by the user then the message box returns an integer value corresponding to the clicked button on the message box. User can test the clicked button which is clicked by the user according to the return value of

42

the user. Input box is also a predefined dialog box of modal type. The input box always returns a string value and can take two string type arguments. The first argument is displayed as a message to the user on the input box. The second argument is displayed as a title on the caption of the form. It is possible to display a form as a dialog box in visual basic application. User can add a form in any visual basic application using the add form tools present in standard tool bar or under the project menu. The form should be hidden in the load event of the main form. User can display the form by calling any sub routine or function and write the statement.

Ques. How do we create variable in VB? Discuss the various types of variables that can be used in VB programming with suitable example in each.
Ans. Variables is those types of elements thats value can be changed during program execution. Alternately we can say that variable is the name of memory location, thats value can be changed during program execution. In Visual Basic variables are created using the Dim keyword as-

Dim Variable name as type of variable


Dim is a keyword which is used to create any type of variable. Variable name must be start with an alphabet and up to 255 character of length. Variable name is not case sensitive in Visual Basic. As is also a keyword used before the actual type of the variable. In Visual Basic the following primitive types are present.

1. 2. 3. 4. 5. 6. 7. 8.

Integer Long Byte Boolean Single Double Currency Date

43

9. 10.

Variant String

Besides the above type user can create any type of variable as the requirement of the user by using the type and end type keyword. Suppose user wants to create a new type student in which name, roll, class, year fields are present to it can be possible as:-

Private type student Name as string Roll as integer Class as string Year as integer End type
In the above student is an user defined data type in which name, roll, class and year are fields of corresponding type. A is a single Dimensional array of 100 blocks of student types. User can store 100 records in the array A. It is also possible to declare variable of existing object type. For Example:Suppose a form is created and user wants to create another form as same as form1. it is possible as:-

Dim N Form As New Form1 N Form.Show


It is also possible to create any type of variable present in the Tool Box and in the Component Dialog Box. It is also possible to create variable of User Defined Classes created using Active EXE, ActiveX DLL etc. For example. Example [kqn ls nsa

44

Ques. What is a form? Why do we use it? Explain the procedure for loading and unloading forms, showing and hiding forms. How can one form be controlled from within another? Explain.
Ans. A form is the main container to contain different types of controls present in the Tool Box or in the component dialog box or created by the user. Form is a main class in which other classes can be inherit and corresponding action can be taken by the component according to the requirement of the user. In Visual Basic automatically one form is arise in any application which is form 1. All the other components can be present on the form. Without form components can not visible in Visual Basic application. i.e, form is the main interface provided in Visual Basic application to interact with the application. To load a form a method load is present. The Load Method actually load the form in the primary memory as well as the components present in the form. The load methods also show the form. That means, activate the form. The unload method is used to release the form from the primary memory. When a form is unload then the form as well as the components present on the form release from the primary memory. The Hide Method just Off the visibility of the form. The Hide method can not release the form and components from the primary memory. The Show method is used to display a form as well as all components of the form. The Hide and Show method can not be work if the form is unloaded. In Visual Basic more then one form can be present in a single application and controlled from one another. In Visual Basic application the default application style is SDI (Single Document Interface) up to Visual Basic 5 only the concept of SDI was present. But in Visual Basic 6 a new concept MDI (Multiple Document Interface) is present.

45

In SDI (Single Document Interface) a single interface can be work at a time and the others are inactive. It is not possible to active more then one interface at a time. But in MDI (Multiple Document Interface) more then one interface can be active at a time and all the interfaces are present entirely in a parent interface. That means, in MDI (Multiple Document Interface) parent child relation ship is build. All the child interfaces are entirely present within the parent interface. Out side of the parent interface, no document can be present.

You might also like