You are on page 1of 19

1.

What is MDI, Explain with example

MDI stands for Multiple Document Interface. A MDI is used for opening many windows at the same time. All the document windows are contained in a parent window, which provides document area in which we can place controls. Visual basic application can have only one MDI form, which contains all the child forms. A child form is an ordinary form that has its Child Property set to TRUE. Child forms are displayed within the internal area of a MDI form at run time.

Creating an MDI Application For creating MDI application, we require atleast two forms, the MDI form and a child form. The given example is similar to the Notepad application in windows. Each time, the user clicks New from the File menu, a new child window is created and displayed. Example Object MDIform1 Form1 Text1 A new standard EXE project is opened. The MDI Form is inserted by selecting Add MDI form from the project menu. Now the project contains a Standard form and a MDI form. The project is saved as .VBP extension. A text Box is added in the standard form. The two forms are designed as per the following specification Property Caption Caption MDIChild MultiLine Text Left Top Height Width Scroll Bar Setting Parent Form Child Form True True (Empty) 0 0 2295 3015 3-Both

Menu items are added to the MDI form as per the following specifications. Caption &File ..&New ..&Exit &Window ..&Cascade ..&Tile Name Mnufile Mnunew Mnuexit Mnuwindow Mnucascade mnutile

The following code is entered in the mnunew_Click() Private sub mnunew_click() Dim newform as new form1 Newform.show End sub The first statement in the above procedure declares a variable class newform as a copy of the child form Form1. This implies that, for all purposes the NewForm can be referred to as an instance of the form1. The following code is entered in the mnutile_Click() procedure of the MDI form Private sub mnutile_click() Mdiform1.arrange vbtilehorizontal End sub The following code is entered in the mnucascade_click() procedure of the MDI form Private sub mnucascade_click() Mdiform1.arrange vbcascade End sub The following code is entered in the mnuexit_click() procedure Procedure sub mnuexit_click() End End sub 2. Explain VB IDE (Integrated Development Environment)

Integrated Development Environment is very first screen in VB to develop applications. It contains various components. It is graphical user interfaces that supports to develop applications in a easy way. Tha Visual Basic IDE is made up of a number of components

Menu Bar

Tool Bar Project Explorer Properties window Form Layout Window Toolbox Form Designer Object Browser

Menu Bar This Menu Bar displays the commands that are required to build an application. The main menu items have sub menu items that can be chosen when needed. There are different menu options, they are File, Edit, View, Project, Format etc., Toolbox The Toolbox contains a set of controls that are used to place on a Form at design time thereby creating the user interface area. Additional controls can be included in the toolbox by using the Components menu item on the Project menu.

Figure 2 Toolbox window with its controls available commonly.

Control Pointer PictureBox TextBox Frame CommandButton CheckBox OptionButton ListBox ComboBox

Description Provides a way to move and resize the controls form Displays icons/bitmaps and metafiles. It displays text or acts as a visual container for other controls. Used to display message and enter text. Serves as a visual and functional container for controls Used to carry out the specified action when the user chooses it. Displays a True/False or Yes/No option. OptionButton control which is a part of an option group allows the user to select only one option even it displays mulitiple choices. Displays a list of items from which a user can select one. Contains a TextBox and a ListBox. This allows the user to select an ietm from the dropdown ListBox, or to type in a selection in the TextBox.

Project Explorer It is available on the right side of the screen, just under the tollbar, is the Project Explorer window. The Project Explorer as shown in figure serves as a quick reference to the various elements of a project namely form, classes and modules. Properties Window

The Properties Window is available under the Project Explorer window. The Properties Window exposes the various characteristics of selected objects. Each and every form in an application is considered an object. Now, each object in Visual Basic has characteristics such as color and size etc., Object Browser The Object Browser allows us to browse through the various properties, events and methods that are made available to us. It is accessed by selecting Object Browser from the View menu or pressing the key F2. 3. Explain DHTML, with example

