Visual Basic 6.0 Desktop.
1. In building your class module, you've been asked to make a property write-only. How can you specify a write-only property for a class?
2. Your company's COM component will include three classes. The main class will encapsulate insurance policy processing. This class will instantiate and manipulate two private classes to support financial processing. The specifications call for client applications to be able to access some properties and methods from the financial classes but to never be allowed to instantiate them directly. What strategy should you choose?
3. In order to make inventory changes offline, you've decided to implement a disconnected Recordset. You declare, create, and populate the Recordset correctly. How do you go about disconnecting it?
4. In developing an ActiveX DLL, one of the requirements for your class is to expose a public event. Client applications will use this event to display a progress during a lengthy, asynchronous task. How would you write the event declaration to allow the user to cancel this process?
5. You are developing an ActiveX component that validates IP addresses. If an invalid IP address is passed to the component, then the component must pass back the address 0.0.0.0. Which of the following deployment models will allow your component to be used simultaneously by multiply applications and still provide the best possible performance?
6. A client application named Client 1 will trap custom events from an ActiveX component named Server 1. Server1 will raise the event from a class named MyClass. Which statement must be used inside Client1 when a server object variable named mobjServer1 is declared?
A. Public mobjServer1 As New MyClass
B. Public Events mobjServer1 As MyClass
C. Public mobjServer1 As Event
D. Public WithEvents mobjServer1 As MyClass
7. You are using ActiveX Data Objects (ADOs) in the initial coding of a Visual Basic database application. You have created an ADO Command object named cndMyCommand and associated it with an ADO Connection object named cnnMyConnection. You want to issue the following UPDATE statement against your database:
UPDATE Employees SET Salary = Salary * 1.10
Which of the following sets of ADO statements should you use to update the Employees table?
A. Set cndMyCommand = "UPDATE Employees SET Salary = Salary * 1.10"
cnd MyCommand Execute
B. Set cndMyommand.CommandText = "UPDATE Employees SET Salary = Salary * 1.10"
cndMyCommand.Execute
C. cnnMyConnection.CommandText = "UPDATE Employees SET Salary = Salary * 1.10"
cndMyCommand Execute
D. cnnMyConnection.Execute "UPDATE Employees SET Salary = Salary * 1.10"
Answers.
1. C Explanation: There are many possible combinations of Property procedures. All of them are valid, but some are relatively uncommon, like write-only properties.
2. D Explanation: The Instancing property of the two private classes should be changed to PublicNotCreateable, so that other applications can use objects of this class. Only the component can create the objects. Other applications can't create objects from these classes
3. C Explanation: Setting the Recordset's ActiveConnection property to Nothing disconnects it from the active connection. The connection can then be closed and made to the client-side Recordset
4. C Explanation: When the client application receives a PercentDone event, the Percent argument will contain the percentage of the task that's complete and the Cancel argument will allow the client to set it to True to cancel the task. Because the Cancel argument wasn't declared with the ByVal keyword, Visual Basic uses its default behavior, which is to pass by reference.
5. B Explanation: Although an internally compiled object provides the best performance, the entire application must be compiled each time the component is update, and the code must be loaded each time another applications requires its use. The local in-process .dll model solves these problems and causes only a small reduction in performance. The .dll model also simplifies the isolation and preservation of modules that can be reused in other applications.
6. D Explanation: In order for an ActiveX client application to respond to another component’s events, an object variable that references the component must be declared by using the WithEvents clause. Additionally an event procedure must be written inside the client application that can respond to the event. This event will have been declared in the ActiveX component and will be invoked by a RaiseEvent statement.
7. D Explanation: There are two principal methods of using ADO to execute an SQL statement directory. The Execute method for a Command object requires that the SQL statement be assigned to the CommandText property of the Command before invoking the Execute method. Because the Commantext property is a string and not an object, you cannot use the Set statement to assign its value. The Execute method for an ADO Connection object requires the SQL statement as its first argument. There is no CommandText property for an ADO Connection object Use of the ADO Command object is required only when passing parameterized or prepared SQL statements. When SQL statements with no parameters are executed, a Command object is not necessary.