Apply Your Knowledge

Set objMyVar GetObject(App.WordDoc) 3. The reference to Object Libraries provides Visual Basic with which of the following information C. Object types supported by the ActiveX Server and their properties and methods. D. Functions for creating object libraries. 4. Which of the following statements will define an object variable and return a valid object reference of type Application 5. Assume that you have a COM component with an application name of MyApp and an object called Spreadsheet. Which...

Study Strategies

Create a COM component that implements business rules or logic. Components include DLLs, ActiveX controls, and active documents. For the first general objective (Create a COM component that implements business rules or logic), become familiar with the material discussed in this chapter's major sections Steps in Creating a COM Component, Implementing Business Rules with COM Components, Implementing an Object Model with a COM Component, and Implementing COM Components Through Class Modules. Do...

Inline Error Handling

Another form of the On Error statement is On Error Resume Next. This alternative is used to handle an error immediately after the line causing the error rather than branching to a specified error handler. Another use of On Error Resume Next is to simply allow your application to ignore errors that you don't need to handle at all. In Listing 11.1, you can assume that the GetObject function might cause a runtime error. Notice that this code attempts to handle the error on the following line by...

Adding a PopUp Menu to an Application

Pop-up menus, also known as context menus or right-mouse menus, provide the user another convenient way to control the application. Pop-up menus are usually unique for various areas of an application. They can be created in Visual Basic or the operating system, and certain objects provide them. Microsoft Excel provides an example of pop-up menus in Figure 3.2. With Excel, the user has the option to use the main menu bar, shortcut keys, or pop-up menus. Different pop-up menus are found,...

Exam Developing Distributed Applications

One of the strengths of ActiveX Data Objects (ADO) is its support for asynchronous operations. Some of these operations issue events before they begin and or after they complete. To test this, you decide to create and populate a recordset object from a connection object method. Which ADO event will indicate that the recordset has been populated 2. You have declared an object variable to be of type ADODB.Recordset, but when you pull down the object combo box in the code window, you don't find...

Using the Create Object and Get Object Functions to Instantiate Objects

Because many COM components do not yet support the As New keyword, you will need to create and instantiate object variables for these components' classes with standard variable declarations and the CreateObject or GetObject functions. The CreateObject and GetObject functions return a reference to a server class object. Use them with the Set keyword to assign their return values to a previously declared class object variable Set objExcel Set objExcel The CreateObject function takes a single...

Finding and Reusing a Component with Visual Component Manager

Open VCM refer back to Figure 12.10 from the VB toolbar by clicking on the VCM icon. 2. Click the Find binoculars icon on the VCM toolbar. 3. On the resulting Find dialog box see Figure 12.20 , enter either a component name or text to locate in the component's keywords, description, or annotations. You can also limit your search to just one type of component by making a choice in the Of Type drop-down menu. 4. When the desired component appears in the Find window, double-click its name to...

Compiling to PCode

The menu command to produce your EXE file. The menu command to produce your EXE file. Setting compiler preferences at compile time. Yes, P-Code is still a compiler option. After you have loaded a project and are ready to produce an EXE, your File menu might look like Figure 20.1. When you choose Make, you will see another dialog box that enables you to set various compiler options. To instruct the compiler to produce a P-Code EXE, all you need to do is select the P-Code option from the dialog...

Adding and Deleting Controls Dynamically Using the Controls Collection

The Add and Remove methods of the Controls Collection are new to VB6. You can use these methods to add and delete controls from a form instead of using the control array technique described in the previous section. Following is an overview of the general steps that you need to take in order to dynamically add and remove controls with the Controls Collection more detailed discussion is given in the following sections 1. Find out the control's ProgID, a unique string used by the Windows operating...

Managing ADO Objects With the Data Environment Designer

A Data Environment Designer is a visual interface for managing a VB application's ADO Connection and Command objects. Take the following steps to add a Data Environment Designer to your project 8.1 Adding a Data Environment Designer to a Project 1. Choose the Project menu in VB. Make sure that Add Data Environment is one of the Project menu's options. If Add Data Environment does not appear on the Project menu, add it by performing the following steps 2. Choose Project, Components and select...

Providing Whats ThisHelp in an Application

Whatsthisbutton Vba

When ToolTips don't provide enough information and you don't want to force the user to toggle between a Help file and your application, Visual Basic provides another means of displaying tips to the user. An example of ToolTips In Visual Basic 6. An example of ToolTips In Visual Basic 6. WhatsThisHelp as it appears in a Visual Basic application. Note the similarity to ToolTips. WhatsThisHelp as it appears in a Visual Basic application. Note the similarity to ToolTips. WhatsThisHelp gives the...

The KeyUp and Key Down Events

The KeyDown and KeyUp events happen when the user respectively presses and releases a key on the keyboard. Their event procedures take the following two parameters KeyCode contains an integer code for the physical key that the user pressed. You can check for a particular key by comparing KeyCode with one of the special VB internal constants for physical key codes. Each constant name begins with the string vbKey followed by an obvious name for the key the letter of the key if it's an alphabetic...

Overview of COM Component Programming

Recall the syntax you saw in the preceding chapter for instantiating ActiveX objects in a client application Dim xl as Excel.Application set xl set xl An object is externally creatable when an application that can serve as an ActiveX client can declare an instance of that object as a variable and then manipulate the methods and properties of that object. Some server components including any server components that you create with VB support Microsoft's recommended standard, Dim As New. Assuming...

Preprocessor Directives

A preprocessor gets its name precisely because it operates on source code before the compiler processes the code. The only function of the VB preprocessor is to conditionally evaluate code to determine which parts of it the compiler should process. The preprocessor uses just the following four conditional flow control directives Aside from the prefix, the preprocessor syntax is just like that of the If, Elself, Else, and End If flow control directives in the Visual Basic programming language....

Using the imageList Control

The ImageList is a control that enables you to store graphic images in an application. Other controls can then use the ImageList as a central repository for the images that they will use. Both bitmaps .bmp files and icons .ico files can be stored in the ImageList control. At runtime the ImageList is invisible, just like a Timer or a CommonDialog control, so you can place it anywhere on a form without interfering with the user interface. After an ImageList control has been added to a form,...

Compiling to Native Code

Although P-Code has its advantages, the capability to compile to native code is an advantage that most VB6 programmers put to good use, especially because it permits additional optimizations. This discussion focuses on the basic compiler options for native code. Visual Basic versions 5 and 6 have the capability to compile native machine code into the EXE files it produces. Like the applications normally produced with other language compilers that produce Windows programs for example, Visual C ,...

Declaring and Defining the Scope of a Variable

When the programmer requires a variable, Visual Basic allows two different ways of declaring them. The first method is called implicit variable declaration. This method enables a programmer to use a variable any time he or she requires one. The programmer just has to type a new variable name into the source code and the variable is automatically created by VB. The following line of code uses implicit variable declaration x Hello In this code sample, the xcontains the String value Hello. Visual...