DHTML stands for Dynamic HTML. A DHTML application is a group of HTML pages that work together to perform a business process. We write Visual Basic code to handle events that occur when these pages are viewed in the browser. We can respond to events that occur on any element on the page from clicking a button to loading an image to passing the mouse over a certain part of the page. Most of the processing associated with a DHTML application occurs on the client computer, although the application can make calls to the server. However, performing the majority of processing on the client (in this case, the browser) allows your applications to respond quickly to user actions without making time-consuming trips to the server. In addition, corporations can lower the cost of training and support associated with their applications by presenting commonly used information and applications through the browser.
Structure of DHTML Applications

DHTML applications are made up of the following pieces:


One or more HTML pages. Visual Basic code that handles the events generated from the HTML pages. A run-time component that hosts the page in the Web browser or Web browser control. A project DLL that contains your Visual Basic code and is accessed by the run-time component, generated automatically when you debug or compile.

There is a one-to-one relationship between the designers and the HTML pages in your project. For each page in your application, there is a page designer. Example Let us build an application that displays a page with different text formats and levels of headings

Start a new project and select DHTML Application as the project type. From the Project Explorer window, open DHTML page designer by double clicking on the page. If you are designing your user interface from scratch, add HTML elements and ActiveX controls to your page and arrange them as desired. If you want to edit an existing page, use the Properties dialog box to refer an external HTML file, then make any necessary changes to the page's contents and appearance. Add code for any elements on the page for which you want to handle user actions. If necessary, add other pages to the project, add elements to them, and write code. Test and debug the application by running the project and viewing the document in Internet Explorer 4.01 or later. Compile the project. Deploy the application using the Package and Deployment Wizard. Saving a DHTML page 4. Explain different types of modules

