Paper : MS(A) 123 Visual Basic COMMON CONTROLS IN VISUAL BASIC

Size: px
Start display at page:

Download "Paper : MS(A) 123 Visual Basic COMMON CONTROLS IN VISUAL BASIC"

Transcription

1 Lesson No. 1 Paper : MS(A) 123 Visual Basic Author: Vishal Goyal COMMON CONTROLS IN VISUAL BASIC Introduction Objectives Creating User Interfaces with Windows Common Controls Drawing a control using Toolbox Resizing, Moving, and Locking Controls Writing Code Creating Menus for Programs Summary Self Understanding Further Readings 1.0 Introduction: The working environment in Visual Basic is often referred to as the Integrated Development Environment or IDE because it integrates many different functions such as design, editing, compiling and debugging within a common environment. In most traditional development tools, each of these functions would operate as a separate program, each with its own interface. The process of developing an application using Visual Basic as an IDE (VB-IDE) can be relatively simple. Using Visual Basic IDE, One can Draw pictures of your user interface on a form. Draw buttons, text boxes and other user-interface items (often called controls. Add little snippets of program code to handle the user interaction. Add, if required, access to outside data objects (databases) Code more complex functions. Add Help files for your application There are three main steps to creating an application in Visual Basic: 1. Create the interface. 2. Set properties. 3. Write code. Menus are the easiest way to give a user multiple options without creating a crowded display. It is also very easy to do. In most applications there are the standard menus: File, Edit, View, Window and Help. Users know what to expect to find on these menus. For example, on the File menu you always can open and save

2 2 files, or open a recent file and the View menu allows you to make changes to what you can see. If you start changing where you put these basic functions you will confuse the user. Stick to these and you will not go wrong. 1.1 Objective After completing this lesson, you will be able to: Define main steps involved in creating an interface Discuss steps for setting properties Explain how to write code Creating Menus for progrms 1.2 Creating user Interface with Windows Common Controls Forms are the foundation for creating the interface of an application. You can use forms to add windows and dialog boxes to your application. You can also use them as containers for items that are not a visible part of the application's interface. For example, you might have a form in your application that serves as a container for graphics that you plan to display in other forms. The first step in building a Visual Basic application is to create the forms that will be the basis for your application's interface. Then you draw the objects that make up the interface on the forms you create. For this first application, you'll use two controls from the Toolbox. 1.3 Drawing a control using the Toolbox 1. Click the tool for the control you choose to draw in this case, the text box. 2. Move the pointer onto your form. The pointer becomes a cross hair, as shown in Figure 1.1

3 3 Figure: Drawing a text box with the Toolbox 3. Place the cross hair where you want the upper-left corner of the control. 4. Drag the cross hair until the control is the size you want. (Dragging means holding the left mouse button down while you move an object with the mouse.) 5. Release the mouse button. 6. The control appears on the form. Another simple way to add a control to a form is to double-click the button for that control in the Toolbox. This creates a default-size control located in the center of the form; then you can move the control to another location on the form. 1.4 Resizing, Moving, and Locking Controls Notice that small rectangular boxes called sizing handles appear at the corners of the control; you'll use these sizing handles in the next step as you resize the control. You can also use the mouse, keyboard and menu commands to move controls, lock and unlock control positions and adjust their positions To resize a control 1. Select the control you intend to resize by clicking it with the mouse. Sizing handles appear on the control.

4 4 2. Position the mouse pointer on a sizing handle and drag it until the control is the size you choose. The corner handles resize controls horizontally and vertically, while the side handles resize in only one direction. 3. Release the mouse button. or Use SHIFT with the arrow keys to resize the selected control To move a control Use the mouse to drag the control to a new location on the form. or Use the Properties window to change the Top and Left properties. You now have the interface for the "Hello, world!" application, as shown in Figure 1.4. Figure: The interface for the "Hello, world!" application 1.5 Setting Properties The next step is to set properties for the objects you've created. The Properties window (Figure 1.3) provides an easy way to set properties for all objects on a form. To open the Properties window, choose the Properties Window command from the View menu, click the Properties Window button on the toolbar or use the context menu for the control.

5 5 Figure: The Properties window To set properties from the Properties window 1. From the View menu, choose Properties or click the Properties button on the toolbar. The Properties window displays the settings for the selected form or control. 2. From the Properties list, select the name of a property. 3. In the right column, type or select the new property setting. Enumerated properties have a predefined list of settings. You can display the list by clicking the down arrow at the right of the Settings box or you can cycle through the list by double-clicking a list item. For the "Hello, world!" example, you'll need to change three property settings. Use the default settings for all other properties.

6 6 Object Property Setting Form Caption Hello, world! Text box Text (Empty) Command button Caption OK 1.5 Writing Code The Code Editor window is where you write Visual Basic code for your application. Code consists of language statements, constants and declarations. Using the Code Editor window, you can quickly view and edit any of the code in your application. To open the Code window Double-click the form or control for which you choose to write code. or From the Project Explorer window, select the name of a form or module and choose the View Code button. Figure1.6 shows the Code Editor window that appears when you double-click the Command button control and the events for that command. Figure 1.4 The Code Editor window You can choose to display all procedures in the same Code window, or display a single procedure at a time. To display all procedures in the same Code window 1. From the Tools menu, select the Options dialog box.

7 7 2. On the Editor tab in the Options dialog box, select the check box to the left of Default to Full Module View. The check box to the left of Procedure Separator adds or removes a separator line between procedures. or Click the Full Module View button in the lower left corner of the Code Editor window. To display one procedure at a time in the Code window 1. From the Tools menu, select the Options dialog box. On the Editor tab in the Options dialog box, clear the check box to the left of Default to Full Module View. or Click the Procedure View button in the lower left corner of the Code Editor window. The Code window includes the following elements: Object list box Displays the name of the selected object. Click the arrow to the right of the list box to display a list of all objects associated with the form. Procedure list box Lists the procedures, or events, for an object. The box displays the name of the selected procedure in this case, Click. Choose the arrow to the right of the box to display all the procedures for the object. 1.6 Creating Menus for Programs Menus are the easiest way to give a user multiple options without creating a crowded display. It is also very easy to do. In most applications there are the standard menus: File, Edit, View, Window and Help. Users know what to expect to find on these menus. For example, on the File menu you always can open and save files, or open a recent file and the View menu allows you to make changes to what you can see. If you start changing where you put these basic functions you will confuse the user. Stick to these and you will not go wrong. The VB Menu system: Creating menus To create menus in VB you use the Menu Editor. You can find this under Tools Menu Editor. The VB Menu editor:

8 8 To create a top menu (i.e. File), use the following steps: 1) Select Tools Menu Editor 2) Enter the text to be displayed for the menu in the Caption text box (i.e. File). As always you can use the & to set the Shortcut key: So &File would display the menu File and could be accessed by Alt+F 3) Enter a name for the menu. This will be used when accessing the menu's properties in your code. 4) Make sure that there are no dots before File in the list box (i.e....file). If there are, press the < button on the dialog box until there are none. These will be explained later. 5) Click OK. If you have used the examples, you will now see something like this:

9 9 When you click the menu, you will see there are no Menu Items. This will be explained in the next section Creating menu items To create a menu item (i.e. Open, on the File Menu), use the following steps: 1) Select Tools Menu Editor 2) Click the item on the list after the menu you want this item to go on. (i.e. after File). If there is an item already there, click Insert: 3) 4) 5) Enter the text to be displayed for the menu item in the Caption text box (i.e. Open). As always you can use the & to set the Shortcut key: So &Open would display the menu item Open and could be accessed by Alt+O when the File menu is open Enter a name for the menu item. This will be used when accessing the menu's properties in your code. Press the > button once. You will see four dots (...) appear before the text Open. This shows that Open is a item on the menu File: 6) Click OK. If you have used the examples, you will now see something like this when you click on File: 7) To write some code that runs when a menu item is clicked, simply click the menu item during design time. A code window will open with a new procedure. Enter any code you want to run when the menu item is clicked here.

10 10 Window Lists If you are using a MDI Form in your application you will want a menu that lists all the open windows. To do this follow these steps: 1) Select the MDI form or MDI Child Form 2) Select Tools Menu Editor 3) Click the menu or menu item you want to list the open windows and check the box which says window list. 4) Click OK The menu will then list any windows you have open within the MDI Form. Creating Submenus In the Menu editor, you will notice that when you press the < and > buttons, dots will appear before the selected item. These show what item belongs to what. For example: &File...&Open...&Save...&Insert......&Text...&Image...&Close &Help...&About << << << << << << << << << Top Menu Menu item of File Menu item of File Menu item of File Sub Menu of Insert Sub Menu of Insert Menu item of File Top Menu Menu item of Help So, to create a sub menu, simply follow these steps: 1) Select Tools Menu Editor 2) Create a menu item which you want to contain the sub menu (which will have the > after it) i.e. Insert on the File menu 3) Insert an item after the menu item you have just created. (i.e. after Insert...). Click Insert: 4) Enter the text to be displayed for the sub menu item in the Caption text box (i.e. Text). As always you can use the & to set the Shortcut key: So &Text would display the menu item Text. 5) Enter a name for the menu item. This will be used when accessing the menu's properties in your code. 6) Press the > button until the item is indented once more than the menu you want to contain a sub menu. You will see four dots (...) appear before the text Open. This shows that Open is a sub menu item on the menu item Insert:

11 6) 11 Click OK. If you have used the examples, you will now see something like this when you click on File: Menu separators On menus you will notice menu separators like this: To do this in VB, simply use the following steps. 1) Select Tools Menu Editor 2) Click on the item on the list after the menu item you want the separator to be displayed after and click Insert. Make sure that there are the same number of before the item. If there is not use the < (reduce) and > (increase) buttons to change it. 3) Enter the a "-" (without quotes) in the Caption text box. This tells VB that this is a menu separator. 4) Enter a name for the separator and click OK. Checked menu items Sometimes you may want the user to be able to select options on the menu. You may have noticed other applications using Ticks or circles next to an item to show that this option is chosen. You can do this is VB too. All you have to do is change the checked property of the menu item. Note that when a checked menu item is clicked, VB will not automatically uncheck the item. The following example will check and un-check mnueditwordwrap and change the text in a label. For this example, create a menu called mnuedit, with a menu item called mnueditwordwrap. Also add a label control to the form.

12 12 Sub mnueditwordwrap_click() If mnueditwordwrap.checked = True ' We are checked - uncheck the menu item mnueditwordwrap.checked = False ' Set the label text Label1.Caption = "No Word Wrap" Else ' We are not checked - check the menu item mnueditwordwrap.checked = True ' Set the label text Label1.Caption = "Word Wrap" End If End Sub Popup menus VB allows you to easily create a popup menu like those you see in Explorer when you right click. All you need to do is create a menu, containing all the items you want displayed on the popup menu. Then, set the menus visible property to false, so it is not displayed on the forms menu bar. Now add the following code to the MouseUp event of any control on which you want the popup menu to be displayed when it is right clicked. If Button = vbrightbutton Then ' Set the flags vflags = vbpopupmenurightbutton ' Display the menu PopupMenu mnuedit, vflags End If The popupmenu function has the following parameters: PopupMenu PopupMenu, Flags, X, Y, DefaultMenu There are a few flags which you can set before displaying the menu. These are described below: vbpopupmenurightbutton Popup menu disappears when whether the left or right mouse button is clicked off the menu vbpopupmenuleftbutton Popup menu only disappears when the left mouse button is clicked off the menu vbpopupmenucenteralign Aligns the menu in the middle of where the mouse is clicked vbpopupmenuleftalign Aligns the menu to the left of where the mouse is clicked. vbpopupmenurightalign Aligns the menu to the right of where the mouse is clicked.

13 13 The X and Y parameters are optional, but you could use them to display the menu at a fixed point (ie next to a button that is clicked to display it). You can also display a default item in bold, by passing the menu item you want in its Default Menu parameter. 1.7 Summary: The working environment in Visual Basic is often referred to as the Integrated Development Environment or IDE. Forms are the foundation for creating the interface of an application. You can use forms to add windows and dialog boxes to your application. You can also use them as containers for items that are not a visible part of the application's interface. One can draw the objects that make up the interface on the forms. One can set various properties for the form objects. The Code Editor window is used to write Visual Basic code for your application. Code consists of language statements, constants and declarations. Using the Code Editor window, one can quickly view and edit any of the code in one s application. Menus are the easiest way to give a user multiple options without creating a crowded display. It is also very easy to do. In most applications there are the standard menus: File, Edit, View, Window and Help. Users know what to expect to find on these menus. For example, on the File menu you always can open and save files or open a recent file, and the View menu allows you to make changes to what you can see. 1.8 Self Understanding: 1. Explain the various features of Visual Basic Explain the difference between Visual Basic.Net and Visual Basic What are the various steps in creating user interfaces with Windows Common Controls? 4. What do you mean by Controls in VB? List various controls various controls and their purpose. 5. What are steps for setting properties for VB Form objects? 6. Explain various components of Visual Basic Form? 7. What are various steps for creating menus for programs? 1.9 Further Readings: Visual Basic 6.0 No Experience Required, BPB Publications. Mastering Visual Basic 6.0, BPB Publications. Visual Basic 6, Black Book by Steve Holzner, Paraglypu Press. Mastering Visual Basic 6 by Evangelos Petroutsos, Sybex. Sams Teach Yourself Visual Basic 6 in 24 hours by Greg Perry, Sams1999. Programming Microsoft Visual Basic 6.0 by Francesco Balena, Miscrosoft Press. The Complete Reference, Visual Basic 6 by Noel Jerke, Tata McGraw Hill. Web Resources

14 Paper : MS(A) 123 Visual Basic Lesson No. 2 Author: Vishal Goyal CASE STUDIES Structure: 2.0 Introduction 2.1 Objectives 2.2 Case study Case Study Summary 2.5 Further Readings 2.0 Introduction: In the previous lesson, various steps for creating menus for programs has been explained. IN the present lesson same concepts will be explained using the case studies. 2.1 Objective After completing this lesson, you will be able to creating Menus for programs. 2.2 Case Study 1 Problem: Design a form containing a menu with two top-level items, File and Help. Solution: The File menu, shown below, will have the following level-two items below it: New, Open, Save, Save As, Print and Exit. Note that separator bars appear above the Save, Print, and Exit items. The Help menu contains just one level-two item below it, About.

15 15 To build a menu for use with your VB program, you use the Menu Editor, which appears as an icon in the toolbar of the VB IDE. It is the circled item in the screen shot below: Alternatively, you can invoke the Menu Editor from the Tools menu item as shown below: To build the menu described above, perform the following steps. 1. Start a new VB project and invoke the Menu Editor using either method shown above (click the Menu Editor toolbar icon or select the Menu Editor option from the Tools menu). The Menu Editor screen appears, as shown below:

16 16 2. For "Caption", type &File (by placing the ampersand to the left of the "F", we establish "F" as an access key for the File item it enables the user to drop down the File menu by keying "Alt+F" on the keyboard in addition to clicking the "File" item with the mouse). For "Name", type mnufile. Your Menu Editor screen should look like this: Click the Next button.

17 3. 17 Click the "right-arrow" button (shown circled below). A ellipsis (...) will appear as the next item in the menu list, indicating that this item is a level-two item (below "File"). For "Caption", type &New; for "Name", type mnunew and for "Shortcut", select Ctrl+N. By specifying a shortcut, you allow the user to access the associated menu item by pressing that key combination. So here, you are providing the user three ways of invoking the "New" function: (1) clicking File, then clicking New on the menu; (2) keying Alt+F,N (because we set up an access key for "N" by placing an ampersand to left of "N" in "New"); or (3) keying Ctrl+N. At this point, your Menu Editor screen should look like this:

18 18 Click the Next button. 4. For "Caption", type &Open; for "Name", type mnuopen and for "Shortcut", select Ctrl+O. Your Menu Editor screen should look like this: Click the Next button.

19 5. 19 For "Caption", type - (a hyphen) and for "Name", type mnufilebar1. A single hyphen as the Caption for a menu item tells VB to create a separator bar at that location. Your Menu Editor screen should look like this: Click the Next button. 6. For "Caption", type &Save; for "Name", type mnusave and for "Shortcut", select Ctrl+S. Your Menu Editor screen should look like this: Click the Next button.

20 7. 20 For "Caption", type Save &As..., and for "Name", type mnusaveas. Your Menu Editor screen should look like this: Click the Next button. 8. For "Caption", type -, and for "Name", type mnufilebar2. Your Menu Editor screen should look like this:

21 21 Click the Next button. 9. For "Caption", type &Print;for "Name", type mnuprint; and for "Shortcut", select Ctrl+P. Your Menu Editor screen should look like this:

22 22 Click the Next button. 10. For "Caption", type -; and for "Name", type mnufilebar3. Your Menu Editor screen should look like this: Click the Next button. 11. For "Caption" type E&xit and for "Name", type mnuexit. Your Menu Editor screen should look like this:

23 23 Click the Next button. 12. Click the "left-arrow" button (shown circled below). The ellipsis (...) no longer appears, meaning we are back to the top-level items. For "Caption", type &Help; and for "Name", type mnuhelp. Your Menu Editor screen should look like this: Click the Next button.

24 Click the "right-arrow" button to create a level-two item below "Help". For "Caption", type &About; and for "Name", type mnuabout. Your Menu Editor screen should look like this: At this point, we are done creating our menu entries, so click the OK button. That will dismiss the menu editor and return focus to the VB IDE. Back in the VB IDE, your form will now have a menu, based on what you have set up in the Menu Editor. If you click on a top-level menu item (File for example), the level-two menu will drop down:

25 Click on the New menu item. The code window for the mnufilenew_click event opens, as shown below. Note: Click is the only event that a menu item can respond to. In theplace mnufilenew_click event, place the code you want to execute when the user clicks the New menu item. Since this is just a demo, we will place a simple MsgBox statement in the event procedure: MsgBox "Code for 'New' goes here.", vbinformation, "Menu Demo" 17. Code similar MsgBox statements for the Open, Save, Save As, and Print menu items: Private Sub mnufileopen_click() MsgBox "Code for 'Open' goes here.", vbinformation, "Menu Demo" End Sub Private Sub mnufilesave_click() MsgBox "Code for 'Save' goes here.", vbinformation, "Menu Demo" End Sub Private Sub mnufilesaveas_click() MsgBox "Code for 'Save As' goes here.", vbinformation, "Menu Demo" End Sub Private Sub mnufileprint_click() MsgBox "Code for 'Print' goes here.", vbinformation, "Menu Demo" End Sub 18. For the Exit menu item Click event, code the statement Unload Me. Private Sub mnufileexit_click() Unload Me End Sub 19. For the About menu item Click event, code as shown below: Private Sub mnuhelpabout_click() MsgBox "Menu Demo" & vbcrlf _ & "Copyright " & Chr$(169) & " 2004 thevbprogrammer.com",, _

26 26 "About" End Sub 20. Run the program. Note how the code executes when you click on the various menu items. Also test the use of the access keys (e.g., Alt+F, N) and shortcut keys (e.g., Ctrl-O). 21. Save the program and exit VB. 2.3 Case Study 2 This example shows you how to create a popup menu (sometimes called a context menu or a right-click menu). 1. Start a new VB project and place a label on the form. Name the label lbltesttext. Set the Caption to Test Text. 2. Open the Menu Editor, and create a top-level item with a Caption value of PopUpFormat and the Name mnupopuupformat. Also importantly uncheck the Visible checkbox (see the circled item below). In order for a menu to be a pop-up menu, it must be invisible.

27 3. 27 Create the following level-two menu items below the PopUpFormat top-level menu. (When creating these level-two items, keep the Visible box checked.) Caption Bold Italic Underline Name mnubold mnuitalic mnuunderline - (hyphen) Cancel mnuformatsep mnucancel When done, your Menu Editor should look like this:

