Chapter 15-Advanced Topics in Visual Basic: 1. What Is An Activex Control? Give An Example
Chapter 15-Advanced Topics in Visual Basic: 1. What Is An Activex Control? Give An Example
1. What is an ActiveX control? Give an example. ANS:The term ActiveX was originally used to refer to controls that could be used with the Internet. Since then the term has been expanded to refer to executable files, controls (COM or Component Object Model objects), and DLLs that are used by multiple applications. These controls were called OLE controls for a period of time, but the term OLE currently refers only to the process of object linking and embedding. The terminology has been changing rapidly and likely will change somewhat in the next few years as the use of the Internet expands. In general, Microsoft refers to any controls as ActiveX controls. These controls may be part of Visual Basic, created by other companies, or you may create your own. The controls that are part of Visual Basic are called intrinsic controls; those that must be added later are called components. There is a large selection of ActiveX controls available, to solve many problems. You can purchase controls to display various types of gauges and indicators, display data in grids, send and receive faxes, display video, scan bar codes, display calendars and appointments, and perform many other functions. Many ActiveX controls are available as shareware, and a few are freeware. Many can be downloaded from a variety of web sites. The files for ActiveX controls have extensions of .ocx or .vbx. (Any controls developed for Visual Basic 4.0 or later should be .ocx files.)
2. What is a DLL? ANS:Windows uses dynamic link libraries (DLLs) to store collections of commonly used procedures. This means that functions available in Windows but not available in Visual Basic can still be used. As a project executes, it can call procedures from the libraries. The DLL file is then linked to your project when it runs. This is especially useful for procedures used by multiple projects; only one copy of the library is kept in memory and its procedures can be called by more than one project. 3. What does API mean? ANS:API is the Windows application programming interface. API uses Windows DLLs for such tasks as moving and resizing windows. Visual Basic uses many API DLLs to create the Visual Basic environment.
4. What are the purposes of a Declare statement? ANS:Any time you will call a procedure which is in a library, a DLL, you must include a Declare statement. Declare statements tell Visual Basic the name of the procedure and the library where it can be found, along with the arguments needed by the procedure. Once you have included the Declare, you can call the procedure as you would one of your own. You can call both sub procedures and function procedures from DLLs; the Declare statement specifies the type of procedure. (Recall that a function returns a value.) 5. Explain the difference between ByVal and ByRef. When is each used? ANS:Arguments may be passed to a called procedure by value or by reference. When passed ByVal, only a copy of the original value is passed; the called procedure cannot alter the original value. When items are passed ByRef, the memory address of the original value is passed to the procedure, allowing the procedure to change the original value. You will pass ByVal or ByRef based upon the requirements of the specific DLL. If no specification is made, the default ByRef is implied. When you are calling Windows API procedures, always declare a string
argument ByVal. (DLLs are usually written in the C language and Visual Basic and C do not store strings in the same way.) 6. Explain the difference between linking and embedding an object into a Visual Basic project. ANS:Linking causes your program to access an object that is actually maintained by the application that creates it. A reference to the linked object is kept in your code but the actual object is kept in the other application. This means that any other application that has linking ability can access the linked object and change it. When your application runs you can access the current state of the object. Embedding places the object in your code. Hence, the object is maintainable only from within your project and cannot be accessed by other projects. Another result of embedding is that the Visual Basic project file becomes significantly larger because of the embedded code. 7. What determines the list of objects that can be used with OLE on a particular system? ANS:You can create your own objects or access those available through word processors, spreadsheets, graphics programs, and the multitude of software available. Of course, the types of objects available to use in a project depend upon the applications that are installed on a particular computer system or network. 8. What does MDI mean? ANS:MDI is an acronym for multiple document interface. An example of MDI would be an application such as Microsoft Word. Word has a parent form (the main window) and child forms (each document window).
9. What are the advantages of having parent and child forms? ANS:You can open multiple child windows, maximize, minimize, restore, or close each child window, which always stays within the boundaries of the parent window. When you close (unload) the parent window, all child windows close (unload) automatically. 10. How can a child form be created? parent form? ANS:Setting the MDIChild property of a form to True will create a child form. Any form that is not set as a child form will operate independently and will not be confined to the parent window. To add an MDI (parent) form to a project, choose Project / Add MDI Form. Only one form in a project can be set as the parent.