Code in Visual Basic is stored in the form of modules. The three kind of modules are Form Modules, Standard Modules and Class Modules. A simple application may contain a single Form, and the code resides in that Form module itself. As the application grows, additional Forms are added and there may be a common code to be executed in several Forms. To avoid the duplication of code, a separate module containing a procedure is created that implements the common code. This is a standard Module. Class module (.CLS filename extension) are the foundation of the object oriented programming in Visual Basic. New objects can be created by writing code in class modules. Each module can contain: Declarations : May include constant, type, variable and DLL procedure declarations. Procedures : A sub function, or property procedure that contain pieces of code that can be executed as a unit. These are the rules to follow when naming elements in VB - variables, constants, controls, procedures, and so on: A name must begin with a letter. May be as much as 255 characters long (but don't forget that somebody has to type the stuff!). Must not contain a space or an embedded period or type-declaration characters used to specify a data type; these are ! # % $ & @ Must not be a reserved word (that is part of the code, like Option, for example) The dash, although legal, should be avoided because it may be confused with the minus sign. Instead of First-name use First_name or FirstName. 5. Explain different Data types

By default Visual Basic variables are of variant data types. The variant data type can store numeric, date/time or string data. When a variable is declared, a data type is supplied for it that determines the kind of data they can store. The fundamental data types in Visual Basic including variant are integer, long, single, double, string, currency, byte and boolean. A list of Visual Basic's simple data types are given below. 1. Numeric Byte Integer Long Single Double Currency 2. String Use to store alphanumeric values. A variable length string can store approximately 4 billion characters 3. Date Use to store date and time values. A variable declared as date type can store both date and time values and it can store date values 01/01/0100 up to 12/31/9999 4. Boolean Boolean data types hold either a true or false value. These are not stored as numeric values and cannot be used as such. Values are internally stored as -1 (True) and 0 (False) and any non-zero value is considered as true. 5. Variant Stores any type of data and is the default Visual Basic data type. In Visual Basic if we declare a variable without any data type by default the data type is assigned as default. 6. Explain different types of procedures in Visual Basic Store integer values in the range of 0 - 255 Store integer values in the range of (-32,768) - (+ 32,767) Store integer values in the range of (- 2,147,483,468) - (+ 2,147,483,468) Store floating point value in the range of (-3.4x10-38) - (+ 3.4x1038) Store large floating value which exceeding the single data type value store monetary values. It supports 4 digits to the right of decimal point and 15 digits to the left

Visual Basic programs can be broken into smaller logical components called Procedures. Procedures are useful for reducing repeated operations such as the

frequently used calculations, text and control manipulation etc. The benefits of using procedures in programming are: It is easier to debug a program a program with procedures, which breaks a program into discrete logical limits. Procedures used in one program can act as building blocks for other programs with slight modifications. A Procedure can be Sub, Function or Property Procedure. Sub Procedures A sub procedure can be placed in standard, class and form modules. Each time the procedure is called, the statements between Sub and End Sub are executed. The syntax for a sub procedure is as follows: [Private | Public] [Static] Sub Procedurename [( arglist)] [ statements] End Sub arglist is a list of argument names separated by commas. Each argument acts like a variable in the procedure. There are two types of Sub Procedures namely general procedures and event procedures.
Event Procedures

An event procedure is a procedure block that contains the control's actual name, an underscore(_), and the event name. The following syntax represents the event procedure for a Form_Load event. Private Sub Form_Load() ....statement block.. End Sub Event Procedures acquire the declarations as Private by default. Function Procedures Functions are like sub procedures, except they return a value to the calling procedure. They are especially useful for taking one or more pieces of data, called arguments and performing some tasks with them. Then the functions returns a value that indicates the results of the tasks complete within the function. The following function procedure calculates the third side or hypotenuse of a right triangle, where A and B are the other two sides. It takes two arguments A and B (of data type Double) and finally returns the results.

Function Hypotenuse (A As Double, B As Double) As Double Hypotenuse = sqr (A^2 + B^2) End Function The above function procedure is written in the general declarations section of the Code window. A function can also be written by selecting the Add Procedure dialog box from the Tools menu and by choosing the required scope and type. 5. Explain different control Statements in VB Control Statements are used to control the flow of program's execution. Visual Basic supports control structures such as if... Then, if...Then ...Else, Select...Case, and Loop structures such as Do While...Loop, While...Wend, For...Next etc method. If...Then The If...Then selection structure performs an indicated action only when the condition is True; otherwise the action is skipped. Syntax of the If...Then selection If <condition> Then statement End If e.g.: If average>75 Then txtGrade.Text = "A" End If
If...Then...Else selection structure

The If...Then...Else selection structure allows the programmer to specify that a different action is to be performed when the condition is True than when the condition is False. Syntax of the If...Then...Else selection If <condition > Then statements Else statements End If e.g.: If average>50 Then txtGrade.Text = "Pass" Else txtGrade.Text = "Fail" End If

Select...Case : Select..Case structure is an alternative to If...Then...ElseIf for selectively executing a single block of statements from among multiple block of statements. Syntax of the Select...Case selection structure Select Case Index Case 0 Statements Case 1 Statements End Select e.g.: Assume you have to find the grade using select...case and display in the text box Dim average as Integer average = txtAverage.Text Select Case average Case 100 To 75 txtGrade.Text ="A" Case 74 To 65 txtGrade.Text ="B" Case 64 To 55 txtGrade.Text ="C" Case 54 To 45 txtGrade.Text ="S" Case 44 To 0 txtGrade.Text ="F" Case Else MsgBox "Invalid average marks" End Select 7. Explain different looping statements

Looping statements allows to execute group of statements continuously until the condition is false.
Do While... Loop Statement

The Do While...Loop is used to execute statements until a certain condition is met. The following Do Loop counts from 1 to 100. Dim number As Integer number = 1 Do While number <= 100 number = number + 1 Loop

A variable number is initialized to 1 and then the Do While Loop starts. First, the condition is tested; if condition is True, then the statements are executed. When it gets to the Loop it goes back to the Do and tests condition again. If condition is False on the first pass, the statements are never executed. While... Wend Statement A While...Wend statement behaves like the Do While...Loop statement. The following While...Wend counts from 1 to 100 Dim number As Integer number = 1 While number <=100 number = number + 1 Wend
Do...Loop While Statement

The Do...Loop While statement first executes the statements and then test the condition after each execution. The following program block illustrates the structure: Dim number As Long number = 0 Do number = number + 1 Loop While number < 201 The programs executes the statements between Do and Loop While structure in any case. Then it determines whether the counter is less than 501. If so, the program again executes the statements between Do and Loop While else exits the Loop. Do Until...Loop Statement Unlike the Do While...Loop and While...Wend repetition structures, the Do Until... Loop structure tests a condition for falsity. Statements in the body of a Do Until...Loop are executed repeatedly as long as the loop-continuation test evaluates to False. An example for Do Until...Loop statement. The coding is typed inside the click event of the command button Dim number As Long number=0 Do Until number > 1000 number = number + 1 Print number Loop

Numbers between 1 to 1000 will be displayed on the form as soon as you click on the command button. The For...Next Loop The For...Next Loop is another way to make loops in Visual Basic. For...Next statement allows to execute all statements until it reaches the end value. Dim x As Integer For x = 1 To 50 Print x Next In order to count the numbers from 1 to 50 in steps of 2, the following loop can be used For x = 1 To 50 Step 2 Print x Next The following loop counts numbers as 1, 3, 5, 7..etc 8. Explain Arrays in Visual Basic

A Sequence of values by the same name can be referred using arrays. The individual elements of an array are identified using an index. Arrays have upper and lower limits and the elements have with in the bounds. Each index number represents the position where the value is going to store in the array. There are 2 types of arrays in visual basic namely

Fixed-size array : The size of array always remains the same Dynamic array : The size of can be changed at run-time

Fixed Size Arrays : Fixed arrays can be declared by giving a name to the array with the upper limit in the parentheses. The upper limit should always be within the range of Long data type. Dim n(9) as Integer In the above declaration, n is the name of the array, and the number 9 included in the parentheses is the upper limit of the array. The above declaration creates an array with 10 elements, with index numbers running from 0 to 9. Multidimensional Arrays : A multidimensional array is used when we need to represent or store related information of different dimensions. In the multidimensional array values are stored in rows and columns. Each item is identified with row and column number.

Ex: Dim marks(50,50) The above declaration created an array with 50 rows and 50 columns in the array. Each item is identified with row and column number Dynamic Arrays : There will be a situation when the user may not know the exact size of the array at design time. Under such circumstances, a dynamic array can be initially declared and can add elements when needed instead of declaring the size of the array at design time. Dim n() The actual number of elements can be allocated using ReDIM statement. This example allocates the number of elements in the array based on the value of the variable Y. Redim n(y+1) Explain OLE container Control The OLE container control allows adding objects from other applications. An OLE control can have only one object at a time. Using OLE control we can

Create a placeholder in our application for an object Create a linked object in our application Bind the OLE container control to a database Create objects from data that was copied onto the clipboard Display objects as icons Perform an action if the user moves, size or updates the objects in the OLE control Provide backward compatibility with an application that includes many OLE container controls.

Creating Objects at Design time Each time an OLE control is drawn on a form, an Insert Object dialog box appear, which presents list of the available objects that can be linked to or embedded in the application. When an object is inserted into the OLE control at design time, the Class, SourceDoc and SourceItem properties that identify the application that supplies the object, the source filename and any specific file that is linked from within that file are automatically set. The following example creates a linked object using Insert Object dialog box.

This example creates link from an existing applications An OLE control is drawn on the form. This display a InsertObject dialog box The create from file Option is clicked and the browse button is chosen. A Browse dialog box appears

The desired file is selected from the directory and the OK button is clicked. The InsertObject box is displayed again. The Link CheckBox is selected and the OK button is clicked. Explain different controls in VB

9.

A control is an object that can be drawn on a Form object to enable or enhance user interaction with an application. Controls have properties that define aspects their appearance, such as position, size and colour, and aspects of their behavior, such as their response to the user input. They can respond to events initiated by the user or set off by the system. For instance, a code could be written in a CommandButton control's click event procedure that would load a file or display a result. In addition to properties and events, methods can also be used to manipulate controls from code. For instance, the move method can be used with some controls to change their location and size. Most of the controls provide choices to users that can be in the form of OptionButton or CheckBox controls, ListBox entries or ScrollBars to select a value. Let us discuss these controls by means of a few simple applications in the following lessons. Classification of Controls Visual Basic cojntrols are broadly classified as standard controls, ActiveX controls and insertable objects. Standard controls such as CommandButton, Label and Frame controls are contained inside .EXE file and are always included in the ToolBox which cannot be removed. ActiveX controls exist as separate files with either .VBX or .OCX extension. They include specialized controls such as;

MSChart control The Communications control The Animation control The ListView control An ImageList control The Multimedia control The Internet Transfer control The WinSock control The TreeView control The SysInfo control The Picture Clip control

Some of these objects support OLE Automation, which allow programming another application's object from within Visual Basic application. I would like to stress that knowing how and when to set the objects' properties is very important as it can help you to write a good program or you may fail to write a good program. So, I advice you to spend a lot of time playing with the objects' properties Here are some important points about setting up the properties

You should set the Caption Property of a control clearly so that a user knows what to do with that command. For example, in the calculator program, all the captions of the command buttons such as +, - , MC, MR are commonly found in an ordinary calculator, a user should have no problem in manipulating the buttons. A lot of programmers like to use a meaningful name for the Name Property may be because it is easier for them to write and read the event procedure and easier to debug or modify the programs later. However, it is not a must to do that as long as you label your objects clearly and use comments in the program whenever you feel necessary One more important property is whether the control is enabled or not Finally, you must also considering making the control visible or invisible at runtime, or when should it become visible or invisible

TabIndex property of Controls Visual Basic uses the TabIndex property to determine the control that would receive the focus next when a tab key is pressed. Every time a tab key is pressed, Visual Basic looks at the value of the TabIndex for the control that has focus and then it scans through the controls searching for the next highest TabIndex number. When there are no more controls with higher TabIndex value, Visual Basic starts all over again with 0 and looks for the first control with TabIndex of 0 or higher that can accept keyboard input. By default, Visual Basic assigns a tab order to control as we draw the controls on the Form, except for Menu, Timer, Data, Image, Line and Shape controls, which are not included in tab order. At run time, invisible or disabled controls also cannot receive the focus although a TabIndex value is given. Setting the TabIndex property of controls is compulsory in development environment. 10. Active X Control

ActiveX controls are a special type of ActiveX component. Therefore, most of the ActiveX concepts discussed in Chapter 14, "Creating an Active Document," apply directly to the subject of ActiveX controls. In particular, an ActiveX control has the following notable features of any ActiveX component class:

Programmer-definable properties Programmer-definable methods Programmer-definable events

Moreover, you can implement these custom-definable members of the ActiveX control class in the same way that you implement customized members of other ActiveX components. Of course there are special considerations for ActiveX control members (especially properties), and we discuss the specifics of ActiveX control members in the rest of this chapter.
Standalone (OCX) ActiveX Controls

Just as you can distribute stand-alone compiled ActiveX components in the form of DLL or EXE files, you can also distribute compiled ActiveX controls in separate OCX files to other programmers and end users. An OCX is another type of DLL that lives in a host application. To create an OCX file implementing one or more custom controls, you create a special ActiveX control project containing the ActiveX components you wish to distribute. Each ActiveX component will be implemented with source code in its own file (extension .CTL). When you follow the steps to create an ActiveX control as described in the rest of this chapter, you then can compile the project into an OCX. ActiveX Controls in Other Projects An ActiveX control can also form part of another VB project. In that case, you would include the control's CTL file as part of a Standard EXE or ActiveX EXE or DLL project. You might choose to implement an ActiveX control as part of another project when the control's function is so specialized that it would never be used outside its host application. You might also keep an ActiveX control inside other projects to prevent other programmers from accessing it independently. You can also accomplish the goal of keeping your control proprietary, however, by using a licensing scheme described in "Licensing and Distributing Your ActiveX Control." To implement your own ActiveX control, you must take the following basic steps:

Put a UserControl container into your application. This object is implemented in its own separate file similar to a Form. The UserControl provides the basis for the control. If you decide to implement user-drawn features in your control, you must plan and implement those raphic features, putting code in the appropriate event procedures. Create custom methods and events in the UserControl as you would in a Class Module. Create custom properties in the UserControl as you would in a Class Module, remembering to make extra provision for property persistence. If you decide to implement constituent controls, then you must place any constituent controls that you will be using on the UserControl's surface and implement their delegated methods, delegated events, and delegated properties as well. Put additional code in UserControl event procedures so that you initialize your control's properties appropriately and cause them to persist. or Explain ActiveX DLL ( please replace EXE with DLL)

Explain Active X EXE

Visual basic can be used to create ActiveX components. These components can either take the form of DLLs or EXE. These components are used to perform operations directly.

The ActiveX EXE component is an out-of-process server, which can be developed and run independently. These can be included in the client application after they are compiled and registered. Creating ActiveX Components:

An activeX component can be created in VB by starting a new project. The ActiveX EXE or ActiveX DLL is chosen depending on the type of project to be created. The new project is created with a single class module. If needed, additional classes can be included to the project. Suitable code to be written for the classes. Finally compile the project into an ActiveX DLL or EXE

Example Let us develop a Calculator to perform the simple arithmetic calculations such as

Addition Subtraction Multiplication Division Modulus

There are three major steps involved as given below


To Create the Calculator which is the ActiveX EXE component To compile this component and register To test the component with our client test applications To Create the Calculator (ActiveX EXE component) To start with, go to program->Visual Basic 6.0> and the New Project dialog box opens, from which select ActiveX EXE To open into a class module namely Class1 by default similar to a form into a standard EXE project Press F4 to edit the properties and set the properties of the class module Write the following function for calculations Public function add(a as single, b as single) as double Addn=a+b End function Public function diff(a as single, b as single) as double Diff=a-b End function Public function prod(a as single, b as single) as double Addn=a*b

1.

End function Public function Div(a as single, b as single) as double Addn=a/b End function Finally running select File->Save Project As and save it as <any filename.vbp> and the class module as <filename.cls>

How to create Menus Visual basic creates supports to creates menus easily with the help of Menu editor. A menu is a list of commands that is used to select easily. Visual basic supports to create pull down menus and shortcut menus. A menu editor can be used to add new commands to the existing menus, create new menus and menu bars, change or delete existing menus and menu bars. To display a menu editor, Menu Editor command is chosen from the Tools menu or the menu editor button is clicked in the toolbar. Steps to create Menu A new standard EXE project is opened and the form and the project files are saved as colors.form and colors.vbp The form is designed as per the properties table given below Object Property Settings Form Caption Color/Size program Name frmColor

The menu items for the Form is designed as per the following specifications Caption &Colors .&FillColor .&Red .:&Green .&Blue &Size &Small .&Large

Name mnuColors mnufillcolor mnufillcolor mnufillgreen mnufillblue mnusize mnusmall mnularge

Create menu according to the above specifications given and name it given above. Once we create a menu, it will be automatically added on the menubar in your form. We can add additional code by writing simple procedure

Private sub mnured_click() Frmcolor.backcolor=qbcolor(4) Mnured.enabled=false Mnugreen.enabled=true Mnublue.enabled=true End sub

Additional Questions Data Environment and Data report Flex Grid control Add-Ins Graphics Shapes Read all 4 marks for last 2 years papers Read all 2 marks for last years old papers

You might also like