28 28 4. Click OK to save your changes. Note: When you return to the IDE, you will NOT see this menu on the form (remember it's a pop-up menu and it will only be visible when invoked through code). 5. Code the lbltesttext_mousedown event as shown below. Note that the Button parameter is tested for vbrightbutton as is conventional, we only want to pop up the menu if the user right-clicks on the label. If the user clicks the right mouse button, the PopupMenu statement is executed. It is this statement that makes the pop-up menu appear. Private Sub lbltesttext_mousedown(button As Integer, _ Shift As Integer, _ X As Single, _ Y As Single) If Button = vbrightbutton Then PopupMenu mnupopupformat, vbpopupmenurightbutton End If End Sub The PopupMenu method syntax has these parts: Part object Menuname Flags Description Optional. An object expression that evaluates to an object in the Applies To list. If object is omitted, the form with the focus is assumed to be object. Required. The name of the pop-up menu to be displayed. The specified menu must have at least one submenu. Optional. A value or constant that specifies the location and behavior of a pop-up menu, described as follows: Constant (location) Value Description vbpopupmenuleftalign 0 (Default) The left side of the pop-up menu is located at x. vbpopupmenucenteralign 4 The pop-up menu is centered at x. vbpopupmenurightalign 8 The right side of the pop-up menu is located at x. Constant (behavior) Value Description

29 29 vbpopupmenuleftbutton 0 (Default) An item on the pop-up menu reacts to a mouse click only when you use the left mouse button. vbpopupmenurightbutton 2 An item on the popup menu reacts to a mouse click when you use either the right or the left mouse button. Note: To specify both a "location" constant and a "behavior" constant, add the two values together. For example: PopupMenu MyMenu, vbpopupmenurightalign + vbpopupmenurightbutton X Optional. Specifies the x-coordinate where the pop-up menu is displayed. If omitted, the mouse coordinate is used. Y Optional. Specifies the y-coordinate where the pop-up menu is displayed. If omitted, the mouse coordinate is used. boldcommand Optional. Specifies the name of a menu control in the pop-up menu to display its caption in bold text. If omitted, no controls in the pop-up menu appear in bold. 5. Code the mnubold_click event as shown below. Note that the Checked property of the menu item is used. When set to True, this causes a checkmark to appear to the left of the menu item. The Checked property is typically used as a toggle. Private Sub mnubold_click() If mnubold.checked Then lbltesttext.fontbold = False mnubold.checked = False Else lbltesttext.fontbold = True mnubold.checked = True End If End Sub 6. Code the mnuitalic_click and mnuunderline_click events in a similar fashion as shown below. Private Sub mnuitalic_click() If mnuitalic.checked Then lbltesttext.fontitalic = False mnuitalic.checked = False Else lbltesttext.fontitalic = True

30 30 mnuitalic.checked = True End If End Sub Private Sub mnuunderline_click() If mnuunderline.checked Then lbltesttext.fontunderline = False mnuunderline.checked = False Else lbltesttext.fontunderline = True mnuunderline.checked = True End If End Sub 7. Run the program and check out the various options you have coded. 8. Save the program and exit VB. NOTE: If desired, you can have both a "regular" menu and as many pop-up menus as you want on the same form. Any top-level menu that has its Visible box checked in the Menu Editor will appear at the top of the form in the menu bar you create. Any toplevel menu that has its Visible box unchecked in the Menu Editor will NOT appear at the top of the form in the menu bar, but can be used as a pop-up menu invoked with the PopupMenu method. 2.4 Summary: In this lesson, the concepts for creating menus for programs has been explained using practical examples. Step by Step excution for creating menus has been explained. 2.5 Further Readings: Visual Basic 6.0 No Experience Required, BPB Publications Mastering Visual Basic 6.0, BPB Publications Visual Basic 6, Black Book by Steve Holzner, Paraglypu Press. Mastering Visual Basic 6 by Evangelos Petroutsos, Sybex. Sams Teach Yourself Visual Basic 6 in 24 hours by Greg Perry, Sams1999. Programming Microsoft Visual Basic 6.0 by Francesco Balena, Miscrosoft Press. The Complete Reference, Visual Basic 6 by Noel Jerke, Tata McGraw Hill. Web Resources

31 Paper : MS(A) 123 Visual Basic Lesson No. 3 Author: Vishal Goyal CREATING CONTROLS Introduction Objectives Controls Collection Method 1: Using a Control Array to create controls Method 2: Creating controls from scratch using the Controls Collection Summary Self Understanding Further Reading 3.0 Introduction Controls can be added to the form at runtime also. This capability provides flexibility to the applications. In the present lesson we will explore two methods for creating controls - Using a Control Array to create controls and Creating controls from scratch using the Controls Collection 3.1 Objective After reading this lesson, you will be able to learn Adding Controls to the forms at the run time How to create control arrays using the controls collections Creating Controls frfom the scratch using the Cotrols Collection 3.2 Controls Collection Did you know that it's possible to create controls at runtime? That's right. If you wish, you can add additional controls to your form at runtime. This capability gives your Visual Basic program the ultimate in flexibility--allowing you to dynamically control the appearance of your form at runtime---not only the placement of controls, but also the type and number of controls that appear on the form. Many Visual Basic programmers are aware that it's possible to create controls at runtime by first creating a control array and then adding additional members to the control array at runtime by using the Load Statement. This is the first method I'll be examining in this article. In addition, I'll also show you how can create controls at runtime entirely from scratch, without the need to first create a control array.

32 Method 1---Using a Control Array to create controls To create a control at run time using this method you first must create a control array for the control you wish to dynamically create. In other words, if you want to create checkboxes at run time, you first must create a control array of checkboxes. For those of you unfamiliar with the term, a control array is a collection of controls on a form, all having the same name and possessing unique Index property values. It's possible to create a Control array that has just a single 'member'---and that's what I'll do now. I'll begin by placing a Checkbox and a Command button on a form. In the Command Button, I'll be placing code to dynamically create a checkbox on the form at run time. More on that in a few minutes. First, I need to tell Visual Basic that the Checkbox is a member of a Control Array---I do that merely by changing its Index property from the default blank value to a number---in this case 0.

33 33 Once the Index property has been set to 0, the Checkbox is now a member of the Check1 Checkbox Control Array---which makes creating a new checkbox at runtime very easy. All we need to do is tell Visual Basic that we want to create a new checkbox, using the existing Checkbox as a template. We do this by executing the Visual Basic Load Statement within the Click Event Procedure of the Command Button---like this. Private Sub Command1_Click() Load Check1(1) Check1(1).Caption = "New Checkbox" End Sub The Load statement Load Check1(1) tells Visual Basic to create a new member of the Check1 checkbox array---and to create it with an Index property of 1. This statement Check1(1).Caption = "New Checkbox" gives the Checkbox, whose index property is equal to 1, a unique caption to make it 'stand out' form the original checkbox placed on the form at design time. If we now run the program and then click on the Command Button we'll see this screenshot

34 34 Oops something's wrong. What I didn't tell you is that when you create a control at runtime, by default, the Visible property of the new control is set to False. To see the new control, we need to explicitly set its Visible propert to True. Let's modify the code in the Click event procedure to look like this Private Sub Command1_Click() Load Check1(1) Check1(1).Caption = "New Checkbox" Check1(1).Visible = True End Sub Now let's run the program again and click on the Command Button once more Something is still wrong---there's still just the single checkbox!

35 35 The problem is this: when the new control is created, the properties of the new control are identical to the properties of the 'template' control used to create it---with the exception of the Index property which we set with the Load statement and the Visible property which we know is initialized to False. Because of that, the new checkbox is on the form---it just so happens to be sitting 'under' the first control, since it has identical Top, Left, Height and Width properties. All we need to do to see the new control is to move it away from the first control--and we can do that by adding a line of code to the Click Event procedure to change the Top property of the new control. Like this Private Sub Command1_Click() Load Check1(1) Check1(1).Caption = "New Checkbox" Check1(1).Visible = True Check1(1).Top = Check1(0).Top + Check1(0).Height End Sub This line of code Check1(1).Top = Check1(0).Top + Check1(0).Height tells VB to take the current value of the Top property of the existing checkbox, and to add to that the value of its Height Property (remember, the first control has an Index property of 0). The result of this addition is a Top property for the new control that is just under the first control. If we now run the program, and click on the Command Button, we'll see this screen shot Works like a charm! I should also point out that if we want to give the user the impression that we are creating controls totally from scratch, we can place the template control on the

36 36 form---and then set its Visuble property to False---that way, at run time, the controls are created---seemingly out of nowhere. To review, here s a summary of the steps necessary to create a new control using the Control Array method. 1. Create a control array of the control type you wish to create at runtime. If you want to create a textbox at runtime, create a Textbox control array. If you want to create a Command Button, create a Command Button Control array. Remember, to create a Control Array, all you need to do is to change the Index property of the control to something other than its default empty value. 2. Use the Load Statement, with a unique Index property, to create the new control. 3. Change the Visible property of the new control to True in order to make it visible. 4. Change the coordinate properties (Left or Top) to bring the new control out from under the original. 3.4 Method 2---Creating controls from scratch using the Controls Collection There's a second method to create a control at runtime, and that's to use the Add Method of the Controls collection. This method is easier to use than the Control Array method, but harder to understand since it requires some familiarity with the Visual Basic Controls Collection. In short, each control that is placed on the form either at Design time or runtime is made a member of the intrinsic Visual Basic Collection called the Controls Collection. For those of you not familiar with Visual Basic Collections, a Collection is similar to a one dimensional array. Each control on the form has a reference placed on the Controls collection when it is placed there at design time. In the same way, a control that is placed on the form at run time (the way we just did using the Control Array Method) also has a reference placed on the Controls Collection. It's also possible to create a control at runtime by adding a reference to a control directly to the Controls Collection. Doing so avoids the necessity of first having to create a 'template' control on the form at design time---the reason for that is that VB maintains templates for all of the controls in the hidden Visual Basic Global Object called VB. Suffice to say that all that is required to create a control at runtime using this method is to execute four lines of code, like this Private Sub Command1_Click() Dim ctlname As Control Set ctlname = Form1.Controls.Add("VB.TextBox", "Text1", Form1) ctlname.visible = True ctlname.top = Check1(0).Top + Check1(0).Height

37 37 End Sub This line of code Dim ctlname As Control declares something known as an Object Variable---which is nothing more than a variable that contains, as a value, a reference to an Object (in this case, a Textbox). You can declare an Object variable as a specific control type (such as Textbox) or elect to declare it as the more generic Control type, which is what we did here. This line of code Set ctlname = Form1.Controls.Add("VB.TextBox", "Text1", Form1) tells Visual Basic to add a Textbox control called Text1 to the Controls Collection of Form1 and to use the Object Variable ctlname to 'point to it'. Once this control has been added to the Controls Collection, thereafter whenever we refer to the control using code we must refer to it by the Object Variable Name. That's why, when we then set the Visible property of the new textbox to True and adjust its Top property, we use the Object Variable name instead. ctlname.visible = True ctlname.top = Check1(0).Top + Check1(0).Height More on the Add Method. The Add Method has three arguments---the first is the name of the template for the control you are creating, the second is the name of the control as it will appear in the Controls Collection and the third argument is the control's container (ordinarily the form, but it could be the name of a Frame Control if you wanted the control to be placed 'within' a Frame on the form). The Textbox control is called Textbox, the Command Button control is called CommandButton. If you open the Visual Basic Object Browser (View-Object Browser from the Visual Basic Menu Bar)

38 38 and select the VB Global Object in the library listbox

39 39 the resulting display will show you the names for the controls that you can create at runtime

40 40 Again, for more information on the Visual Basic Object Browser, check out my Objects book. If we now run the program and click on the command button, we'll see this screenshot

41 41 As you can see, the new Textbox control has been placed on 3.5 Summary Control Collections can be added at runtime also. In this chapter we have explained through example about Using a Control Array to create controls and creating controls from scratch using the Controls Collection 3.6 Self Understanding 1. Explain with the help of the example for creating controls using control arrays. 2. Explain the various steps for creating controls using controls collection. 3.7 Further Readings Visual Basic 6.0 No Experience Required, BPB Publications Mastering Visual Basic 6.0, BPB Publications Visual Basic 6, Black Book by Steve Holzner, Paraglypu Press. Mastering Visual Basic 6 by Evangelos Petroutsos, Sybex. Sams Teach Yourself Visual Basic 6 in 24 hours by Greg Perry, Sams1999. Programming Microsoft Visual Basic 6.0 by Francesco Balena, Miscrosoft Press. The Complete Reference, Visual Basic 6 by Noel Jerke, Tata McGraw Hill. Web Resources

42 Paper : MS(A) 123 Visual Basic Lesson No. 4 Author: Vishal Goyal ACTIVE DATA OBJECTS Structure: 4.0 Introduction 4.1 Objective 4.2 Class 4.3 Building Your First Class 4.4 Properties of Class 4.5 Active Data Objects 4.6 Accessing ADO with Various Languages 4.7 Accessing ADO with Visual Basic 4.8 Creating ActiveX Objects 4.9 Using ADO with Visual Basic: An Example 4.10 Summary 4.11 Self Understanding 4.12 Further Readings 4.0 Introduction In the present lesson, building of classes in your VB Application will be explained with examples using Add Class Module. A robust class is one that actively protects its internal data from tampering. ActiveX Data Objects (ADO) is an application program interface from Microsoft that lets a programmer writing Windows applications get access to a relational or non-relational database from both Microsoft and other database providers. Visual Basic is probably the most popular language in which to develop applications for ADO. Visual Basic is a very easy language to understand and excellent for both beginners and advanced developers. In Visual Basic, you can create new ADO objects by simply referencing the ADODB classes of the Microsoft ActiveX Data Objects Library. 4.1 Objective After reading this lesson, you will be able to learn about Building classes Creating ActiveX Objects Accessing ADO with various languages and with Visual Basic 4.2 Class The main purpose of the class is to define the properties and methods for the

43 43 class. Although included in previous versions of Visual Basic, the class has become a key technology in VB.NET and its object-oriented programming. Among the important ideas about classes are: A class can have subclasses that can inherit all or some of the characteristics of the class. Subclasses can also define their own methods and variables that are not part of their parent class. The structure of a class and its subclasses is called the class hierarchy. Classes involve a lot of terminology. An original class, from which interface and behavior is derived, can be identified by any of these equivalent names: Parent class Superclass Base class And new classes can have these names: Child class Subclass 4.3 Building Your First Class Creating a class in Visual Basic is very simple: just select the Add Class Module command from the Project menu. A new code editor window appears on an empty listing. Visual Basic automatically add a class module named Class1, so the very first thing you should do is change the Class name in the Project Properties window in a more appropriate name. The first version of our class includes only a few properties. These properties are exposed as Public members of the class module itself. To create a class module 1. Start Visual Basic. 2. In the New Project dialog box, select Standard EXE, then click OK. 3. On the Project menu, click Add Class Module. 4. In the Add Class Module dialog box, select Class Module, then click Open. 5. In the Properties window, set the Name property for the class module to Student. To create public property 1. In the Code window, type the following: 'In the declaration section of the Student class module Public Student_ID As String Public FirstName As String Public LastName As String Public MajorCode As String

44 44 Public YearLevel As String Public BirthDate As Date This is a very simple class, which consists of Public properties, so we are not distracted by OOP details (not yet), we will just examine the concept. Once you've created a class, you can create an instance of that class then you can use the properties of that class. The following example creates an instance of the Student class, and sets and retrieves its properties: To Use the Student Class 1. Place a command button on Form1. 2. In the Click event for the command button, type the following: 'Declare an object Student Dim objstudent As Student 'Create an instance of the class Set objstudent = New Student 'Use the object Student objstudent.studentid = "12345" objstudent.firstname = "Cathrina" objstudent.lastname = "Aniversario" objstudent.majorcode = "C" objstudent.yearlevel = "Freshmen" objstudent.birthdate = "Oct 10, 1980" MsgBox "Student ID : " & objstudent.studentid & vbcrlf & _ "Student Name : " & objstudent.firstname & " " & _ objstudent.lastname & vbcrlf & _ "Major Code : " & objstudent.majorcode & vbcrlf & _ "Year : " & objstudent.yearlevel & vbcrlf & _ "BirthDate : " & objstudent.birthdate Set objstudent = Nothing On the Run menu in Visual Basic, click Start. When the program is running, click the Command1 button. Click OK to close the message box. On the Run menu in Visual Basic, click Stop.

45 45 Object Keyword The New keyword The New keyword (when used in a Set command) tells Visual Basic to create a brandnew instance of a given class. The keyword then returns the address of the instance data area just allocated. The Setcommand The Set command simply copies what it finds to the right of the equal sign into the object variable that appears to the left of it. This value can be, for example, the result of a New keyword, the contents of another variable that already exists or the result of an expression that evaluates to an object. The only other tasks that the Set command performs are incrementing the reference counter of the corresponding instance data area and decrementing the reference counter of the object originally pointed to by the left-hand variable (if the variable didn't contain the Nothing value): Unlike regular variable, which can be used as soon as they have been declared, an object variable must be explicitly assigned an object reference before you can invoke the object's properties and methods. When an object variable has not been assigned, it contains the special Nothing value, meaning it doesn't contain any valid reference to an actual object. For example try this code: ' Declare the variable Dim objstudent As Student ' Then comment out the next line ' Set objstudent = New Student ' Raises an error 91 ' "Object variable or With block variable not set" MsgBox objstudent.firstname The code will give you an error, because we trying to use an object that doesn't exist. This behavior is favorable because it doesn't make much sense to use a property of an object that doesn't exist. One way to avoid the error is to test its contents of an object variable using the Is Nothing ' Use the variable only if it contains a valid object reference If Not (objstudent Is Nothing) Then MsgBox objstudent.firstname MsgBox objstudent.firstname

46 46 But in other cases, you may want to create an object and then assign its properties. You might find it useful to declare an auto-instancing object variable using the As New clause: Dim objstudent As New Student ' Auto-instancing variable At runtime, when Visual Basic encounters a reference to an auto-instancing variable, it first determines whether it's pointing to an existing object and creates a brand new instance of the class if necessary. But auto-instancing variables have an advantage and disadvantage: It reduces the amount of code you need to write to be up and running with your classes. This can be useful if you are prototyping an application. In some condition, you might declare a variable but never actually use it: which happens all the time with standard variables and with object variables too. In truth is, if you create an object with a Set command at the beginning of a procedure, you might be creating an object for no real purpose (thus taking both time and memory). On the other hand, if you delay the creation of an object until you actually need it, you could soon find yourself drowning in a sea of Set commands, each preceded by an Is Nothing test to avoid re-creating an object instanced previously. Auto-instancing variables are automatically created by Visual Basic only if and when they are referenced. This is probably the situation in which auto-instancing variables are most useful. Your object variable cannot be tested against the Nothing value. In fact, as soon as you use one in the Is Nothing test, Visual Basic insistently creates a new instance and the test always returns False It eliminate errors, which is sometimes this is specifically what you don't need especially during the development stage, because during this state, you want to see all the errors because this might be the symptoms of other serious deficiency in your code logic. Auto-instancing variables make the debugging step a little more difficult to understand because you can never be sure when and why an object was created. You can't declare an auto-instancing variable of a generic type, such as Object, or Form because Visual Basic must know in advance which kind of object should be created when it references that variable for the first time. Finally, each time Visual Basic references an auto-instancing variable, it incurs a small performance hit each time Visual Basic reference an auto-instancing, because Visual Basic has to check whether it's Nothing. In short, auto-instancing variables are not the best choice for creating the object and you should stay away from it.

47 47 Object Keyword The Nothing value The Nothing keyword is the Visual Basic way of saying Null or 0 to an object variable. The Is operator The Is operator is used by Visual Basic to check whether two object variables are pointing to the same instance data block. At a lower level, Visual Basic does nothing but compare the actual addresses contained in the two operands and return True if they match. The only possible variant is when you use the Is Nothing test, in which case Visual Basic compares the contents of a variable with the value 0. You need this special operator because the standard equal symbol, which has a completely different meaning, would fire the evaluation of the objects' default properties: 4.4 Properties Of a Class Now is the time to make our class to more robust class. A robust class is one that actively protects its internal data from tampering. So how can a class protect itself from invalid assignments, such as an empty string for its FirstName or LastName properties. To accomplish this purpose, you must change the internal implementation of the class module, because in its present form you have no means of trapping the assignment operation. Simply change all the Public member into Private members and encapsulate them in pairs of Property procedures. To change our Student class 1. Double click the class Student.cls in the Project Explorer. 2. In the Student Class Module, change all word Public to Private and add a prefix m_ in front of all private variables, as shown below: In the declaration section of the Student class module Private m_student_id As String Private m_firstname As String Private m_lastname As String Private m_yearlevel As String Private m_birthdate As Date NOTE You can also use Replace Dialog box. To do this, press Ctrl-H, the Dialog box appears. On the Find What combo box, type Public. Next on the With combo box, type Private, then click Replace All button. Appending the prefix m_ is just a personal style, this way it keeps my name and private member variable synchronize and it is commonly programming. Feel free to use it or to create your own style. Replace Replace property used in

48 48 3. In the Student Class Module, type the following code: 'In the declaration section of the Student class module Private m_student_id As String Private m_firstname As String Private m_lastname As String Private m_majorcode As String Private m_yearlevel As String Private m_birthdate As Date Property Get MajorCode() As String MajorCode = m_majorcode End Property Property Let MajorCode(ByVal strnewvalue As String) ' Raise an error if an invalid assignment is attempted. If Len(strNewValue) = 0 Or Len(strNewValue) > 1 Then Err.Raise 5 m_majorcode = strnewvalue End Property Property Get FirstName() As String FirstName = m_firstname End Property Property Let FirstName(ByVal strnewvalue As String) ' Raise an error if an invalid assignment is attempted. If Len(strNewValue) = 0 Then Err.Raise 5 ' Invalid procedure argument ' Else store in the Private member variable. m_firstname = strnewvalue End Property Property Get LastName() As String LastName = m_lastname End Property Property Let LastName(ByVal strnewvalue As String) ' Raise an error if an invalid assignment is attempted. If Len(strNewValue) = 0 Then Err.Raise 5 ' Invalid procedure argument ' Else store in the Private member variable.

49 49 m_lastname = strnewvalue End Property Property Get StudentID() As String StudentID = m_student_id End Property Property Let StudentID(ByVal strnewvalue As String) ' Raise an error if an invalid assignment is attempted. If Len(strNewValue) = 0 Then Err.Raise 5 ' Invalid procedure argument ' Else store in the Private member variable. m_student_id = strnewvalue End Property Property Get BirthDate() As Date BirthDate = m_birthdate End Property Property Let BirthDate(ByVal datnewvalue As Date) If datnewvalue >= Now Then Err.Raise 1001,, "Future Date!" m_birthdate = datnewvalue End Property Property Get YearLevel() As String YearLevel = m_yearlevel End Property Property Let YearLevel(ByVal strnewvalue As String) Dim vartemp As Variant Dim found As Boolean For Each vartemp In Array("Freshmen", "Sophomore", "Junior", "Senior") If InStr(1, strnewvalue, vartemp, vbtextcompare) Then found = True Exit For End If Next

50 50 If Not found Then Err.Raise 5 m_yearlevel = strnewvalue End Property NOTE Visual Basic can help you in typing Property Procedure by Add Procedure command from the Tools menu, which creates a templates for Property Get and Let procedures. But you should edit the result to a proper data type, because all properties created by this command is of type Variant. 4. On the Run menu in Visual Basic, click Start. 5. When the program is running, click the Command1 button. 6. Click OK to close the message box. 7. On the Run menu in Visual Basic, click Stop. Everything works as before. What we have done is make the class a bit more robust because it now refuses to assign invalid values to its properties. To see what I mean, just try to issue this command: objstudent.firstname = "" 'Raises an error 'Invalid Procedure call 4.5 Active Data Objects ActiveX Data Objects (ADO) is an application program interface from Microsoft that lets a programmer writing Windows applications get access to a relational or non-relational database from both Microsoft and other database providers. For example, if you wanted to write a program that would provide users of your Web site with data from an IBM DB2 database or an Oracle database, you could include ADO program statements in an HTML file that you then identified as an Active Server Page. Then, when a user requested the page from the Web site, the page sent back would include appropriate data from a database, obtained using ADO code. Like Microsoft's other system interfaces, ADO is an object-oriented programming interface. It is also part of an overall data access strategy from Microsoft called Universal Data Access. Microsoft says that rather than trying to build a universal database as IBM and Oracle have suggested, finding a way to provide universal access to various kinds of existing and future databases is a more practical solution. In order for this to work, Microsoft and other database companies provide a "bridge" program between the database and Microsoft's OLE DB, the lowlevel interface to databases. OLE DB is the underlying system service that a programmer using ADO is actually using. A feature of ADO, Remote Data Service, supports "data-aware" ActiveX controls in Web pages and efficient client-side caches. As part of ActiveX, ADO is also

51 51 part of Microsoft's overall Component Object Model (COM), its component-oriented framework for putting programs together. ADO evolved from an earlier Microsoft data interface, Remote Data Objects (RDO). RDO works with Microsoft's ODBC to access relational databases, but not nonrelational databases such as IBM's ISAM and VSAM 4.6 Accessing ADO with Various Languages Because ActiveX Data Objects expose their properties by means of COM interfaces, they can be accessed by any language that can utilize COM. In this lesson, we will look at accessing ADO from Visual Basic, Visual C++, and Visual J++, since these are the most commonly used tools for developing ADO applications on the Windows operating system. In addition to these three languages, there are two scripting languages that are already well-established: VBScript and JScript. VBScript is a lightweight subset of Visual Basic that's designed specifically for adding script to HTML documents. JScript is Microsoft's implementation of JavaScript, designed for script development within HTML documents. Although ADO is meant to offer the same development interface to each language from which it is accessed, some inconsistencies arise because of differences in their syntax and the development environments in which they are used. In this chapter, we will take a look at each of the five languages and learn how to get started developing ADO applications in each. 4.7 Accessing ADO with Visual Basic Visual Basic is probably the most popular language in which to develop applications for ADO. Visual Basic is a very easy language to understand and excellent for both beginners and advanced developers. Referencing ActiveX Data Objects To write an application in Visual Basic using ActiveX Data Objects, you must first tell Visual Basic about them by adding ADO to the list of references that Visual Basic uses to run an application. You may do this by selecting the Project References menu item so that the References dialog box appears, as shown in Following figure. In the Available References list box, select the latest version of Microsoft ActiveX Data Objects Library that you have installed. Now you are ready to create and use ADO objects within your current Visual Basic application.

52 52 Figure: The References dialog box of Visual Basic When redistributing ADO applications, you should use the MDAC redistributable package available for download from Microsoft's web site. Some basic steps are required in order to be able to access and manipulate data using ADO : 1. Create a connection object to connect to the database. 2. Create a recordset object in order to receive data in. 3. Open the connection 4. Populate the recordset by opening it and passing the desired table name or SQL statement as a parameter to open function. 5. Do all the desired searching/processing on the fetched data. 6. Commit the changes you made to the data (if any) by using Update or UpdateBatch methods. 7. Close the recordset 8. Close the connection 4.8 Creating ActiveX Data Objects In Visual Basic, you can create new ADO objects by simply referencing the ADODB classes of the Microsoft ActiveX Data Objects Library. The following piece of code creates a Connection and a Recordset object in Visual Basic: ' create a reference to a Connection object Dim con As ADODB.Connection ' create a reference to a Recordset object Dim rst AS ADODB.Recordset

53 53 As with any other Visual Basic objects, you must instantiate them before they can be used, as in the following examples: ' create a new instance of the Connection object Set con = New ADODB.Connection ' create a new instance of the Recordset object Set rst = New ADODB.Recordset In the previous examples, the ADODB prefix to the ADO objects is used in case your Visual Basic development environment references another object of the same class name in a different class library. The following code illustrates how a DAO Recordset and an ADO Recordset can be created within the same project: ' which object model is this from? Dim rst As Recordset ' explicitly specifying the Data Access Object Model Dim rstdao As DAO.Recordset ' explicitly specifying the ActiveX Data Object Model Dim rstado As ADODB.Recordset If you know for a fact that no other class library listed in the References dialog box of your current Visual Basic application has the same class names as ADO, you may remove the ADODB prefix when declaring and instantiating object variables. However, if you are using more than one object model with the same class definitions (as in the previous example), not specifying the library from which the class should be derived tells VB to instantiate the class from the library that comes first in the list of references to the project. In Visual Basic, it is always a good idea to remove an object from memory once it is no longer being used. This is done by setting the object to Nothing, as follows: ' remove the objects Set con = Nothing Set rst = Nothing 4.9 Using ADO with Visual Basic: An Example So that you can visualize how to work with ADO objects in Visual Basic, Example uses ADO to open a connection to the Jet Biblio database and to return a recordset containing the names of its first ten authors. Each record is then written to a list box before both the Connection and Recordset objects are closed. Note that the example makes use of dynamic control creation supported by Visual Basic 6.0 or later; if you have an earlier version, simply delete the code that defines, instantiates, and sets the properties of the list box and place a list box named lstauthors on the form at design time.

54 54 To begin, create a new Application EXE project and open the Project References menu so that you see the References dialog box shown in Figure Above. Select the latest version of Microsoft ActiveX Data Objects that you have installed, and press the OK button. Now, replace the existing source code for Form1 with the code shown in Following Example and run the application. That's all there is to it. Make sure that you have a Biblio.mdb database located at C:\Program Files\Microsoft Visual Studio\VB98, or if you have it in another location, simply change the path in the code that points to the Access database. Example: A Simple Visual Basic Example Option Explicit Private WithEvents lstauthors As ListBox Private Sub Form_Load ( ) create new instances of the Connection and Recordset objects Dim con As ADODB.Connection Dim rst As ADODB.Recordset ' instantiate the Connection and Recordset objects Set con = New ADODB.Connection Set rst = New ADODB.Recordset create two strings to define the connection and the recordset Dim sconstring As String Dim ssqlstring As String Create list box control Set lstauthors = Me.Controls.Add ("vb.listbox", "lstauthors", Me) lstauthors.visible = True open the BiblioDSN data source with the Connection object sconstring = "Provider=Microsoft.Jet.OLEDB.4.0; " _ & "Data Source=C:\Program Files" _ & "\Microsoft Visual Studio" _ & "\VB98\Biblio.mdb" con.open sconstring Debug.Print "Connection opened." ' create a Recordset object from a SQL string ssqlstring = "SELECT TOP 10 Author " &"FROM Authors" Set rst = con.execute(ssqlstring)

55 55 Debug.Print "SQL statement processed." ' retrieve all the data within the Recordset object Debug.Print "Getting data now..." Do Until (rst.eof) lstauthors.additem rst("author").value rst.movenext Loop Debug.Print "End of data." close and remove the Recordset object from memory rst.close Set rst = Nothing Debug.Print "Closed and removed " _ & "Recordset object from memory." close and remove the Connection object from memory con.close Set con = Nothing Debug.Print "Closed and removed "& "Connection object from memory." End Sub Private Sub Form_Resize( ) ' this code is added for asthetics lstauthors.top = 0 lstauthors.left = 0 lstauthors.width = Me.Width lstauthors.height = Me.Height End Sub 4.10 Summary A robust class is one that actively protects its internal data from tampering. ActiveX Data Objects (ADO) is an application program interface from Microsoft that lets a programmer writing Windows applications get access to a relational or nonrelational database from both Microsoft and other database providers. Visual Basic is probably the most popular language in which to develop applications for ADO. Visual Basic is a very easy language to understand and excellent for both beginners and advanced developers. In Visual Basic, you can create new ADO objects by simply referencing the ADODB classes of the Microsoft ActiveX Data Objects Library.

56 Self Understanding 1. What do you mean by class? What are the benefits of using classes in application? 2. Explain various steps for setting properties of a class. 3. What do you mean by ADO? Explain various steps for creating ADO in VB Application taking an example Further Readings Visual Basic 6.0 No Experience Required, BPB Publications Mastering Visual Basic 6.0, BPB Publications Visual Basic 6, Black Book by Steve Holzner, Paraglypu Press. The Complete Reference, Visual Basic 6 by Noel Jerke, Tata McGraw Hill. Mastering Visual Basic 6 by Evangelos Petroutsos, Sybex. Sams Teach Yourself Visual Basic 6 in 24 hours by Greg Perry, Sams1999. Programming Microsoft Visual Basic 6.0 by Francesco Balena, Miscrosoft Press. Web Resources

57 Paper : MS(A) 123 Visual Basic Lesson No. 5 Author: Vishal Goyal MULTIPLE DOCUMENT INTERFACE Introduction Objective Working with Forms The Appearance of Forms Setting the Start-Up Form Loading and Unloading Forms Showing and Hiding Forms 5.4 Multiple Document Interface Creating an MDI Application Working with MDI Child Forms at Design Time Run-Time Features of MDI Forms Working with MDI Forms and Child Forms Loading MDI Forms and Child Forms Setting Child Form Size and Position Maintaining State Information for a Child Form Unloading MDI Forms with Query Unload 5.5 Summary 5.6 Self-Understanding 5.7 Suggested Readings 5.1 Introduction Forms are the basic component of VB Applications. So, there can be multiple forms in the application depending upon the scale of the application. Each form has its own appearance, one among them can be set as start up form, some event or settings can be performed while loading and unloading of the form, form can shown or hidden. In the coming section these topics will be explained in depth. There are applications when there is a need to open forms within forms (Child forms). Thus the concept of Multiple Document Interface comes into picture. There are number of features of MDI that can be set at run time. We can load and unload MDI forms and its child forms and various other properties related to it can be set. 5.2 Objective After reading this lesson you will be able to Create Forms Set properties of the forms

58 58 Creating MDI Forms and its child forms Setting various properties related to MDI Forms 5.3 Working with Forms The Appearance of Forms The main characteristic of a Form is the title bar on which the Form's caption is displayed. On the left end of the title bar is the Control Menu icon. Clicking this icon opens the Control Menu. Maximize, Minimize and Close buttons can be found on the right side of the Form. Clicking on these buttons performs the associated function. The following figure illustrates the appearance of a Form: The control menu contains the following commands : Restore : Restores a maximized Form to the size it was before it was maximized; available only if the Form has been maximized. Move : Lets the user moves the Form around with the mouse Size : Lets the user resizes the control with the mouse Minimize: Minimizes the Form Maximize : Maximizes the Form Close : Closes the Form Setting the Start-Up Form A typical application has more than a single Form. When an application runs the main Form is loaded. By setting the Project properties you can control which Form is to be displayed in the Start-Up of the application. Following figure illustrates the Project property window.

59 59 By default, Visual Basic suggests the name of the first Form created when the project started Loading and Unloading Forms In order to load and unload the forms, Load and Unload statements are used. The Load statement has the following syntax : Load FormName And the Unload statement has the following syntax : Unload FormName The FormName variable is the name of the Form to be loaded or unloaded. Unlike the Show method which cares of both loading and displaying the Form, the load statement doesn't show the Form. You have to call the Form's Show method to display it on the desktop Showing and Hiding Forms Show method is used to Show a Form. If the Form is loaded but invisible, the Show method is used to bring the Form on Top every other window. If the Form is not loaded, the Show method loads it and then displays it. Syntax of the Show method of the Form FormName.Show mode The FormName variable is the Form's name, and the optional argument mode determines whether the Form will be Modal or not. It can have one of the following syntax : * 0-Modeless (default) * 1-Modal Modeless Forms are the normal Forms. Modeless Forms interact with the user and the user allowed to switch to any other Form of the application. If you do not specify the optional mode argument, by default the mode is set to modeless.

60 60 The Modal Forms takes the total control of the application where user cannot switch to any other Forms in the application unless the Form is closed. A modal Form, thus, must have a Close button or some means to close the Form in order to return to the Form where the Modal Form was loaded. Hiding Forms The Hide method is used to hide a Form. The following is the syntax of the Hide Method. FormName.Hide To hide a Form from within its own code, the following code can be used. Me.Hide You must understand that the Forms that are hidden are not unloaded ; they remains in the memory and can be displayed instantly with the Show Method. When a Form is hidden, you can still access its properties and code. For instance, you can change the settings of its Control Properties or call any Public functions in the Form.The following is an example illustrates the Show method and Mode statement * Open a new Project and save the Project Design the application as shown below: Object Property Setting Form Caption Name Form1 frm1 Form Caption Name Form2 frm2 Form Caption Name Form3 frm3 Caption Name Click on button display Form Label1 Label a to a

61 61 The following code is typed in the Click event of the command buttons: Run the application. Clicking on the buttons will display the Forms respectively. But you can see that in the cmd2_click( ) event additionally VbModal argument has been added. You can see the difference after you display the forms by clicking on the command buttons. You can notice that you cannot switch to any other Forms in the application unless you close the Form3. Difference between Unload and Hide method To know what the difference is between Unload and Hide methods we will do an example. Open a new project and save the project. Draw two buttons on the form and name those as shown above. In the click event of the Hide button Following code is entered.

62 62 Me.Hide In the click event of the Unload button following code is entered. Unload Me Save the project and run the application. Once you click on Hide button you can note that the Form is invisible but the application is still running. But when you click on Unload button you can see that the application is terminated. 5.4 Multiple-Document Interface The Multiple-Document Interface (MDI) allows you to create an application that maintains multiple forms within a single container form. Applications such as Microsoft Excel and Microsoft Word for Windows have multiple-document interfaces. An MDI application allows the user to display multiple documents at the same time, with each document displayed in its own window. Documents or child windows are contained in a parent window, which provides a workspace for all the child windows in the application. For example, Microsoft Excel allows you to create and display multiple-document windows of different types. Each individual window is confined to the area of the Excel parent window. When you minimize Excel, all of the document windows are minimized as well; only the parent window's icon appears in the task bar. A child form is an ordinary form that has its MDIChild property set to True. Your application can include many MDI child forms of similar or different types. At run time, child forms are displayed within the workspace of the MDI parent form (the area inside the form's borders and below the title and menu bars). When a child form is minimized, its icon appears within the workspace of the MDI form instead of on the taskbar, as shown in Figure. Figure: Child forms displayed within the workspace of the MDI form

63 63 Note Your application can also include standard, non-mdi forms that are not contained in the MDI form. A typical use of a standard form in an MDI application is to display a modal dialog box. An MDI form is similar to an ordinary form with one restriction. You can't place a control directly on a MDI form unless that control has an Align property (such as a picture box control) or has no visible interface (such as a timer control) Creating an MDI Application Use the following procedure to create an MDI form and its child forms. To create an MDI application 1. Create an MDI form. From the Project menu, choose Add MDI Form. Note An application can have only one MDI form. If a project already has an MDI form, the Add MDI Form command on the Project menu is unavailable. 2. Create the application's child forms. To create an MDI child form, create a new form (or open an existing one) and set its MDIChild property to True Working with MDI Child Forms at Design Time At design time, child forms are not restricted to the area inside the MDI form. You can add controls, set properties, write code and design the features of child forms just as you would with any other Visual Basic form. You can determine whether a form is an MDI child by looking at its MDIChild property, or by examining the Project Explorer. If the form's MDIChild property is set to True, it is a child form. Visual Basic displays special icons in the Project Explorer for the MDI and MDI child forms, as shown in Figure below.

64 64 Figure: Icons in the Project Explorer identify MDI child standard and MDI forms Run-Time Features of MDI Forms At run time, an MDI form and all of its child forms take on special characteristics: All child forms are displayed within the MDI form's workspace. The user can move and size child forms like any other form; however, they are restricted to this workspace. When a child form is minimized, its icon appears on the MDI form instead of the taskbar. When the MDI form is minimized, the MDI form and all of its child forms are represented by a single icon. When the MDI form is restored, the MDI form and all the child forms are displayed in the same state they were in before being minimized. When a child form is maximized, its caption is combined with the caption of the MDI form and is displayed in the MDI form's title bar (see Figure below) By setting the AutoShowChildren property, you can display child forms automatically when forms are loaded (True) or load child forms as hidden (False). The active child form's menus (if any) are displayed on the MDI form's menu bar, not on the child form.

65 65 Figure : A child form caption combined with the caption of an MDI form The MDI NotePad Application The MDI NotePad sample application is a simple text editor similar to the NotePad application included with Microsoft Windows. The MDI NotePad application, however, uses a multiple-document interface (MDI). At run time, when the user requests a new document (implemented with the New command on the application's File menu), the application creates a new instance of the child form. This allows the user to create as many child forms or documents, as necessary. To create a document-centered application in Visual Basic, you need at least two forms an MDI form and a child form. At design time, you create an MDI form to contain the application and a single child form to serve as a template for the application's document. To create your own MDI NotePad application : 1. From the File menu, choose New Project. 2. From the Project menu, choose Add MDI Form to create the container form.

66 66 The project should now contain an MDI form (MDIForm1) and a standard form (Form1). 3. Create a text box (Text1) on Form1. 4. Set properties for the two forms and the text box as follows. Object Property Setting MDIForm1 Caption MDI NotePad Form1 Caption Untitled MDIChild True Text1 MultiLine Text Left Top True (Empty) Using the Menu Editor (from the Tools menu), create a File menu for MDIForm1. Caption Name Indented &File mnufile No &New mnufilenew Yes 6. Add the following code to the mnufilenew_click procedure: Private Sub mnufilenew_click () `Create a new instance of Form1, called NewDoc. Dim NewDoc As New Form1 `Display the new form. NewDoc.Show End Sub This procedure creates and then displays a new instance (or copy) of Form1, called NewDoc. Each time the user chooses New from the File menu, an exact duplicate (instance) of Form1 is created, including all the controls and code that it contains. 7. Add the following code to the Form_Resize procedure for Form1: Private Sub Form_Resize () ' Expand text box to fill the current child form.

67 67 Text1.Height = ScaleHeight Text1.Width = ScaleWidth End Sub The code for the Form_Resize event procedure, like all the code in Form1, is shared by each instance of Form1. When several copies of a form are displayed, each form recognizes its own events. When an event occurs, the code for that event procedure is called. Because the same code is shared by each instance, you might wonder how to reference the form that has called the code especially since each instance has the same name (Form1). 8. Press F5 to run the application Working with MDI Forms and Child Forms When users of your MDI application open, save and close several child forms in one session, they should be able to refer to the active form and maintain state information on child forms. This topic describes coding techniques you can use to specify the active child form or control, load and unload MDI and child forms, and maintain state information for a child form. Specifying the Active Child Form or Control Sometimes you want to provide a command that operates on the control with the focus on the currently active child form. For example, suppose you want to copy selected text from the child form's text box onto the Clipboard. In the Mdinote.vbp sample application, the Click event of the Copy item on the Edit menu calls EditCopyProc, a procedure that copies selected text onto the Clipboard. Because the application can have many instances of the same child form, EditCopyProc needs to know which form to use. To specify this, use the MDI form's ActiveForm property, which returns the child form that has the focus or that was most recently active. Note At least one MDI child form must be loaded and visible when you access the ActiveForm property or an error is returned. When you have several controls on a form, you also need to specify which control is active. Like the ActiveForm property, the ActiveControl property returns the control with the focus on the active child form. Here's an example of a copy procedure that can be called from a child form menu, a menu on the MDI form, or a toolbar button: Private Sub EditCopyProc () `Copy selected text onto Clipboard. ClipBoard.SetText _ frmmdi.activeform.activecontrol.seltext End Sub

68 68 If you're writing code that will be called by multiple instances of a form, it's a good idea to not use a form identifier when accessing the form's controls or properties. For example, refer to the height of the text box on Form1 as Text1.Height instead of Form1.Text1.Height. This way, the code always affects the current form. Another way to specify the current form in code is to use the Me keyword. You use me to reference the form whose code is currently running. This keyword is useful when you need to pass a reference to the current form instance as an argument to a procedure Loading MDI Forms and Child Forms When you load a child form, its parent form (the MDI form) is automatically loaded and displayed. When you load the MDI form, however, its children are not automatically loaded. In the MDI NotePad example, the child form is the default startup form, so both the child and MDI forms are loaded when the application is run. If you change the startup form in the MDI NotePad application to frmmdi (on the General tab of Project Properties) and then run the application, only the MDI form is loaded. The first child form is loaded when you choose New from the File menu. You can use the AutoShowChildren property to load MDI child windows as hidden, and leave them hidden until you display them using the Show method. This allows you to update various details such as captions, position and menus before a child form becomes visible. You can't show an MDI child form or the MDI form modally (using the Show method with an argument of vbmodal). If you want to use a modal dialog box in an MDI application, use a form with its MDIChild property set to False Setting Child Form Size and Position When an MDI child form has a sizable border (BorderStyle = 2), Microsoft Windows determines its initial height, width and position when it is loaded. The initial size and position of a child form with a sizable border depends on the size of the MDI form, not on the size of the child form at design time. When an MDI child form's border is not sizable (BorderStyle = 0, 1, or 3), it is loaded using its design-time Height and Width properties. If you set AutoShowChildren to False, you can change the position of the MDI child after you load it, but before you make it visible Maintaining State Information for a Child Form A user deciding to quit the MDI application must have the opportunity to save work. To make this possible, the application needs to be able to determine, at all times, whether the data in the child form has changed since the last time it was saved.

69 69 You can do this by declaring a public variable on each child form. For example, you can declare a variable in the Declarations section of a child form: Public booldirty As Boolean Each time the text changes in Text1, the child form's text box Change event sets booldirty to True. You can add this code to indicate that the contents of Text1 have changed since the last time it was saved: Private Sub Text1_Change () booldirty = True End Sub Conversely, for each time the user saves the contents of the child form, the text box's Change event sets booldirty to False to indicate that the contents of Text1 no longer need to be saved. In the following code, it is assumed that there is a menu command called Save (mnufilesave) and a procedure called FileSave that saves the contents of the text box: Sub mnufilesave_click () `Save the contents of Text1. FileSave Set the state variable. booldirty = False End Sub Unloading MDI Forms with QueryUnload The booldirty flag becomes useful when the user decides to exit the application. This can occur when the user chooses Close from the MDI form's Control menu, or through a menu item you provide, such as Exit on the File menu. If the user closes the application using the MDI form's Control menu, Visual Basic will attempt to unload the MDI form. When an MDI form is unloaded, the QueryUnload event is invoked first for the MDI form and then for every child form that is open. If none of the code in these QueryUnload event procedures cancels the Unload event, then each child is unloaded and finally, the MDI form is unloaded. Because the QueryUnload event is invoked before a form is unloaded, you can give the user the opportunity to save a form before unloading it. The following code uses the booldirty flag to determine if the user should be prompted to save the child before it is unloaded. Notice that you can access the value of a public form-level variable anywhere in the project. This code assumes that there is a procedure, FileSave, that saves the contents of Text1 in a file. Private Sub mnufexit_click() When the user chooses File Exit in an MDI application, unload the MDI form, invoke

70 70 ' the QueryUnload event for each open child. Unload frmmdi End End Sub Private Sub Form_QueryUnload(Cancel As Integer, _ UnloadMode As Integer) If booldirty Then ' Call procedure to query the user and save ' file if necessary. FileSave End If End Sub 5.5 Summary Forms are the basic component of VB Applications. So, there can be multiple forms in the application depending upon the scale of the application. Each form has its own appearance, one among them can be set as start up form, some event or settings can be performed while loading and unloading of the form, form can shown or hidden. In the coming section these topics will be explained in depth. There are applications when there is a need to open forms within forms (Child forms). Thus the concept of Multiple Document Interface comes into picture. There are number of features of MDI that can be set at run time. We can load and unload MDI forms and its child forms and various other properties related to it can be set. 5.6 Self Understanding 1. Explain various steps for creating forms, is components and how to set various properties of the form. 2. What do you mean by MDI Form? How MDI Forms are created? 3. Explain the various steps for developing an MDI Application. 5.7 Suggested Readings Visual Basic 6, Black Book by Steve Holzner, Paraglypu Press. The Complete Reference, Visual Basic 6 by Noel Jerke, Tata McGraw Hill. Mastering Visual Basic 6 by Evangelos Petroutsos, Sybex. Sams Teach Yourself Visual Basic 6 in 24 hours by Greg Perry, Sams1999. Programming Microsoft Visual Basic 6.0 by Francesco Balena, Miscrosoft Press. Web Resources

71 M.Sc.(IT) PART I PAPER : MS(A)-23 VISUAL BASIC LESSON NO. 6 AUTHOR : VISHAL GOYAL ACTIVE X CONTROLS Introduction Objective ActiveX Control Fundamentals Creating the User Control Module Running the ActiveX Control Interface Wizard Advanced ActiveX Controls Summary Self-Understanding Suggested Readings Introduction ActiveX controls are the descendants of the first OCX controls that appeared when Visual Basic 4 was released. While they retain the same file extension, they're very different beneath the surface. The original OCX controls included a lot of lowlevel functionality (and consequently had to support many COM interfaces) and therefore were heavy and relatively slow. The new ActiveX controls were specifically redesigned to be embedded in HTML pages and delegate much of their functionality to their container, be it Microsoft Internet Explorer, a Visual Basic form or any other ActiveX-compliant environment. Thanks to this different approach, ActiveX controls are generally slimmer than old OCXs, download faster and load in memory more rapidly. 6.2 Objective In this lesson, you will be able to learn the two different type of ActiverX Controls, how to create User Control, how to run ActiveX Control Interface wizard and brief about advanced activex Controls 6.3 ActiveX Control Fundamentals Visual Basic 5 and 6 give you all the tools you need to create powerful ActiveX controls, which you can then reuse in all your projects. More precisely, you can create two different types of ActiveX controls: Private ActiveX controls that can be included in any type of Visual Basic project. They're saved in files with the.ctl extension and you can reuse them in any other Visual Basic project merely by adding the file to the project. (This is reuse at the source-code level.) Public ActiveX controls that can be included only in ActiveX control projects;

72 M.Sc.(IT) Part-I 72 You have to compile them into OCX files and then you can use them in any other Microsoft Windows application written in Visual Basic, Microsoft Visual C++ or any other development environment that supports ActiveX controls. (This is reuse at the binary level.) Visual Basic 5 was the first language that permitted programmers to create ActiveX controls using a visual approach. As you'll see in a moment, you can create powerful controls by simply grouping simpler controls together: These controls are known as constituent controls. By putting together a PictureBox and two scroll bar controls, for example, you can create an ActiveX control that can scroll its contents. Visual Basic also allows you to create an ActiveX control without using any constituent controls. These are the so-called owner-drawn ActiveX controls. You should also keep this in mind when working with ActiveX controls: You're used to distinguishing between two distinct types of people interacting with your program-the developer and the user. To better understand how ActiveX controls behave, you need to take another role into account, the author of the control itself. The author's job is to prepare a control that will be used by the developer to deliver an application to the user. As you'll see, the author's and developer's perspectives are sometimes different, even though the two roles might be occupied by the same person. (That is, you might act as the author of the control and then as the developer who uses it.) 6.4 Creating the UserControl Module In this section, we'll learn you how to create a sort of super-textbox control that adds extra capabilities to the regular TextBox control, such as filtering out invalid characters. The steps that you have to take any time you create a new Public ActiveX control are the following ones: 1. Add a new ActiveX control project to the environment. This new project already includes a UserControl module. (Alternatively, manually add a UserControl module from the Project menu if you're creating a Private ActiveX control.) 2. Give the project a meaningful name and a description. The former becomes the name of the control's library and the latter is the string that appears in the Components dialog box for all the projects that use this control. In this example, we'll use the project's name SuperTB and the description An enhanced TextBox control. 3. Click on the UserControl designer's window to give it the focus and then enter a value for the Name property of the control in the Properties window. In this example, you can enter SuperTextBox. 4. Place one or more constituent controls on the surface of the UserControl designer. In this example, you need to add a Label control and a TextBox control, as shown in Figure

73 M.Sc.(IT) Part-I 73 Figure The SuperTextBox control at design time. You can use any intrinsic control as a constituent control of an ActiveX control except the OLE Container control (whose Toolbox icon is disabled when an ActiveX control designer has the focus). You can also use external ActiveX controls as constituent controls, but if you use one you should ascertain that you have the legal right to encapsulate it in your own control. All the ActiveX controls in the Visual Basic package except DBGrid can be freely reused in your own ActiveX control. Always carefully read the license agreements for third-party controls before encapsulating any in your own controls. You'll find more advice about these matters in the "Licensing" section near the end of this lesson. Finally, you can create ActiveX controls that don't use constituent controls, such as the SuperLabel control that you can find on the companion CD in the same directory as the SuperText project. Now you can close the UserControl designer's window and switch to the Standard EXE project that you are using as a test client program. You'll notice that a

74 M.Sc.(IT) Part-I 74 new icon is now active in the Toolbox. Select it and drop an instance of your brand new control on the form, as shown in Figure. Congratulations! You've just created your first ActiveX control. I want to draw your attention to one specific point in the previous description. You need to explicitly close the ActiveX control designer window before using the control on the test container form. If you omit this step, the icon in the Toolbox stays inactive. In fact, Visual Basic activates the ActiveX control and prepares it for siting only when you close the designer window. Siting refers to the instant an ActiveX control is placed on its container's surface. You need to keep in mind that you have to deal with two different instances of the control, the design-time instance and the run-time instance. Unlike other Visual Basic modules, a UserControl module must be active even when the test project is in design mode. This is necessary because the control must react to the programmer's actions, such as entering the value of a property in the Properties window or resizing the control on the parent form. When you're working with the ActiveX control designer open, however, the control itself is in design mode and therefore can't be used in a form. To run an ActiveX control, you need to close its designer window, as I explained earlier. Figure: An instance of the SuperTextBox control on a testform. The Properties window includes a number of properties that have been defined for you by Visual Basic.

75 M.Sc.(IT) Part-I Running the ActiveX Control Interface Wizard Our first version of the SuperTextBox control doesn't do anything useful yet, but you can run the client application and ensure that everything is working and that no error is raised. To turn this first prototype into a useful control, you need to add properties and methods and write the code that correctly implements the new features. To complete the SuperTextBox control, you need to add all the properties that the user of this control expects to find such as ForeColor, Text and SelStart. A few of these properties must appear in the Properties window; others are run time_only properties. You also need to add other properties and methods that expand the basic TextBox functionality-for example the FormatMask property (which affects how the control's contents is formatted) or the Copy method (which copies the control's contents to the Clipboard). In most cases, these properties and methods map directly to properties and methods of constituent controls: for example, the ForeColor and the Text properties map directly to the Text1 constituent control's properties with the same names, whereas the Caption property corresponds to the Caption property of the Label1 constituent control. To facilitate the task of creating the public interface of an ActiveX control and writing all the delegation code, Visual Basic includes the ActiveX Control Interface Wizard. This add-in is installed with the Visual Basic package, but you might need to explicitly load it from within the Add-In Manager dialog box. In the first step of the wizard, you select the interface members, as shown in Figure below. The wizard lists the properties, methods and events that are exposed by the constituent controls and lets you select which ones should be made available to the outside. In this case, accept all those that are already in the rightmost list except BackStyle and then add the following items: Alignment, Caption, Change, hwnd, Locked, MaxLength, MouseIcon, MousePointer, PasswordChar, SelLength, SelStart, SelText, Text, plus all the OLExxxx properties, methods and events. These members ensure that the SuperTextBox control matches nearly all the capabilities of a regular TextBox control. A few properties have been left out-namely, MultiLine and ScrollBars. The reason for these exclusions will be clear later.

76 M.Sc.(IT) Part-I 76 Figure: The first step of the ActiveX Control Interface Wizard. You can also highlight multiple items and add all of them in one operation. Note Unfortunately, the ActiveX Control Interface Wizard lets you include many properties, methods and events that you should never add to the public interface of your controls-for example, the ToolTipText, CausesValidation, WhatsThisHelpID and Validate event. As a matter of fact, Visual Basic automatically adds these members to any ActiveX control that you create, so you don't need to specify them unless you plan to use the control in environments other than Visual Basic. More on this later. In the next step, you define all the custom properties, methods and events that your ActiveX control exposes. You should add the FormatMask, FormattedText, CaptionFont, CaptionForeColor,and CaptionBackColor properties; the Copy, Clear, Cut, and Paste methods; and the SelChange event. In the third step, you define how the public members of the ActiveX control are mapped to the members of its constituent controls. For example, the Alignment public property should be mapped to the Text1constituent control's Alignment property. The same holds true for the majority of the members in the list, and you can speed up mapping operations by selecting all of members and assigning them to the Text1control, as shown in Figure below.

77 M.Sc.(IT) Part-I 77 Figure: In the third step in the ActiveX Control Interface Wizard, you canmap multiple members by highlighting them in the leftmost list and then selectinga constituent control in the Control combo box on the right. A few members-for example, the Caption property-map to the Label1 constituent control. You must specify the name of the original member in the constituent control when the two names differ, as in the case of the CaptionForeColor, CaptionBackColor and CaptionFont properties that correspond to the Label1's ForeColor, BackColor and Font properties, respectively. At other times, you have to map a public member to the UserControl itself-for example, the Refresh method. There might be members that can't be directly mapped to any constituent control, and in the fourth step of the wizard you define how such members behave. For example, you declare that the Copy, Cut, Clear and Paste methods are Subs by setting their return type to Empty. Similarly, you specify that FormatMask is a String property that can be read and modified either at design time or run time, whereas the FormattedText isn't available at design time and is read-only at run time. You should also specify an empty string as the default value for these three properties because even if you change the property type to String, the Wizard doesn't automatically change the value 0 that it initially set as the default. You must enter the argument list for all methods and events, as well as a brief description for each member, as shown in Figure below.

78 M.Sc.(IT) Part-I 78 The otherwise excellent ActiveX Control Interface Wizard has some limitations, though. For example, you can neither define properties with arguments, nor can you enter a description for all the custom properties-the CaptionFont and CaptionForeColor properties in this case-that are mapped to constituent controls. Caution Beware, international programmers! Being written in Visual Basic, the ActiveX Control Interface Wizard inherits a curious bug from the language if the Regional Setting established in the Control Panel isn't English. When Boolean constants True and False are concatenated in a string, the value you obtain is the localized string corresponding to that value. (For example, in Italian you get the strings "Vero" and "Falso", respectively.) Thus, in these circumstances the Wizard doesn't produce correct Visual Basic code and you might have to edit it manually to run it. Or, if you prefer, you can set the Regional Setting to English if you plan to run the Wizard often in a programming session. Figure: In the fourth step in the ActiveX Control Interface Wizard, you decide the syntax of methods and events and whether properties are read/write or read-only at run time. You're finally ready to click on the Finish button and generate all the code for the Super Text Box control. If you go back to the instance of the control on the test

79 M.Sc.(IT) Part-I 79 form, you'll notice that the control has been grayed. This happens each time you change the public interface of the control. You can make the ActiveX control active again by right-clicking on its parent form and selecting the Update UserControls menu command. 6.6 Advanced ActiveX Controls If you can create a Visual Basic form, you can create a Visual Basic advance ActiveX control - The steps and skills necessary to create controls with VB 5.0 are practically identical to those used to create a form. What's more, control creation possibilities are virtually unlimited. When should you create an ActiveX control? Think of an ActiveX control first, as a reusable User Interface component. It is, of course, possible to create invisible controls that provide reusable functionality that has nothing to do with a user interface, but before you make a final decision to solve a problem using a control, you should be aware of other new features in Visual Basic 5.0 that may provide a better fit for your particular situation. For instance, one of the major new features in Visual Basic 5 is that ActiveX components can raise events. This applies to ActiveX DLL components and ActiveX EXE components. As a result, many tasks that previously required ActiveX controls can now be implemented using ActiveX components. The following is a brief summary of the major characteristics of the two technologies that should prove helpful in deciding which you should use for a given task: ActiveX components (EXE or DLL servers): These are generally used to encapsulate business rules, algorithms and data services. They provide objects with associated functionality to other components or applications - even ActiveX controls. ActiveX components can contain forms for a user interface, but are not designed to be seamlessly placed on containers in the same way as ActiveX controls. One of the major new features of ActiveX components is Multi-threading which can provide significant performance improvements in many situations associated with larger enterprise systems and multithreaded applications. ActiveX controls: These are generally reusable User Interface components that work in Visual Basic, a web page or any other ActiveX host. When used in a web page, they are a component in the web page and are controlled by VBScript or JavaScript. ActiveX controls have the ability to be sited on a container and Support design time programming characteristics including: o Support for property pages. o The ability to store property values set at design time in a location specified by the container. o The ability to interact with the container's property browser if one exists.

80 M.Sc.(IT) Part-I Summary There are two different types of ActiveX controls: Private ActiveX Controls that can be included in any type of Visual Basic project. They're saved in files with the.ctl extension, and you can reuse them in any other Visual Basic project merely by adding the file to the project. Public ActiveX controls that can be included only in ActiveX control projects; You have to compile them into OCX files and then you can use them in any other Microsoft Windows application written in Visual Basic, Microsoft Visual C++, or any other development environment that supports ActiveX controls. You can create ActiveX Controls as per your needs. For example, In the above sections you have learnt creating sort of Super Text Box that gives you more featured text box than a regular text box. 6.8 Self Understanding Q1. What do you mean by ActiveX Control? Explain various categories of ActiveX Controls? Q2. What do you mean by Private ActiveX Controls? Write various steps for creating it taking the example. Q3. What do you mean by Public ActiveX Controls? Write various steps for creating it taking the example. 6.9 Suggested Readings 1. Visual Basic 6 Black Book by Steve Holzuer, Paraglypu Press. 2. Visual Basic 6 : The Complete Reference by Noel Jerke, Tata McGraw Hill. 3. Mastering Visual Basic 6 by Evangelos Petroutsos, Sybex. 4. Sams Teach Yourself Visual Basic 6 in 24 hours by Greg Perry, Sams Programming Microsoft Visual Basic 6.0 by Francesco Balena, Miscrosoft Press. Web Resources :

81 M.Sc. (IT) PART I PAPER : MS(A)-123 VISUAL BASIC LESSON NO. 7 AUTHOR : VISHAL GOYAL ACTIVE X CONTROLS INTERFACE WIZARD Objective Starting out with ActiveX controls Design your Control The Three Four Control Models ActiveX Control Interface Wizard Key Objects Advance Design Features Summary Self Understanding Suggested Readings 7.1 Objective In this lesson, you will be able to understand about how to create ActiveX Control, How ActiveX Control Interface Wizard can be used, Some key objects and advance design features related to ActiveX Controls. 7.2 Starting out with ActiveX controls Design your Control Visual Basic's ease of use has often tempted programmers to go directly to coding, without bothering to design their application. The same will probably be true with ActiveX controls. Before you even open a new control project, you should decide on the following: Which control model to use (more on this in a moment). Which standard properties and methods will you implement. Which standard events will you implement. The characteristics of the user interface for your control (design time and runtime). A large part of creating a quality ActiveX control lies in the details - verifying the design and runtime characteristics of every property, method, event and user input. Defining these ahead of time will go a long way towards helping you succeed The Three Four Control Models The Visual Basic 5.0 documentation suggests that there are three control models. For the purposes of this paper, there are actually four:

82 M.Sc. (IT) Part-I Enhance an Existing Control In this model your control contains a single constituent control. Most of the properties, methods and events of the constituent control are mapped to public properties, methods and events of your control. Your control can add new properties or events or otherwise modify the behavior of the standard control. For example: you could implement a list box that has built in search capabilities. The biggest advantage of enhancing an existing control is that it is extremely easy to do. The ActiveX control interface wizard can do much of the work of mapping public properties, methods and events to those of constituent controls or the UserControl object. Even though this is the easiest, There are reasons why you might want to use another approach: Because each constituent control defines its own behavior and drawing characteristics, there are limits to what you can do to modify the control. There are occasions where you can use advanced subclassing techniques to perform some modifications to the behavior of the constituent controls, but this is a rather advanced technique that requires a good understanding of the Win32 API and, depending on the control, some trial and error as you attempt to figure out how the control responds to different Windows messages. Constituent controls are always in run mode when your control is active, making it impossible to set the control's design time properties even though the control's container is in design mode. For example: if you want to create an enhanced list box that supported both single and multiple selection modes, you would need to place two separate list box controls into your control - one set to single selection and the other to multiple selection. You would then show one of these controls depending on your control's configuration. This approach also requires you to manage properties carefully - when the developer using your control sets a property, you need to be sure to set the property for the visible control. This technique breaks down when you have more than one or two design time properties to deal with, as the number of constituent controls you need doubles with each one. There are, however, other solutions to this problem, as you will see shortly. As soon as you go beyond the built in controls or redistributable controls provided by Microsoft, you run into licensing and copyright issues. In order for your control to work in Visual Basic's design environment, each of the constituent controls must be properly licensed Build a complex control from constituent controls This model is a superset of the Enhanced control model. The major differences are as follows:

83 M.Sc. (IT) Part-I 83 Instead of mapping your public properties and events to a single control, you map them to any or all of the constituent controls. It is also possible to map the same property to more than one control. You can map multiple constituent events to one event in your control. For example: in a control consisting of two command buttons, the click event from both constituent controls can be mapped to a single parameterized click event as follows: Event Click (ByVal ButtonNum%) Private Sub Command1_Click () RaiseEvent Click (1) End Sub Private Sub Command2_Click () RaiseEvent Click (2) End Sub Private Sub UserControl_Click() RaiseEvent Click (0) End Sub You can map a single class property to multiple controls as shown here with the Font property: Public Property Get Font () As Font Set Font = Command1.Font End Property Public Property Set Font(ByVal New_Font As Font) Set Command1.Font = New_Font Set Command2.Font = New_Font PropertyChanged "Font" End Property Why do we return the font property from the Command1 object in the Property Get statement? In truth, it doesn't matter. Both of the constituent controls reference the same Font object, so you can retrieve a reference from any of them and it will work. This model of control creation suffers from exactly the same advantages and disadvantages as the Enhanced control approach. It also has the characteristic that the UserControl itself cannot receive the focus - only th2.3 e constituent controls receive focus User Drawn Controls The two prior approaches have the advantage of being incredibly easy to use. Now let's look at an approach whose major advantages is incredible flexibility - it allows you to do almost anything. User drawn controls represent one of the most exciting approaches for control creation, though it also represents a jump in complexity. With this type of control you work primarily with properties and events of the UserControl object. You can include

84 M.Sc. (IT) Part-I 84 invisible constituent controls if you wish, but as soon as you add a visible constituent control, the behavior of the control changes in that the UserControl object can no longer receive the focus. You will usually use the UserControl_Paint event to draw to the control. All of the appearance characteristics and behavior of the control is defined by your code. When implementing a user drawn control, you must define the following: Design time appearance. It is possible to create a control that a developer can interact with at design time by setting the UserControl object's EditAtDesignTime property to True, but this is relatively uncommon. Run time appearance and behavior when the control has the input focus. Run time appearance and behavior when the control does not have the input focus. The biggest advantage of user drawn controls is their flexibility. Because you determine the behavior and appearance of the control at all points in its life, there are few limits on what your control can do. The biggest disadvantage of user drawn controls derives from this fact. Not only can you determine the behavior and appearance of the control - you MUST do so. This can rapidly get very complex. Keep in mind that when you are implementing a user drawn control, you are not limited to the functionality inherent in Windows - you have access to all of the Win32 API functions as well - and the Win32 API includes some extremely powerful graphic and text output functions that go far beyond what is implemented by Visual Basic (and are faster besides). Also watch for third party products that include commercial quality controls with source code. They not only offer controls that you can use in your application, but a great way to learn advanced control creation techniques The fourth control model: Create Your Own Window The Windows operating system defines standard classes of windows such as listboxes, text boxes, outline windows, common dialogs and so on. Many ActiveX controls and Visual Basic intrinsic controls are actually superclasses of these standard windows. For example: The Visual Basic list box control actually creates a Windows listbox window. It intercepts the underlying messages for the window and maps them into control properties and events. This allows a relatively simple control to take full advantage of controls that are built into the operating system. The problem with this approach is that your control can suffer from limitations that are introduced at either level of the hierarchy. Not every ActiveX control implements all of the functionality of the underlying Windows class. For example: even the Visual Basic ListBox control does not allow you to set tab locations in a list box, a feature that is built into the operating system's implementation. With Visual Basic 5.0 authored ActiveX controls you are also limited in that any design time only properties cannot be changed at runtime.

85 M.Sc. (IT) Part-I 85 Why is this? Because with a LISTBOX class window, certain characteristics such as whether the control can handle multiple selections, must be determined as the window is created. In order to change this characteristic, it is necessary to destroy and recreate the window. Visual Basic 5.0 created controls cannot arbitrarily destroy and recreate a constituent control - something that is necessary to change characteristics such as support for multiple selections. But there is a solution. Instead of using the Visual Basic listbox, you can go directly to the windows class itself and create your own LISTBOX class window on top of the UserControl. Because you created the window yourself, you can destroy it and recreate it at will allowing you to change these "design time" characteristics any time you wish - even at the container's runtime if you so choose. The advantage of this approach is that it allows you to take full advantage of window classes that are defined by the operating system. But there are a number of disadvantages: This approach requires a good understanding of Windows API techniques and the operation of the windows class. This approach can involve quite a bit of work - especially for complex controls. But there is one factor to keep in mind. If you are creating a control for your own use, you may not need to expose all of the functionality offered by the operating system for a particular window class. A commercial developer will usually expose as many of the features of the underlying control as possible to make the control useful to as many programmers as possible. But when you take this approach for your own applications, you can concentrate on those features that you need and not waste time implementing and testing others. So this model may be more practical than it seems at first glance. 7.3 ActiveX Control Interface Wizard The ActiveX control interface wizard can be very helpful in taking some of the grunt work out of implementing your controls. It is especially useful with regards to supporting standard properties, methods and events in your control. It is also an excellent learning tool, since it allows you to see Microsoft's recommended way to handle certain types of properties. The wizard begins with a screen that asks you which standard properties will be supported in your control. If your control is intended to be invisible at runtime, you should remove all of the standard properties from the control at this time. Otherwise, you should review the list to see if it matches the design specification that you should have created before running the wizard. The default list suggested by the wizard is a good starting point. I would suggest that you add the hwnd property as well, as it will make it easier to use your control with more advanced applications

86 M.Sc. (IT) Part-I 86 that use Win32 API calls. Do not arbitrarily add every available property to the list many of them are intended for internal use by the control and should not be exposed. The next screen prompts you for custom properties, methods and events. Remember that you can add members to your control at any time by editing the code for the control. It is entirely up to you as to whether you find the wizard more convenient. This is one area in which Visual Basic control development differs significantly from Visual C++. The Visual C++ class wizard edits code in several files including the header file, the source file and the ODL (Object Description Language) file, performing tasks that are difficult for even experienced programmers to do correctly. The Visual Basic ActiveX control interface wizard produces relatively little code and that code is so simple that even beginning programmers can understand it. It is thus a very reasonable approach to add control members by just editing the control's code module. The next wizard screen maps the control's public members to those of the constituent controls or the UserControl object. The code produced by the wizard to map members in this manner is very educational, though it may not always match the functionality that you desire. The final wizard screen lets you specify the characteristics of those members that are not mapped. The first thing that you should do is choose a property type other than the default variant type. While there are some situations where variant properties are appropriate, by and large they serve only to impose additional testing complexity in return for a loss in performance. Not a good deal by any measure. You can also set the member description and read/write characteristics. Once again, these are all settings that can be made quite easily without the wizard if you prefer to do so. You should also use the Tools-Procedure Attributes menu command to bring up the Procedure Attributes dialog box and make sure that the procedure ID is correct for each standard property. Regardless of whether you choose to use the wizard or write your code directly, it is imperative that you understand how the code that the wizard produces works. This is because it is unlikely that the code produced by the wizard will match your needs exactly, especially in a sophisticated control or one that is made up of multiple constituent controls where the members of the control do not map directly to those of constituent controls. Remember that the wizard does not provide any range checking or validation on your properties - something which you should always do. Learn the Fundamentals There are several subjects relating to control development that you do not need to understand well in order to muddle through a simple control. But a thorough understanding of them will help a great deal when designing and implementing sophisticated controls.

87 M.Sc. (IT) Part-I Key Objects There are four main objects that you will work with when creating ActiveX controls using Visual Basic: The UserControl object is the heart and soul of every VB ActiveX control. It is the object that the container interacts with directly. All user interaction is through this object and its events drive the behavior of your control. The Ambient object provides you with information about your control's container. The most important ambient property is the UserMode property which tells you whether your control's container is in design mode or run mode (for those containers that support this features). The Extender object is the object that a developer using your control will use to communicate with your control. It contains not only the public members of your control, but additional properties that are added by the container. For example: The Left and Top property describes the location of the upper left corner of your control. You do not need to implement these properties because the container adds them to your control's extender object. The control object itself contains the members that you define for the control. These are the public properties, methods and events that a developer will use to work with your control. The meaning of design time and run-time One of the most confusing issues that a new control developer faces when using Visual Basic to create controls is the difference between the control's design time and runtime and the container's design time and runtime. The following table summarizes the possible control states: Control / Container Design time Runtime Control/Container Design Time Runtime Design time (Designer open) Control disabled (hatched lines) Control disabled (hatched lines) Runtime (Designer closed) Control design mode Control run mode When the control is in design mode, the control is disabled and appears with hatched lines in any container that is referencing the control. When the control's designer is closed, the control is running - regardless of the mode of the container. You will need to define both the design time and runtime characteristics of your control. COM The Component Object Model is the underlying technology on which all ActiveX components are based. While you can accomplish a great deal using Visual Basic

88 M.Sc. (IT) Part-I 88 without understanding COM, learning at least the principles of how it works can help you take full advantages of all of the features of Visual Basic. It will certainly help you understand how those features work. Error Handling Regardless of whether you use the ActiveX control interface wizard or code support for properties yourself, you should always review your control's members to incorporate validation to make sure that they cannot be set to illegal values. You should review the list of trappable Visual Basic errors, since you can and should, use these standard error codes where appropriate. This will help ensure that your control is fully compatible with containers that expect certain standard errors to be raised in particular situations. For example: you should raise error 380 if your control detects an attempt to set a property to an invalid value. Building Advanced Controls There is a saying that the most important part of solving any difficult problem is knowing that an answer exists. The intent in this section is not to try to teach you advanced techniques, but rather to point out some of the techniques that are possible so that when you reach the point of needing them, you'll know that a solution does exist. Persistence can go beyond properties An ActiveX control can save and load design time properties by using the PropBag object during the UserControl's WriteProperties and ReadProperties events. Both the ActiveX control interface wizard and the typical control samples tend to show individual properties being saved in this manner. But you should be aware that there is absolutely no relation between the property saving mechanism and the properties themselves. The labels that you use in the PropBag functions do not need to be names of actual properties. In other words, you can save any data that you wish using any label that you wish. This means that the property persistence mechanism for controls should be thought of as a way to save the design time characteristics of a control - not just a way to save properties. Of course, if you are saving properties, you should use the actual property name as a label for the PropBag functions in order to improve the readability of both your control code and the forms that are created using your control. DataBinding can go beyond standard control databinding The easy way to databind a property in a control is to let Visual Basic do it for you. This is accomplished by defining a property and setting it's attributes using the Tools-Procedure Attributes dialog box. There are four available selections for databinding: Property is data bound. Check this box to cause the property to be bound.

89 M.Sc. (IT) Part-I 89 This property binds to the DataField. This property becomes the "default" bound property if the control has more than one bound property. Show in DataBindings collection at design time. Allows the developer using your control to edit the data binding at design time. Property will call CanPropertyChange before changing. This options informs the container that your control will call CanPropertyChange before changing bound property values. To understand these better, you need to have an idea of what happens when you set a property to be bound. Visual Basic adds four properties to the control's extender object: 1. The DataSource property is used by the developer to select a data control to which your control will be bound. 2. The DataField property is used by the developer to select a field in the database to which one of your control's properties will be bound (the one that has its "This property binds to Datafield" check box set. You should always check this box for at least one property). 3. The DataBindings property appears in the VB window to allow the developer to bind other bound properties in your control to various fields in the database. All bound controls whose procedure attribute specifies "Show in DataBindings collection at design time" will appear in the DataBindings dialog. The control's Extender object also exposes a DataBindings collection which contains a DataBinding object for each bound property. This object contains the binding information for the property. 4. The DataChanged property indicates if any of the bound properties have been changed. One important thing to keep in mind is that databinding is supported by the container. Containers are not required to support databinding and not all that do will support binding of more than one property in a control. Keep in mind, however, that your ActiveX control has full access to the Microsoft Data Access Library and all the database features that are available to any Visual Basic control or component. As such, it is possible to create more sophisticated models of databinding - for example: you can create a list box that is bound to a field, where each entry in the list box corresponds to a different record. You can have multiple list boxes in your control, each of which is bound to a different data source. To do this you will have to define your own properties to allow the user to set the sources for the data, which can be tricky and is definitely harder than letting Visual Basic do the work for you. However, if the level of data binding that you need goes beyond that supported with the built in databinding features, the extra effort can make even the most sophisticated design possible.

90 M.Sc. (IT) Part-I 90 Interface Extensions Even this early in the life of Visual Basic 5.0, I have already heard people make the statement that you can't write serious ActiveX controls using Visual Basic, and that to do so you must go to tools such as Visual C++. This is absurd. Visual Basic's great strength has always been that it encapsulates a significant amount of functionality in the language itself, then allows you to accomplish virtually anything by selectively using Win32 API functionality or third party products. This is definitely the case with ActiveX controls. Visual Basic created ActiveX controls can handle many types of controls without going beyond the core language. In fact, in one area - the ability to use constituent controls, Visual Basic is far superior to Visual C++. The following techniques are available for extending Visual Basic when it comes to creating ActiveX controls: Win32 API Functionality The Win32 API provides thousands of functions that cover every aspect of Windows, and the vast majority of them can be called safely from your ActiveX control project. The most important of these for most control developers are likely to be those relating to drawing, as the Win32 API provides drawing functionality that is vastly greater than that provided by Visual Basic alone. Subclassing and Private Windows Visual Basic now provides native support for private windows and in-process subclassing, though you should use it with great caution. You should, in any case, perform these operations in a separate ActiveX DLL component and not in your control code. This is because adding these features to your control code makes it nearly impossible to debug your control. This is because when your control enters break mode, no Visual Basic code runs in your control - including the code that implements the private window or subclassing operation. This is a case where using a commercial subclasser or window management tool may save you time and effort. Overriding Standard Interfaces Every ActiveX control works by supporting standard interfaces within the control, regardless of the language used to implement the control. These interfaces are part of the ActiveX specification. Visual Basic's standard implementation of these interfaces may not expose the full functionality of the interface to you as a control developer. However, you can use a third party tool such as Desaware's SpyWorks to override the behavior of a standard interface. For example: the IPerPropertyBrowsing interface is used internally to control the display of property information and enumeration lists in the VB property window. By overriding this interface you can display anything you want in the property window entry for a given property and you

91 M.Sc. (IT) Part-I 91 can customize the drop down list with entries that do not correspond to an enumeration. Plus, you can use drop down lists for non enumerated properties. Adding New Interfaces You should be aware that the Implements statement allows you to add interfaces to your Visual Basic classes and objects. This includes your ActiveX control object. Under Visual Basic 5.0, the Implements statement only supports a kind of interface called an "automation interface", one that is based on an interface called IDispatch. However there are certain non-automation interfaces defined by the ActiveX specification that can be used to extend the functionality of your ActiveX control. This is another task that can be accomplished using third party products. The IObjectSafety interface is a good example of this. This interface allows a control to report to a container that it is safe for initialization or safe for scripting - an important feature for any control that is intended to be downloaded through the Internet or a corporate intranet. The Visual Basic setup wizard allows you to mark a control as safe by adding an entry into the registry. However, if you implement IObjectSafety in your control, not only can you avoid modifying the registry (and the overhead of a registry lookup), but you can create a control that supports both a safe and unsafe mode. On an Internet download, the browser can request that the control enter safe mode. You can detect this request and disable any features in your control that could harm the client user's system. However, a developer using the control within an application would be able to take advantage of all of the control's features, since Visual Basic does not request that a control enter safe mode. 7.5 Advance Design Features Like the BASIC programming language, Visual Basic was designed to be easy to learn and use. The language not only allows programmers to create simple GUI applications, but can also develop complex applications. Programming in VB is a combination of visually arranging components or controls on a form, specifying attributes and actions of those components and writing additional lines of code for more functionality. Since default attributes and actions are defined for the components, a simple program can be created without the programmer having to write many lines of code. Performance problems were experienced by earlier versions, but with faster computers and native code compilation this has become less of an issue. Although programs can be compiled into native code executables from version 5 onwards, they still require the presence of runtime libraries of approximately 2 MB in size. This runtime is included by default in Windows 2000 and later, but for earlier versions of Windows or Windows Vista, it must be distributed together with the executable.

92 M.Sc. (IT) Part-I 92 Forms are created using drag and drop techniques. A tool is used to place controls (e.g., text boxes, buttons, etc.) on the form (window). Controls have attributes and event handlers associated with them. Default values are provided when the control is created, but may be changed by the programmer. Many attribute values can be modified during run time based on user actions or changes in the environment, providing a dynamic application. For example, code can be inserted into the form resize event handler to reposition a control so that it remains centered on the form, expands to fill up the form, etc. By inserting code into the event handler for a keypress in a text box, the program can automatically translate the case of the text being entered or even prevent certain characters from being inserted. Visual Basic can create executables (EXE files), ActiveX controls, DLL files, but is primarily used to develop Windows applications and to interface web database systems. Dialog boxes with less functionality can be used to provide pop-up capabilities. Controls provide the basic functionality of the application, while programmers can insert additional logic within the appropriate event handlers. For example, a drop-down combination box will automatically display its list and allow the user to select any element. An event handler is called when an item is selected, which can then execute additional code created by the programmer to perform some action based on which element was selected, such as populating a related list. Alternatively, a Visual Basic component can have no user interface, and instead provide ActiveX objects to other programs via Component Object Model (COM). This allows for server-side processing or an add-in module. The language is garbage collected using reference counting, has a large library of utility objects, and has basic object oriented support. Since the more common components are included in the default project template, the programmer seldom needs to specify additional libraries. Unlike many other programming languages, Visual Basic is generally not case sensitive, although it will transform keywords into a standard case configuration and force the case of variable names to conform to the case of the entry within the symbol table entry. String comparisons are case sensitive by default, but can be made case insensitive if so desired. The Visual Basic compiler is shared with other Visual Studio languages (C, C++), but restrictions in the IDE do not allow the creation of some targets (Windows model DLL's) and threading models. Derivative languages Microsoft has developed derivatives of Visual Basic for use in scripting. Visual Basic itself is derived heavily from BASIC and subsequently has been replaced with a.net platform version. Some of the derived languages are: Visual Basic for Applications (VBA) is included in many Microsoft applications (Microsoft Office), and also in many third-party products like SolidWorks,

93 M.Sc. (IT) Part-I 93 AutoCAD, WordPerfect Office 2002 and ArcGIS. There are small inconsistencies in the way VBA is implemented in different applications, but it is largely the same language as VB6 and uses the same runtime library. VBScript is the default language for Active Server Pages. It can be used in Windows scripting and client-side web page scripting. Although it resembles VB in syntax, it is a separate language and it is executed by vbscript.dll as opposed to the VB runtime. ASP and VBScript should not be confused with ASP.NET which uses the.net Framework for compiled web pages. Visual Basic.NET is Microsoft's designated successor to Visual Basic 6.0, and is part of Microsoft's.NET platform. Visual Basic.Net compiles and runs using the.net Framework. It is not backwards compatible with VB6. An automated conversion tool exists, but for most projects automated conversion is impossible. Star Basic is a Visual Basic compatible interpreter included in Star Office suite, developed by Sun Microsystems. 7.6 Summary Visual Basic is not only the easiest way to create ActiveX controls, I expect it will soon become the most popular way to create all types of controls, from simple downloadable controls to complex controls intended primarily for application developers. If you take the time to understand the underlying technology, and are prepared to learn and use all of the tools available for extending Visual Basic, there will be few tasks, if any, that you cannot accomplish in Visual Basic when it comes to creating advanced ActiveX controls. 7.7 Self Understanding Q1. Explain the four Control Models for Active X Controls? Q2. What do you mean by design time and run time? Illustrate your answer with the help of example. Q3. Explain some advanced features related to ActiveX Controls Suggested Readings 1 Visual Basic 6 Black Book by Steve Holzuer, Paraglypu Press. 2 Visual Basic 6 : The Complete Reference by Noel Jerke, Tata McGraw Hill. 3 Mastering Visual Basic 6 by Evangelos Petroutsos, Sybex. 4 Sams Teach Yourself Visual Basic 6 in 24 hours by Greg Perry, Sams Programming Microsoft Visual Basic 6.0 by Francesco Balena, Miscrosoft Press. Web Resources :

94 M.Sc. (IT) PART I LESSON NO. 8 PAPER : MS(A)-123 VISUAL BASIC AUTHOR : VISHAL GOYAL EXTERNAL FUNCTIONS IN VISUAL BASIC Declaring and using external functions in Visual Basic Visual Basic Functions in Microsoft Access Visual Basic Conversion Functions Creating your own ActiveX control Suggested Readings Declaring and using external functions in Visual Basic Any Fortran subroutine called from Visual Basic must reside in a dynamic link library (DLL). A DLL file is nothing more than a collection of functions and subroutines that can be loaded dynamically, when your Visual Basic program requests one of its components at run time. Because DLL procedures reside in files that are external to your Visual Basic application, you must specify where the procedures are located and identify the arguments with which they should be called. You provide this information with the Declare statement. Once you have declared a DLL procedure, you can use it in your code just like a native Visual Basic procedure. To declare a DLL procedure, you add a Declare statement to the declarations section of the code window. If the procedure returns a value, write the declare as a function: Declare Function publicname Lib "libname" [Alias "alias"] [([[ByVal] variable [As type ] [,[ByVal] variable [As type]]...])] As Type If a procedure does not return a value, write the declare as a Sub: Declare Sub publicname Lib "libname" [Alias "alias"] [([[ByVal] variable [As type] [,[B yval] variable [As type]]...])] DLL procedures declared in standard modules are public by default and can be called from anywhere in your application. DLL procedures declared in any other type of module are private to that module, and you must identify them as such by preceding the declaration with the Private keyword. Procedure names are case-sensitive in 32-bit versions of Visual Basic. The Lib clause in the Declare statement tells Visual Basic where to find the.dll file that contains the procedure. When you're referencing one of the core Windows libraries (User32, Kernel32, or GDI32), you don't need to include the file name extension: Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long For other DLLs, such as those created in Fortran, the Lib clause is a file specification that can include a path:

95 M.Sc. (IT) Part-I 95 Declare Function lzcopy Lib "c:\windows\lzexpand.dll" (S As Integer, D As Integer) A s Long If you do not specify a path for libname, Visual Basic will search for the file in the following order: Directory containing the.exe file Current directory Windows system directory (often but not necessarily \Windows\System or \winnt\system32) Windows directory (often but not necessarily \Windows or \winnt) Path environment variable Occasionally, a DLL procedure has a name that is not a legal identifier. It might have an invalid character (such as a hyphen) or the name might be the same as a Visual Basic keyword (such as GetObject). When this is the case, use the Alias keyword to specify the illegal procedure name. For example, some procedures in the operating environment DLLs begin with an underscore character. While you can use underscores in Visual Basic identifiers, you cannot begin an identifier with an underscore. To use one of these procedures, you first declare the function with a legal name, then use the Alias clause to reference the procedure's real name: Declare Function lopen Lib "kernel32" Alias "_lopen" (ByVal lppathname As String, B yval ireadwrite As Long) As Long In this example, lopen becomes the name of the procedure referred to in your Visual Basic procedures. The name _lopen is the name recognized in the DLL. You can also use the Alias clause to change a procedure name whenever it's convenient. If you do substitute your own names for procedures (such as using WinDir for GetWindowsDirectoryA), make sure that you thoroughly document the changes so that your code can be maintained at a later date. The Alias clause is also useful to adjust the name of functions and subroutines created with some Fortran compilers. Some compilers by default export DLL subroutines with all lowercase or uppercase names, while others prefix an underscore character ("_") and suffix "@nn" to the name of exported subroutines. You can use the Alias clause to make these procedures accessible to Visual Basic with a friendlier name. For example, let's say you have a subroutine in a Fortran DLL that has been exported with the name _ARCCOSINE@4, you can alias this name into a friendlier name with Declare Sub ArcCosine Lib "MyFortran.dll" Alias "_ ARCCOSINE@4" (ByRef X As Double) As Double 8.2 Visual Basic Functions in Microsoft Access Web site navigation for our Visual Basic function discussion is listed to the right. Of course, Access gives you the ability to create any VB function you can think of. But it is good to know what VB functions already exist so you don't re-invent the

96 M.Sc. (IT) Part-I 96 wheel. We will give the syntax, discussion and examples of each of the functions listed to the left as we go down the page. We didn't create these functions so most of the syntax and usage information is taken from the Microsoft Access Visual Basic help system. We have added our own notes and discussion to help clarify the functions where we can. Let's get started! Microsoft Access Visual Basic Abs Function The Visual Basic Abs function simply removes the sign from a number returning a positive value. This is useful for calculating the absolute difference between values and adding them differences up. You would first use the Abs function before adding the values. This example uses the Abs function to compute the absolute value of a number. Dim TheNumber TheNumber = Abs(19.2) ' Returns the absolute value '19.2'. TheNumber = Abs(-19.2) ' Returns the absolute value '19.2'. Visual Basic Array Function for Microsoft Access The VB Array function establishes an array (list) of values. To create a constant array you define the array name as a variant. See below; Dim myarray as Variant myarray = Array(5,10,15,21) You can then refer to an array element by its integer position starting at 1: Msgbox myarray(2) The Msgbox above will display the number 10 Visual Basic Asc Function The VBA Asc function returns the ASCII character code for the 1st letter in the Asc argument: TheNumber = Asc("A") ' Returns 65. TheNumber = Asc("a") ' Returns 97. TheNumber = Asc("Avalanche") ' Returns 65. The arctangent is used to calculate the angles of a right triangle. It works opposite of the tangent function. While tangent will find the ratio of the two sides of a right triangle when given an angle, arctangent can find the angle given the ratio. This example uses the Atn function to calculate the value of pi. Dim pipi = 4 * Atn(1) ' Calculates the numeric result for pi. Visual Basic CallByName Function The CallByName() function is used to manipulate objects by either executing a method or setting the value of a property. Syntax CallByName(object, procname, calltype,[args()]) The CallByName function syntax has these named arguments: Argument List Definition object - Required; Variant (Object). The name of the object on which the function will be executed. procname - Required; Variant (String). A string expression containing the name of a

97 M.Sc. (IT) Part-I 97 property or method of the object. calltype - Required; Constant. A constant of type vbcalltype representing the type of procedure being called. args() Optional: Variant (Array). Remarks The CallByName function is used to set or get a property or initialize a method at runtime using a string name. In the example below CallByName to set the MousePointer property of a text box. Then we get the value of the MousePointer property. The last line initiates the Move method to move the text box: CallByName Text1, "MousePointer", vblet, vbcrosshair Result = CallByName (Text1, "MousePointer", vbget) CallByName Text1, "Move", vbmethod, 100, 100 Visual Basic Choose Function Choose returns a value from the list of choices based on the value of index. If index is 1, Choose returns the first choice in the list; if index is 2, it returns the second choice, and so on. Visual Basic Chr Function The Visual Basic Chr function returns a string containing the character associated with the specified character code. Example: Dim MyChar MyChar = Chr(65) ' Returns A. MyChar = Chr(97) ' Returns a. Visual Basic Command Function The Visual Basic Command function returns the argument part of the command line used to invoke MS Visual Basic or an program developed with Visual Basic. The Visual Basic Command function is not available in Microsoft Office applications. When Visual Basic is launched from the command line, any portion of the command line that follows ' /cmd ' is forwarded to the program as an argument. In the example below, cmdlineargs is the argument information returned by the Command function. VB /cmd cmdlineargs For applications created with Visual Basic and compiled, Command returns any arguments that appear after the name of the application on the command line. For example: MyApp cmdlineargs

98 M.Sc. (IT) Part-I 8.3 Visual Conversion Functions Function 98 Basic Return Type Range for expression argument CBool Boolean Any valid string or numeric expression. CByte Byte 0 to 255. CCur Currency -922,337,203,685, to 922,337,203,685, CDate Date Any valid date expression. CDbl Double E308 to E-324 for negative values; E-324 to E308 for positive values. CDec Decimal +/-79,228,162,514,264,337,593,543,950,335 for zero-scaled numbers, that is, numbers with no decimal places. For numbers with 28 decimal places, the range is +/ The smallest possible non-zero number is CInt Integer -32,768 to 32,767; fractions are rounded. CLng Long -2,147,483,648 to 2,147,483,647; fractions are rounded. CSng Single E38 to E-45 for negative values; E-45 to E38 for positive values. CStr String Returns for CStr depend on the expression argument. CVar Variant Same range as Double for numerics. Same range as String for non-numerics.

99 M.Sc. (IT) Part-I Creating your own ActiveX control: ActiveX control is control like all visual basic common controls: Command Button, Label, etc. You can make your own ActiveX control, for example over button control, and use it in every VB program you make without addition of code.instead of writing the same code every time you want to use the hover button, make once over button ActiveX control, and drag it to your form every time you want to use it, like it was the usual Command Button. In this tutorial we will make a button control, that will pop a message box when the user will click on it. I know that it's not very useful and for this purpose you don't have to make an ActiveX control, but this example will teach you how to make an ActiveX control. Getting started Choose from the menu (in VB 6.0) File->New Project Image 1: Select ActiveX Control and press OK.

100 M.Sc. (IT) Part-I 100 Image 2: A new form without a title bar has been opened (Image 3). Image 3:

101 M.Sc. (IT) Part-I 101 Choose from the menu Project->Project1 Properties. Image 4: In the 'Project Name' Text Box is written by default 'Project1' (Image 5). Image 5:

102 M.Sc. (IT) Part-I 102 Change the 'Project Name' to myfirstocx. This is what you will see, after you complete the control, In the Project->Components menu - where the user choose which OCX controls to add to his project (Image 6). Image 6: Right click on the form, and choose properties from the menu. Image 7: The form's name property by default is UserControl1.Change it to MyControl.

103 M.Sc. (IT) Part-I 103 Image 8: This will be default name of the control when the user will insert it to his form: MyControl1, MyControl2 and so on. Starting the programming Add 1 Command Button to your form (named Command1). Image 9: This is how your control will look like. Your control is the form and everything on it. We don't want that the control will be a form with a button on it,we want that the control will be a button only, without the form around him. So resize the form to be at the size of the button exactly, so you won't see the form. Image 10:

104 M.Sc. (IT) Part-I 104 So now the Control look like a button. But it's not a button, it's a form with button on it. But what if the user will resize the control at design time(like you do to Command Button, after you enter it to your form)?suppose you have a regular form with a button on it and the form is resized to the button size (like in your current control). When the user will resize the form, he will see the form that was before 'under' the button. The same thing will happen in our case. To solve this problem, when the user resize the form (i.e the control), we need to resize the button to fit the form and the form will be again at the size of the button.when the user resize the control, he actually try to resize the button. Enter the following code to let the user resize the button instead of resizing the form: Private Sub UserControl_Resize() Command1.Width = UserControl.Width Command1.Height = UserControl.Height End Sub UserControl is the name of the Form/Control. thus, UserControl.Width is the Form/Control width, UserControl.Height is the Form/Control Height and UserControl_Resize() is the event that occur when the user resize the control. Implementing Control's Properties Every control has few properties as default: Name, Left, Index, Tag, and more. Our control will inherit those properties as default.but we want that our control will have some properties that he doesn't get as default, like Text - the text of the message box that will pop when the user press the button. Implementing Text Property We have 2 occasions: when reading the Text property and when changing the Text property.the reading occasion occur when we want to read the porperty that the user set. For example if the user set the control Text property to "hello", the reading result will return "hello".lets implement first the reading occasion. Enter the following code to your form: Dim TextVariable As String The TextVariable will be the variable that holds for us the value of the Text property, therefore the String that will be inserted into the message box. Enter the following code to your form: Private Sub UserControl_ReadProperties (PropBag As PropertyBag) TextVariable = PropBag.ReadProperty ("Text", "There is no message") End Sub The function above says: read the control's "Text" property. If the reading yield nothing, set as default the Text property to be "There is no message". We called to read the Text property, now we have to implement the reading method:

105 M.Sc. (IT) Part-I 105 Public Property Get Text () As String Text = TextVariable End Property The TextVariable will hold the Text property value, so we simply need to return the value of TextVariable. TextVariable is a string and the calling for reading the Text property value will return string, therefore the 'As String' above. Implementing The Writing Method The write occasion occur when the user change the Text property.in that case, we need to update the variable that holds for us the propery value (TextVariable). Enter the Following code to your form: Private Sub UserControl_WriteProperties(PropBag As PropertyBag) Call PropBag.WriteProperty("Text", TextVariable, "There is no message") End Sub The function above says: Write the new property value to TextVariable and update the Text Property. If the writing to the TextVariable return nothing,set the Text property value to be "There is no message".now we have to implement the writing method,where the new property value will be entered into the TextVariable. Enter the following code to your form: Public Property Let Text(ByVal New_Text As String) TextVariable = New_Text PropertyChanged "Text" End Property The new Text property value is passed with the New_Text parameter.of course this parameter have to be String, because the Text property holds String.We set the TextVariable variable to hold the new Text property value.then we announce that the "Text" property has been changed. Implementing events We know what the user wants to pop up when he clicks the button - the Text in TextVariable. Now we need to pop up the message box when the user click the button. We want 2 events: KeyPress and Click.First we need to declare them. enter the following code to your form: Event Click() Event KeyPress(KeyAscii As Integer) How do we know that the Click event not getting parameters,and the KeyPress event get the KeyAscii parameter?double Click on the command button.2 new lines have been inserted to your code: Private Sub Command1_Click() End Sub as you see, the Click event gets no parameters.now go to the button KeyPress event,

106 M.Sc. (IT) Part-I 106 via the right ComboBox under the title bar,which now showing the current event Click After you choose KeyPress from the combobox, 2 new lines were inserted to your code: Private Sub Command1_KeyPress(KeyAscii As Integer) End Sub As you can see, the button KeyPress event get the KeyAscii parameter. Implementing The KeyPress Event We don't want to change the KeyPress Event.We want that the code the user will insert to the KeyPress Event (Image 11) will be launched as usual, without any changes. Image 11: So we will enter the following lines to our form: Private Sub Command1_KeyPress(KeyAscii As Integer) RaiseEvent KeyPress(KeyAscii) End Sub Code Explanation: when the user press on the Command1 Button, simply launch the Control (MyControl) KeyPress event. The 'RaiseEvent' function launch an event. It launch the event with the KeyAscii parameter that has been received from the Command1 KeyPress event. Implementing The Click Event We want to pop up the message box when the Click event occur, and then run the code that the user entered in the MyControl1 - Click event. Enter the following code to your form: Private Sub Command1_Click() MsgBox (TextVariable) RaiseEvent Click End Sub When the user Click on Command1, pop up a message box with the TextVariable string.then run the code that the user inserted to the control Click event. What will happen if you omit the 'RaiseEvent Click' line?

107 M.Sc. (IT) Part-I 107 When the user will click the button, the message box will pop up and the code that the user entered to the MyControl1 Click event will not be apply. So actually the user will not be able to program the click event. By now, your code should look like this: Dim TextVariable As String Event Click () Event KeyPress(KeyAscii As Integer) Private Sub Command1_Click () MsgBox (TextVariable) RaiseEvent Click End Sub Private Sub Command1_KeyPress (KeyAscii As Integer) RaiseEvent KeyPress(KeyAscii) End Sub Private Sub UserControl_Resize() Command1.Width = UserControl.Width Command1.Height = UserControl.Height End Sub Public Property Get Text () As String Text = TextVariable End Property Public Property Let Text (ByVal New_Text As String) TextVariable = New_Text PropertyChanged "Text" End Property Private Sub UserControl_ReadProperties(PropBag As PropertyBag) TextVariable = PropBag.ReadProperty("Text", "There is no message") End Sub Private Sub UserControl_WriteProperties(PropBag As PropertyBag) Call PropBag.WriteProperty("Text", TextVariable, "There is no message) End Sub Compiling and running the control Now lets see how the control is working by now.save the project (File->Save Project).

108 M.Sc. (IT) Part-I 108 Image 12: lets compile the project to OCX Control. From the menu, choose File->Make MyFirstOCX.ocx and press OK. Image 13: Now your OCX Control has been created AND registered with your system Start a new project and enter your control to the project (From the menu choose Project>Components (Image 14),mark the MyFirstOCX checkbox (Image 15) and press OK)

109 M.Sc. (IT) Part-I 109 Image 14: Image 15: Now you see the new control at the ToolBox.

110 M.Sc. (IT) Part-I 110 Image 16: Insert it to your form, resize it to your preferred size, and insert "hello" to the control Text property. Run the program and click the button.a "hello" message box is popping Suggested Readings 1 Visual Basic 6 Black Book by Steve Holzuer, Paraglypu Press. 2 Visual Basic 6 : The Complete Reference by Noel Jerke, Tata McGraw Hill. 3 Mastering Visual Basic 6 by Evangelos Petroutsos, Sybex. 4 Sams Teach Yourself Visual Basic 6 in 24 hours by Greg Perry, Sams Programming Microsoft Visual Basic 6.0 by Francesco Balena, Miscrosoft Press. Web Resources :

111 M.Sc. (IT) PART I LESSON NO. 9 PAPER : MS(A)-123 VISUAL BASIC AUTHOR : VISHAL GOYAL USING ACTIVE X SERVER IN VISUAL BASIC The purpose of this lesson is to explain how one can use Microsoft Visual Basic 6.0 to create, compile and update an ActiveX Server Component. For the purposes of this lesson, we define an ActiveX Server Component as a component that is designed to be used from inside an Active Server Page. It is assumed that the reader is already familiar with the process of creating and viewing ASP pages and has some knowledge of the Microsoft Internet Information Server and its configuration utility, the Internet Service Manager. Finally, please note that this lesson applies only to Windows NT 4.0 or Windows 2000 and IIS 4.0. For a walk-through of the overall process, we ll create the obligatory Hello World example. Step 1: Like all things Visual Basic, creating an ActiveX server component is not an overly complex task. If, when you open Visual Basic, a New Project window appears, skip this first subtask and proceed directly to the second subtask selecting the ActiveX DLL project type. Alternatively, if upon opening Visual Basic you are prompted with an empty work environment proceed as follows: Under the File menu, select New Project

112 M.Sc. (IT) Part-I 112 In the New Project dialogue box that appears, select ActiveX DLL and click OK. Visual Basic will now work some magic and you will shortly have in your possession the skeleton of an ActiveX server component. This essentially consists of a project named, by default, Project 1, and a class (by default named Class 1.) The project should be displayed with a worksheet opened for the first class.

113 M.Sc. (IT) Part-I 113 Step 2: To display our pithy little greeting, we ll make use of one of the intrinsic ASP objects, Response, which we ll gain access to through the auspices of the Microsoft Transaction Server. In order to utilize external libraries of objects such as those found in MTS or ASP, we must tell the Visual Basic compiler where these libraries are located. This is achieved in Visual Basic by including references to the appropriate DLLs. To do this, you first need to select the References option on the Project menu. In the list of the libraries that appear, find the listing for "Microsoft Active Server Pages Object Library." In addition, if you are using Windows NT 4.0, find "Microsoft Transaction Server Type Library," or if you are using Windows 2000, find "Com+ Services type library." Mark the appropriate check-box to the left of your selection(s) and click OK.

114 M.Sc. (IT) Part-I 114 To actually make use of any of the Active Server Page intrinsic objects such as Response, Session, Application or Request, you ll need to create and initialize instances of these objects. Fortunately, thanks to the Microsoft Transaction Server, this is a relatively painless task. Whenever the Transaction Server instantiates a new MTS component, it checks to see whether or not that component implements a set of functions and subroutines collectively known as the ObjectControl interface. If, in fact, the component being created does implement this interface, then MTS will call this component s implementation of the ObjectControl_Activate subroutine at some point during the creation process. Similarly, when the MTS object is being destroyed, MTS will automatically call the object s implementation of the ObjectControl_Deactivate subroutine, if it exists. Now the nice thing about this whole chain of events, is that inside the ObjectControl_Activate subroutine we can determine the context in which our component is currently being created. We may then get references to any contextspecific objects, such as the ASP intrinsic Response object. Add the following lines of code to Class1 now to accomplish just such a trick: Private ocontext As ObjectContext Private oresponse As Response Implements ObjectControl

115 M.Sc. (IT) Part-I 115 Private Sub ObjectControl_Activate() Set ocontext = GetObjectContext() Set oresponse = ocontext("response") End Sub Private Sub ObjectControl_Deactivate() Set ocontext = Nothing Set oresponse = Nothing End Sub Private Function ObjectControl_CanBePooled() As Boolean ObjectControl_CanBePooled = False End Function Providing an implementation of the ObjectControl_CanBePooled function as in the above code, is a requirement of implementing the MTS ObjectControl interface. The purpose of the function is to tell MTS whether or not you want it to cache (pool) instances of your object that are no longer being used. If MTS does pool your component, then when another instance is required it can simply be returned from the pool, rather than being recreated from scratch. In our component we wish to disable pooling, since the reference to the Response object that we are obtaining will be specific to each instance of the component. Step 3: Phew! Next we ll need to write the method that will perform our humble task. To do this, add the following lines of code to Class1 now: Public Sub DisplayGreeting() oresponse.write "Hello, out there!<br>" & VBCrLf End Sub The VBCrLf constant simply adds the carriage-return and line-feed characters to the end of the line and is purely an aesthetic addition to the code. Step 4: That should comprise the whole of the code for the component. For the next step, we ll compile it into a DLL that can subsequently be called from a server-side script. Before doing this, though, you ll probably want to give some meaningful names to your project and its sole class. To alter the default name for the project from "Project1" to something more agreeable, click on the project name in the Project Explorer window, which lies to the right of the workspace. In the Properties window below it, there should be only one property listed, which is (Name). Alter this to suit your tastes, and then click on the listing for Class, again in the Project Explorer window. The (Name) property for the class will be the first of several properties listed in the Properties window. For our example, we ve chosen the rather predictable names of "Example" and "Greeting" for our project and class. After entering the code

116 M.Sc. (IT) Part-I 116 as directed and renaming everything, your Visual Basic editor window should look something like the following (but note that we have removed the toolbox from the left of the window so that more of the code is visible.) Now save your project and then, on the File menu, select Make Example.dll, where "Example" is the name that you ve given to the project. The default location for the DLL is the folder in which you saved your project and this will do as well as any. Once you ve chosen a location for the DLL, your code will be compiled and a listing for the resulting DLL will be added to the system registry. Step 5: Having created the DLL we must now register it with the Microsoft Transaction Server. Components that are registered with MTS are organized into packages which typically contain all the components for a particular application. If you are using Windows NT 4.0, to register the DLL with MTS, we must first create a new package. To do this, open the Transaction Server Explorer by clicking the Windows NT Start button, selecting Programs, then Windows NT 4.0 Option Pack, followed by Microsoft Transaction Server and finally Transaction Server Explorer. When the MTS explorer window appears, expand the Microsoft Transaction Server folder in the left pane, then expand Computers, followed by My Computer. Now select (by left-clicking on) the Packages Installed folder. Next, right-click on Packages Installed and select New followed by Package. If you are using Windows

117 M.Sc. (IT) Part-I , to register the DLL with MTS, you must click the Start button, when the window pops up select Settings, followed by Control Panel, then Administrative Tools, and finally Component Services. Expand the My Computer directory in the left pane and select Com+ Applications then right click and select New followed by Application. Click the Create an Empty Package button from the pop-up window that appears, enter the name of your package (we ve called the package Example), click Next, if you are Using Windows 2000 click Next once more and then Finish. A new icon representing your example package will then appear in the right pane of the explorer. Having created the requisite MTS package, we must now add our newly created DLL to this package. To achieve this, expand your package in the MTS explorer and then select (by left-clicking) the Components folder. Next, right-click on Components, select New and then Component.

118 M.Sc. (IT) Part-I 118 Click the Import component(s) that are already registered button. After a short while a pop-up window will appear containing a list of all the components registered on your computer. Select Example.Greeting (or whatever you chose to call your component) and click the Finish button.

119 M.Sc. (IT) Part-I 119 An icon representing your component will appear in the previously blank right pane of the MTS explorer. This completes the registration of your component and you can now begin testing. Step 6: Having built and registered our new component, we can now begin testing. To test your new ActiveX Server Component, create an ASP page now (using Visual Interdev or the editor of your choice) and paste in the following code: <% Set oexample = Server.CreateObject("Example.Greeting") oexample.displaygreeting %> The CreateObject method of the Server object creates an instance of the component specified by its single String argument. In the above example, we create an instance of our Example.Greeting component. Now save your ASP page in a folder that is or can be made, accessible to IIS. If you are not sure where to save your ASP page, we suggest making a folder C:\inetpub\wwwroot\test and storing it there.

120 M.Sc. (IT) Part-I 120 Before viewing your test ASP page in a browser, it is important that you configure the page to run in a separate process from the main Internet Information Server (IIS) service. If you do not do this, you may have to shut down the Web server each time you wish to rebuild your DLL. This is because the web server process will attach itself to your DLL and prevent the file from being overwritten when you attempt to recompile your Visual Basic project. By configuring IIS to run your page in a separate process however, we will only have to shut down that one process in order to free up the DLL and enable the project to be rebuilt. To make sure that your page is set to run out-of-process, start up the Microsoft Management Console (MMC) for IIS. This should be accessible, if you are using Window NT 4.0, by clicking the Start button, selecting Programs, then Windows NT 4.0 Option Pack, followed by Microsoft Personal Web Server (for NT workstation) or Microsoft Internet Information Server (for NT Server) and finally selecting Internet Service Manager. If you are Using Windows 2000, this is accessible by clicking the Start button, selecting Settings, followed by Control Panel, then Administrative Tools and finally Internet Service Manager. You will notice that you can configure both the Internet Information Server and the Transaction Server from this interface. Having opened MMC, locate your ASP page s directory in the Internet Information Server tree view in the left pane, and then right-click on the directory name. On the menu that appears, select Properties. In order for your test ASP page to run out-of-process from IIS, the directory in which

121 M.Sc. (IT) Part-I 121 it s located must be an application starting point. To determine whether or not this is the case, look at the tree view in MMC. Icons for the directories which are application starting points are depicted as open boxes, whereas those directories which are not application starting points are represented by the standard folder icon. If the page s directory is not an application starting point, click the Create button on the property page. You can give the new application a name after creating it, although this is not actually necessary. Once you ve ensured that the directory is capable of running the page out-of-process, make sure that the check-box to the left side of Run in separate memory space is checked (in the above screenshot this checkbox is disabled as we have not yet created the Application starting point.) Finally, click Apply, followed by OK, to close the property page. Now, you may finally view your test ASP page containing the script to call your object s DisplayGreeting subroutine. When you do this, you should see the string "Hello, out there!" displayed in the browser.

Text box. Command button. 1. Click the tool for the control you choose to draw in this case, the text box.

Text box. Command button. 1. Click the tool for the control you choose to draw in this case, the text box. Visual Basic Concepts Hello, Visual Basic See Also There are three main steps to creating an application in Visual Basic: 1. Create the interface. 2. Set properties. 3. Write code. To see how this is done,

More information

END-TERM EXAMINATION

END-TERM EXAMINATION (Please Write your Exam Roll No. immediately) END-TERM EXAMINATION DECEMBER 2006 Exam. Roll No... Exam Series code: 100274DEC06200274 Paper Code : MCA-207 Subject: Front End Design Tools Time: 3 Hours

More information

Program and Graphical User Interface Design

Program and Graphical User Interface Design CHAPTER 2 Program and Graphical User Interface Design OBJECTIVES You will have mastered the material in this chapter when you can: Open and close Visual Studio 2010 Create a Visual Basic 2010 Windows Application

More information

Full file at https://fratstock.eu Programming in Visual Basic 2010

Full file at https://fratstock.eu Programming in Visual Basic 2010 OBJECTIVES: Chapter 2 User Interface Design Upon completion of this chapter, your students will be able to 1. Use text boxes, masked text boxes, rich text boxes, group boxes, check boxes, radio buttons,

More information

LESSON B. The Toolbox Window

LESSON B. The Toolbox Window The Toolbox Window After studying Lesson B, you should be able to: Add a control to a form Set the properties of a label, picture box, and button control Select multiple controls Center controls on the

More information

Getting started 7. Setting properties 23

Getting started 7. Setting properties 23 Contents 1 2 3 Getting started 7 Introducing Visual Basic 8 Installing Visual Studio 10 Exploring the IDE 12 Starting a new project 14 Adding a visual control 16 Adding functional code 18 Saving projects

More information

NiceForm User Guide. English Edition. Rev Euro Plus d.o.o. & Niceware International LLC All rights reserved.

NiceForm User Guide. English Edition. Rev Euro Plus d.o.o. & Niceware International LLC All rights reserved. www.nicelabel.com, info@nicelabel.com English Edition Rev-0910 2009 Euro Plus d.o.o. & Niceware International LLC All rights reserved. www.nicelabel.com Head Office Euro Plus d.o.o. Ulica Lojzeta Hrovata

More information

Getting started 7. Setting properties 23

Getting started 7. Setting properties 23 Contents 1 2 3 Getting started 7 Introduction 8 Installing Visual Basic 10 Exploring the IDE 12 Starting a new project 14 Adding a visual control 16 Adding functional code 18 Saving projects 20 Reopening

More information

MICROSOFT WORD 2010 BASICS

MICROSOFT WORD 2010 BASICS MICROSOFT WORD 2010 BASICS Word 2010 is a word processing program that allows you to create various types of documents such as letters, papers, flyers, and faxes. The Ribbon contains all of the commands

More information

HOUR 4 Understanding Events

HOUR 4 Understanding Events HOUR 4 Understanding Events It s fairly easy to produce an attractive interface for an application using Visual Basic.NET s integrated design tools. You can create beautiful forms that have buttons to

More information

MS Office Word Tabs & Tables Manual. Catraining.co.uk Tel:

MS Office Word Tabs & Tables Manual. Catraining.co.uk Tel: MS Office 2010 Word Tabs & Tables Manual Catraining.co.uk Tel: 020 7920 9500 Table of Contents TABS... 1 BASIC TABS WITH ALIGNMENT... 1 DEFAULT TAB STOP... 1 SET MANUAL TAB STOPS WITH RULER... 2 SET MANUAL

More information

Designer Reference 1

Designer Reference 1 Designer Reference 1 Table of Contents USE OF THE DESIGNER...4 KEYBOARD SHORTCUTS...5 Shortcuts...5 Keyboard Hints...5 MENUS...7 File Menu...7 Edit Menu...8 Favorites Menu...9 Document Menu...10 Item Menu...12

More information

d2vbaref.doc Page 1 of 22 05/11/02 14:21

d2vbaref.doc Page 1 of 22 05/11/02 14:21 Database Design 2 1. VBA or Macros?... 2 1.1 Advantages of VBA:... 2 1.2 When to use macros... 3 1.3 From here...... 3 2. A simple event procedure... 4 2.1 The code explained... 4 2.2 How does the error

More information

You will have mastered the material in this chapter when you can:

You will have mastered the material in this chapter when you can: CHAPTER 6 Loop Structures OBJECTIVES You will have mastered the material in this chapter when you can: Add a MenuStrip object Use the InputBox function Display data using the ListBox object Understand

More information

Intro to Excel. To start a new workbook, click on the Blank workbook icon in the middle of the screen.

Intro to Excel. To start a new workbook, click on the Blank workbook icon in the middle of the screen. Excel is a spreadsheet application that allows for the storing, organizing and manipulation of data that is entered into it. Excel has variety of built in tools that allow users to perform both simple

More information

VBA Excel 2013/2016. VBA Visual Basic for Applications. Learner Guide

VBA Excel 2013/2016. VBA Visual Basic for Applications. Learner Guide VBA Visual Basic for Applications Learner Guide 1 Table of Contents SECTION 1 WORKING WITH MACROS...5 WORKING WITH MACROS...6 About Excel macros...6 Opening Excel (using Windows 7 or 10)...6 Recognizing

More information

17. Introduction to Visual Basic Programming

17. Introduction to Visual Basic Programming 17. Introduction to Visual Basic Programming Visual Basic (VB) is the fastest and easiest way to create applications for MS Windows. Whether you are an experienced professional or brand new to Windows

More information

PowerPoint Instructions

PowerPoint Instructions PowerPoint Instructions Exercise 1: Type and Format Text and Fix a List 1. Open the PowerPoint Practice file. To add a company name to slide 1, click the slide 1 thumbnail if it's not selected. On the

More information

Understanding Word Processing

Understanding Word Processing Understanding Word Processing 3.0 Introduction In this chapter you are going to learn how to create a simple memo or note or a complex and complicated multi column business document using word processing

More information

The Domino Designer QuickStart Tutorial

The Domino Designer QuickStart Tutorial The Domino Designer QuickStart Tutorial 1. Welcome The Domino Designer QuickStart Tutorial You've installed Domino Designer, you've taken the Designer Guided Tour, and maybe you've even read some of the

More information

Customizing Access Parameter Queries

Customizing Access Parameter Queries [Revised and Updated 15 August 2018] Everyone likes parameter queries! The database developer doesn't have to anticipate the user's every requirement, and the user can vary their enquiries without having

More information

Introduction to MS Word XP 2002: An Overview

Introduction to MS Word XP 2002: An Overview Introduction to MS Word XP 2002: An Overview Sources Used: http://www.fgcu.edu/support/office2000/word/files.html Florida Gulf Coast University Technology Skills Orientation Word 2000 Tutorial The Computer

More information

Part I. Integrated Development Environment. Chapter 2: The Solution Explorer, Toolbox, and Properties. Chapter 3: Options and Customizations

Part I. Integrated Development Environment. Chapter 2: The Solution Explorer, Toolbox, and Properties. Chapter 3: Options and Customizations Part I Integrated Development Environment Chapter 1: A Quick Tour Chapter 2: The Solution Explorer, Toolbox, and Properties Chapter 3: Options and Customizations Chapter 4: Workspace Control Chapter 5:

More information

Introduction to the workbook and spreadsheet

Introduction to the workbook and spreadsheet Excel Tutorial To make the most of this tutorial I suggest you follow through it while sitting in front of a computer with Microsoft Excel running. This will allow you to try things out as you follow along.

More information

PowerPoint Introduction. Video: Slide Basics. Understanding slides and slide layouts. Slide Basics

PowerPoint Introduction. Video: Slide Basics. Understanding slides and slide layouts. Slide Basics PowerPoint 2013 Slide Basics Introduction PowerPoint presentations are made up of a series of slides. Slides contain the information you will present to your audience. This might include text, pictures,

More information

Guide to WB Annotations

Guide to WB Annotations Guide to WB Annotations 04 May 2016 Annotations are a powerful new feature added to Workbench v1.2.0 (Released May 2016) for placing text and symbols within wb_view tabs and windows. They enable generation

More information

WORD XP/2002 USER GUIDE. Task- Formatting a Document in Word 2002

WORD XP/2002 USER GUIDE. Task- Formatting a Document in Word 2002 University of Arizona Information Commons Training Page 1 of 21 WORD XP/2002 USER GUIDE Task- Formatting a Document in Word 2002 OBJECTIVES: At the end of this course students will have a basic understanding

More information

Welcome Application. Introducing the Visual Studio.NET IDE. Objectives. Outline

Welcome Application. Introducing the Visual Studio.NET IDE. Objectives. Outline 2 T U T O R I A L Objectives In this tutorial, you will learn to: Navigate Visual Studio.NET s Start Page. Create a Visual Basic.NET solution. Use the IDE s menus and toolbars. Manipulate windows in the

More information

Report Designer Report Types Table Report Multi-Column Report Label Report Parameterized Report Cross-Tab Report Drill-Down Report Chart with Static

Report Designer Report Types Table Report Multi-Column Report Label Report Parameterized Report Cross-Tab Report Drill-Down Report Chart with Static Table of Contents Report Designer Report Types Table Report Multi-Column Report Label Report Parameterized Report Cross-Tab Report Drill-Down Report Chart with Static Series Chart with Dynamic Series Master-Detail

More information

Tutorial 2 - Welcome Application Introducing, the Visual Studio.NET IDE

Tutorial 2 - Welcome Application Introducing, the Visual Studio.NET IDE 1 Tutorial 2 - Welcome Application Introducing, the Visual Studio.NET IDE Outline 2.1 Test-Driving the Welcome Application 2.2 Overview of the Visual Studio.NET 2003 IDE 2.3 Creating a Project for the

More information

Stamina Software Pty Ltd. TRAINING MANUAL Viságe Reporter

Stamina Software Pty Ltd. TRAINING MANUAL Viságe Reporter Stamina Software Pty Ltd TRAINING MANUAL Viságe Reporter Version: 2 21 st January 2009 Contents Introduction...1 Assumed Knowledge...1 Pre Planning...1 Report Designer Location...2 Report Designer Screen

More information

Click Here to Begin OS X. Welcome to the OS X Basics Learning Module.

Click Here to Begin OS X. Welcome to the OS X Basics Learning Module. OS X Welcome to the OS X Basics Learning Module. This module will teach you the basic operations of the OS X operating system, found on the Apple computers in the College of Technology computer labs. The

More information

Visual Programming 1. What is Visual Basic? 2. What are different Editions available in VB? 3. List the various features of VB

Visual Programming 1. What is Visual Basic? 2. What are different Editions available in VB? 3. List the various features of VB Visual Programming 1. What is Visual Basic? Visual Basic is a powerful application development toolkit developed by John Kemeny and Thomas Kurtz. It is a Microsoft Windows Programming language. Visual

More information

MAKING TABLES WITH WORD BASIC INSTRUCTIONS. Setting the Page Orientation. Inserting the Basic Table. Daily Schedule

MAKING TABLES WITH WORD BASIC INSTRUCTIONS. Setting the Page Orientation. Inserting the Basic Table. Daily Schedule MAKING TABLES WITH WORD BASIC INSTRUCTIONS Setting the Page Orientation Once in word, decide if you want your paper to print vertically (the normal way, called portrait) or horizontally (called landscape)

More information

Forms Desktop for Windows Version 4 Manual

Forms Desktop for Windows Version 4 Manual Forms Desktop for Windows Version 4 Manual Revision Date 12/05/2007 HanDBase is a Registered Trademark of DDH Software, Inc. All information contained in this manual and all software applications mentioned

More information

Clickteam Fusion 2.5 Creating a Debug System - Guide

Clickteam Fusion 2.5 Creating a Debug System - Guide INTRODUCTION In this guide, we will look at how to create your own 'debug' system in Fusion 2.5. Sometimes when you're developing and testing a game, you want to see some of the real-time values of certain

More information

Visual Basic.NET. 1. Which language is not a true object-oriented programming language?

Visual Basic.NET. 1. Which language is not a true object-oriented programming language? Visual Basic.NET Objective Type Questions 1. Which language is not a true object-oriented programming language? a.) VB.NET b.) VB 6 c.) C++ d.) Java Answer: b 2. A GUI: a.) uses buttons, menus, and icons.

More information

1 Information system An information system is the combination of technology(computers) and people that enable an organization to collect data, store them, and transform them into information Data Data

More information

Maximizer. The CRM Company. User's Guide

Maximizer. The CRM Company. User's Guide TM Maximizer The CRM Company User's Guide Contents i Contents Chapter 1 Introduction...1 Welcome to Maximizer Form Designer...2 Using Maximizer Form Designer...3 Running Maximizer Form Designer...4 Getting

More information

This chapter is intended to take you through the basic steps of using the Visual Basic

This chapter is intended to take you through the basic steps of using the Visual Basic CHAPTER 1 The Basics This chapter is intended to take you through the basic steps of using the Visual Basic Editor window and writing a simple piece of VBA code. It will show you how to use the Visual

More information

variables programming statements

variables programming statements 1 VB PROGRAMMERS GUIDE LESSON 1 File: VbGuideL1.doc Date Started: May 24, 2002 Last Update: Dec 27, 2002 ISBN: 0-9730824-9-6 Version: 0.0 INTRODUCTION TO VB PROGRAMMING VB stands for Visual Basic. Visual

More information

The purpose of this tutorial is to introduce you to the Construct 2 program. First, you will be told where the software is located on the computer

The purpose of this tutorial is to introduce you to the Construct 2 program. First, you will be told where the software is located on the computer Learning Targets: Students will be introduced to industry recognized game development software Students will learn how to navigate within the software Students will learn the basics on how to use Construct

More information

Handout Objectives: a. b. c. d. 3. a. b. c. d. e a. b. 6. a. b. c. d. Overview:

Handout Objectives: a. b. c. d. 3. a. b. c. d. e a. b. 6. a. b. c. d. Overview: Computer Basics I Handout Objectives: 1. Control program windows and menus. 2. Graphical user interface (GUI) a. Desktop b. Manage Windows c. Recycle Bin d. Creating a New Folder 3. Control Panel. a. Appearance

More information

CounselLink Reporting. Designer

CounselLink Reporting. Designer CounselLink Reporting Designer Contents Overview... 1 Introduction to the Document Editor... 2 Create a new document:... 2 Document Templates... 3 Datasets... 3 Document Structure... 3 Layout Area... 4

More information

Excel Select a template category in the Office.com Templates section. 5. Click the Download button.

Excel Select a template category in the Office.com Templates section. 5. Click the Download button. Microsoft QUICK Excel 2010 Source Getting Started The Excel Window u v w z Creating a New Blank Workbook 2. Select New in the left pane. 3. Select the Blank workbook template in the Available Templates

More information

Excel 2010: Getting Started with Excel

Excel 2010: Getting Started with Excel Excel 2010: Getting Started with Excel Excel 2010 Getting Started with Excel Introduction Page 1 Excel is a spreadsheet program that allows you to store, organize, and analyze information. In this lesson,

More information

Chapter 2 Using Slide Masters, Styles, and Templates

Chapter 2 Using Slide Masters, Styles, and Templates Impress Guide Chapter 2 Using Slide Masters, Styles, and Templates OpenOffice.org Copyright This document is Copyright 2007 by its contributors as listed in the section titled Authors. You can distribute

More information

Using Microsoft Excel

Using Microsoft Excel Using Microsoft Excel Formatting a spreadsheet means changing the way it looks to make it neater and more attractive. Formatting changes can include modifying number styles, text size and colours. Many

More information

ABOUT THIS COURSE... 3 ABOUT THIS MANUAL... 4 LESSON 1: MANAGING LISTS... 5

ABOUT THIS COURSE... 3 ABOUT THIS MANUAL... 4 LESSON 1: MANAGING LISTS... 5 Table of Contents ABOUT THIS COURSE... 3 ABOUT THIS MANUAL... 4 LESSON 1: MANAGING LISTS... 5 TOPIC 1A: SORT A LIST... 6 Sort a list in A-Z or Z-A Order... 6 TOPIC 1B: RENUMBER A LIST... 7 Renumber a List

More information

USER GUIDE. MADCAP FLARE 2017 r3. QR Codes

USER GUIDE. MADCAP FLARE 2017 r3. QR Codes USER GUIDE MADCAP FLARE 2017 r3 QR Codes Copyright 2018 MadCap Software. All rights reserved. Information in this document is subject to change without notice. The software described in this document is

More information

Forms for Android Version Manual. Revision Date 12/7/2013. HanDBase is a Registered Trademark of DDH Software, Inc.

Forms for Android Version Manual. Revision Date 12/7/2013. HanDBase is a Registered Trademark of DDH Software, Inc. Forms for Android Version 4.6.300 Manual Revision Date 12/7/2013 HanDBase is a Registered Trademark of DDH Software, Inc. All information contained in this manual and all software applications mentioned

More information

SciGraphica. Tutorial Manual - Tutorials 1and 2 Version 0.8.0

SciGraphica. Tutorial Manual - Tutorials 1and 2 Version 0.8.0 SciGraphica Tutorial Manual - Tutorials 1and 2 Version 0.8.0 Copyright (c) 2001 the SciGraphica documentation group Permission is granted to copy, distribute and/or modify this document under the terms

More information

PowerPoint Slide Basics. Introduction

PowerPoint Slide Basics. Introduction PowerPoint 2016 Slide Basics Introduction Every PowerPoint presentation is composed of a series of slides. To begin creating a slide show, you'll need to know the basics of working with slides. You'll

More information

Getting S tarted w ith E xcel

Getting S tarted w ith E xcel Lesson 1 - Getting Started with Excel 1 Lesson 1 Getting S tarted w ith E xcel Les s on Topics Using Excel The Workbook Exiting Excel Les s on Objectives At the end of the lesson, you will be able to:

More information

In the first class, you'll learn how to create a simple single-view app, following a 3-step process:

In the first class, you'll learn how to create a simple single-view app, following a 3-step process: Class 1 In the first class, you'll learn how to create a simple single-view app, following a 3-step process: 1. Design the app's user interface (UI) in Xcode's storyboard. 2. Open the assistant editor,

More information

Creating a Template in WordPerfect

Creating a Template in WordPerfect 1. File a. New From Project Creating a Template in WordPerfect b. Go to Options 2. Create A Category 1 3. Name it Family History (or a title of your choice) 4. Find Family History in the Drop down list

More information

Mach4 CNC Controller Screen Editing Guide Version 1.0

Mach4 CNC Controller Screen Editing Guide Version 1.0 Mach4 CNC Controller Screen Editing Guide Version 1.0 1 Copyright 2014 Newfangled Solutions, Artsoft USA, All Rights Reserved The following are registered trademarks of Microsoft Corporation: Microsoft,

More information

Chapter 4: Single Table Form Lab

Chapter 4: Single Table Form Lab Chapter 4: Single Table Form Lab Learning Objectives This chapter provides practice with creating forms for individual tables in Access 2003. After this chapter, you should have acquired the knowledge

More information

2 USING VB.NET TO CREATE A FIRST SOLUTION

2 USING VB.NET TO CREATE A FIRST SOLUTION 25 2 USING VB.NET TO CREATE A FIRST SOLUTION LEARNING OBJECTIVES GETTING STARTED WITH VB.NET After reading this chapter, you will be able to: 1. Begin using Visual Studio.NET and then VB.NET. 2. Point

More information

StarTeam Layout Designer Help

StarTeam Layout Designer Help StarTeam 16.3 Layout Designer Help Micro Focus The Lawn 22-30 Old Bath Road Newbury, Berkshire RG14 1QN UK http://www.microfocus.com Copyright Micro Focus 2018. All rights reserved. MICRO FOCUS, the Micro

More information

Simply Personnel Screen Designer

Simply Personnel Screen Designer Simply Personnel Screen Designer -Training Workbook- Screen Designer Page 1 Build 12.8 Introduction to Simply Personnel Screen Designer This document provides step-by-step guide for employee users to give

More information

Microsoft Word 2007 on Windows

Microsoft Word 2007 on Windows 1 Microsoft Word 2007 on Windows Word is a very popular text formatting and editing program. It is the standard for writing papers and other documents. This tutorial and quick start guide will help you

More information

Recommended GUI Design Standards

Recommended GUI Design Standards Recommended GUI Design Standards Page 1 Layout and Organization of Your User Interface Organize the user interface so that the information follows either vertically or horizontally, with the most important

More information

Specification Manager

Specification Manager Enterprise Architect User Guide Series Specification Manager How to define model elements simply? In Sparx Systems Enterprise Architect, use the document-based Specification Manager to create elements

More information

Lab 7 Macros, Modules, Data Access Pages and Internet Summary Macros: How to Create and Run Modules vs. Macros 1. Jumping to Internet

Lab 7 Macros, Modules, Data Access Pages and Internet Summary Macros: How to Create and Run Modules vs. Macros 1. Jumping to Internet Lab 7 Macros, Modules, Data Access Pages and Internet Summary Macros: How to Create and Run Modules vs. Macros 1. Jumping to Internet 1. Macros 1.1 What is a macro? A macro is a set of one or more actions

More information

SUM - This says to add together cells F28 through F35. Notice that it will show your result is

SUM - This says to add together cells F28 through F35. Notice that it will show your result is COUNTA - The COUNTA function will examine a set of cells and tell you how many cells are not empty. In this example, Excel analyzed 19 cells and found that only 18 were not empty. COUNTBLANK - The COUNTBLANK

More information

GreenFolders User Manual

GreenFolders User Manual GreenFolders User Manual Welcome! Welcome to GreenFolders the Electronic Records Management Solution. GreenFolders allows you to store and retrieve files with many easy-to-use features for working with

More information

Graphical User Interface Canvas Frame Event structure Platform-free GUI operations Operator << Operator >> Operator = Operator ~ Operator + Operator

Graphical User Interface Canvas Frame Event structure Platform-free GUI operations Operator << Operator >> Operator = Operator ~ Operator + Operator Graphical User Interface Canvas Frame Event structure Platform-free GUI operations Operator > Operator = Operator ~ Operator + Operator - Operator [] Operator size Operator $ Operator? Operator!

More information

A Guided Tour of Doc-To-Help

A Guided Tour of Doc-To-Help A Guided Tour of Doc-To-Help ii Table of Contents Table of Contents...ii A Guided Tour of Doc-To-Help... 1 Converting Projects to Doc-To-Help 2005... 1 Using Microsoft Word... 10 Using HTML Source Documents...

More information

FrontPage 98 Quick Guide. Copyright 2000 Peter Pappas. edteck press All rights reserved.

FrontPage 98 Quick Guide. Copyright 2000 Peter Pappas. edteck press All rights reserved. Master web design skills with Microsoft FrontPage 98. This step-by-step guide uses over 40 full color close-up screen shots to clearly explain the fast and easy way to design a web site. Use edteck s QuickGuide

More information

ECDL Module 4 REFERENCE MANUAL

ECDL Module 4 REFERENCE MANUAL ECDL Module 4 REFERENCE MANUAL Spreadsheets Microsoft Excel XP Edition for ECDL Syllabus Four PAGE 2 - ECDL MODULE 4 (USING MICROSOFT EXCEL XP) - MANUAL 4.1 USING THE APPLICATION... 4 4.1.1 FIRST STEPS

More information

SYLLABUS B.Com (Computer) VI SEM Subject Visual Basic Unit I

SYLLABUS B.Com (Computer) VI SEM Subject Visual Basic Unit I SYLLABUS B.Com (Computer) VI SEM Subject Visual Basic Unit I UNIT I UNIT II UNIT III UNIT IV UNIT V Introduction to Visual Basic: Introduction Graphics User Interface (GUI), Programming Language (Procedural,

More information

Creating Reports in Access 2007 Table of Contents GUIDE TO DESIGNING REPORTS... 3 DECIDE HOW TO LAY OUT YOUR REPORT... 3 MAKE A SKETCH OF YOUR

Creating Reports in Access 2007 Table of Contents GUIDE TO DESIGNING REPORTS... 3 DECIDE HOW TO LAY OUT YOUR REPORT... 3 MAKE A SKETCH OF YOUR Creating Reports in Access 2007 Table of Contents GUIDE TO DESIGNING REPORTS... 3 DECIDE HOW TO LAY OUT YOUR REPORT... 3 MAKE A SKETCH OF YOUR REPORT... 3 DECIDE WHICH DATA TO PUT IN EACH REPORT SECTION...

More information

The Mathcad Workspace 7

The Mathcad Workspace 7 For information on system requirements and how to install Mathcad on your computer, refer to Chapter 1, Welcome to Mathcad. When you start Mathcad, you ll see a window like that shown in Figure 2-1. By

More information

The CAP Panel Builder technology is designed to construct and manage configurations of stack panel products.

The CAP Panel Builder technology is designed to construct and manage configurations of stack panel products. About The CAP technology is designed to construct and manage configurations of stack panel products. Use the intuitive to assemble the components and control properties of stackable panels such as top

More information

Beginning a presentation

Beginning a presentation L E S S O N 2 Beginning a presentation Suggested teaching time 40-50 minutes Lesson objectives To learn how to create and edit title and bullet slides, you will: a b c d Select slide types by using the

More information

-Using Excel- *The columns are marked by letters, the rows by numbers. For example, A1 designates row A, column 1.

-Using Excel- *The columns are marked by letters, the rows by numbers. For example, A1 designates row A, column 1. -Using Excel- Note: The version of Excel that you are using might vary slightly from this handout. This is for Office 2004 (Mac). If you are using a different version, while things may look slightly different,

More information

Microsoft Office Word 2010

Microsoft Office Word 2010 Microsoft Office Word 2010 Content Microsoft Office... 0 A. Word Basics... 4 1.Getting Started with Word... 4 Introduction... 4 Getting to know Word 2010... 4 The Ribbon... 4 Backstage view... 7 The Quick

More information

Writing Practice Tool Guide

Writing Practice Tool Guide Writing Practice Tool Guide Virginia Standards of Learning Grades 5, 8, & End-of-Course (EOC) Writing February, 2013 Pearson 1 Revised February 14, 2013 Table of Contents OVERVIEW... 3 SYSTEM REQUIREMENTS

More information

Introduction to the Visual Studio.NET Integrated Development Environment IDE. CSC 211 Intermediate Programming

Introduction to the Visual Studio.NET Integrated Development Environment IDE. CSC 211 Intermediate Programming Introduction to the Visual Studio.NET Integrated Development Environment IDE CSC 211 Intermediate Programming Visual Studio.NET Integrated Development Environment (IDE) The Start Page(Fig. 1) Helpful links

More information

Forms for Palm OS Version 4 Manual

Forms for Palm OS Version 4 Manual Forms for Palm OS Version 4 Manual Revision Date 12/05/2007 HanDBase is a Registered Trademark of DDH Software, Inc. All information contained in this manual and all software applications mentioned in

More information

Tabbing Between Fields and Control Elements

Tabbing Between Fields and Control Elements Note: This discussion is based on MacOS, 10.12.6 (Sierra). Some illustrations may differ when using other versions of macos or OS X. The capability and features of the Mac have grown considerably over

More information

GUI Design and Event- Driven Programming

GUI Design and Event- Driven Programming 4349Book.fm Page 1 Friday, December 16, 2005 1:33 AM Part 1 GUI Design and Event- Driven Programming This Section: Chapter 1: Getting Started with Visual Basic 2005 Chapter 2: Visual Basic: The Language

More information

Microsoft Visio 2016 Foundation. Microsoft Visio 2016 Foundation Level North American Edition SAMPLE

Microsoft Visio 2016 Foundation. Microsoft Visio 2016 Foundation Level North American Edition SAMPLE Microsoft Visio 2016 Foundation Microsoft Visio 2016 Foundation Level North American Edition Visio 2016 Foundation - Page 2 2015 Cheltenham Group Pty. Ltd. All trademarks acknowledged. E&OE. No part of

More information

Barchard Introduction to SPSS Marks

Barchard Introduction to SPSS Marks Barchard Introduction to SPSS 22.0 3 Marks Purpose The purpose of this assignment is to introduce you to SPSS, the most commonly used statistical package in the social sciences. You will create a new data

More information

Using Microsoft Word. Paragraph Formatting. Displaying Hidden Characters

Using Microsoft Word. Paragraph Formatting. Displaying Hidden Characters Using Microsoft Word Paragraph Formatting Every time you press the full-stop key in a document, you are telling Word that you are finishing one sentence and starting a new one. Similarly, if you press

More information

SlickEdit Gadgets. SlickEdit Gadgets

SlickEdit Gadgets. SlickEdit Gadgets SlickEdit Gadgets As a programmer, one of the best feelings in the world is writing something that makes you want to call your programming buddies over and say, This is cool! Check this out. Sometimes

More information

SETTING UP A. chapter

SETTING UP A. chapter 1-4283-1960-3_03_Rev2.qxd 5/18/07 8:24 PM Page 1 chapter 3 SETTING UP A DOCUMENT 1. Create a new document. 2. Create master pages. 3. Apply master pages to document pages. 4. Place text and thread text.

More information

MOODLE MANUAL TABLE OF CONTENTS

MOODLE MANUAL TABLE OF CONTENTS 1 MOODLE MANUAL TABLE OF CONTENTS Introduction to Moodle...1 Logging In... 2 Moodle Icons...6 Course Layout and Blocks...8 Changing Your Profile...10 Create new Course...12 Editing Your Course...15 Adding

More information

How to Create Greeting Cards using LibreOffice Draw

How to Create Greeting Cards using LibreOffice Draw by Len Nasman, Bristol Village Ohio Computer Club If you want to create your own greeting cards, but you do not want to spend a lot of money on special software, you are in luck. It turns out that with

More information

SPARK. User Manual Ver ITLAQ Technologies

SPARK. User Manual Ver ITLAQ Technologies SPARK Forms Builder for Office 365 User Manual Ver. 3.5.50.102 0 ITLAQ Technologies www.itlaq.com Table of Contents 1 The Form Designer Workspace... 3 1.1 Form Toolbox... 3 1.1.1 Hiding/ Unhiding/ Minimizing

More information

Writing and Running Programs

Writing and Running Programs Introduction to Python Writing and Running Programs Working with Lab Files These instructions take you through the steps of writing and running your first program, as well as using the lab files in our

More information

Creating Web Pages with SeaMonkey Composer

Creating Web Pages with SeaMonkey Composer 1 of 26 6/13/2011 11:26 PM Creating Web Pages with SeaMonkey Composer SeaMonkey Composer lets you create your own web pages and publish them on the web. You don't have to know HTML to use Composer; it

More information

Introduction. Headers and Footers. Word 2010 Working with Headers and Footers. To Insert a Header or Footer: Page 1

Introduction. Headers and Footers. Word 2010 Working with Headers and Footers. To Insert a Header or Footer: Page 1 Word 2010 Working with Headers and Footers Introduction Page 1 You can make your document look professional and polished by utilizing the header and footer sections. The header is a section of the document

More information

Microsoft Word 2007 Essential Skills

Microsoft Word 2007 Essential Skills The "Anatomy" of the Word Window The typical program window will look similar to that shown below. It is possible to customize your own display, but that is a topic for discussion later on. OFFICE BUTTON

More information

OU EDUCATE TRAINING MANUAL

OU EDUCATE TRAINING MANUAL OU EDUCATE TRAINING MANUAL OmniUpdate Web Content Management System El Camino College Staff Development 310-660-3868 Course Topics: Section 1: OU Educate Overview and Login Section 2: The OmniUpdate Interface

More information

Computer Science 110. NOTES: module 8

Computer Science 110. NOTES: module 8 Computer Science 110 NAME: NOTES: module 8 Introducing Objects As we have seen, when a Visual Basic application runs, it displays a screen that is similar to the Windows-style screens. When we create a

More information

Chapter 5 Making Life Easier with Templates and Styles

Chapter 5 Making Life Easier with Templates and Styles Chapter 5: Making Life Easier with Templates and Styles 53 Chapter 5 Making Life Easier with Templates and Styles For most users, uniformity within and across documents is important. OpenOffice.org supports

More information

EXCEL 2003 DISCLAIMER:

EXCEL 2003 DISCLAIMER: EXCEL 2003 DISCLAIMER: This reference guide is meant for experienced Microsoft Excel users. It provides a list of quick tips and shortcuts for familiar features. This guide does NOT replace training or

More information

PowerPoint Basics (Office 2000 PC Version)

PowerPoint Basics (Office 2000 PC Version) PowerPoint Basics (Office 2000 PC Version) Microsoft PowerPoint is software that allows you to create custom presentations incorporating text, color, graphics, and animation. PowerPoint (PP) is available

More information