Sams Teach Yourself Visual Basic 6 in 24 Hours

Sams Teach Yourself Visual Basic 6 in 24 Hours

By Greg Perry

The System Objects

You've worked with several Visual Basic objects already. The Printer object is an object you use with a Print method to send output to the printer, as in the following statement:

Printer.Print Tab(15); "Company Balance Sheet"

In addition, you've seen the Debug object when printing to the Immediate window like this:

Debug.Print "intVar is "; intVar

In both cases, the object represents an item outside your application's scope. The printer and the Immediate window are not your application's; therefore, Visual Basic uses objects to represent them. The Printer object doesn't reference any particular printer; rather, the Printer object references the current Windows printer. The Debug object represents the Immediate window.

A system object is an object defined by Visual Basic that lies outside your program's immediate scope.

The Printer and the Debug objects are system objects predefined by the Visual Basic system. Although a command button on your form is an object, the command button isn't a system object because the object didn't really exist before you placed the command button on the form—only its pattern existed on the Toolbox window.

Table 22.1 lists all the predefined system objects your applications can work with.

Table 22.1. The system objects and their methods.

Object Description Methods
App Your current application The EXEName method returns the application's filename. Path returns the application's path. Title returns the primary startup form's title bar text. Previnstance returns True or False to indicate whether another instance (copy) of the application is currently running.
ClipBoard The Windows Clipboard The method Clear erases the Clipboard. GetData returns the graphic image stored on the Clipboard. GetFormat returns the format of the Clipboard object. GetText returns the text on the Clipboard. SetData copies a graphic image to the Clipboard. SetText copies text to the Clipboard.
Debug The Immediate window The method Print copies information, at runtime, to the Immediate window (only possible in Visual Basic programs you run from Visual Basic's development environment).
Printer The system printer Provides printer support.
Screen The user's screen FontCount returns the number of fonts the current screen supports. Fonts contains a list of all the screen's possible font names. Height returns the twip height of the screen area. MousePointer holds (or determines if you specify a new one) the shape of the mouse cursor. TwipsPerPixelX returns the number of possible horizontal twips. TwipsPerPixelY returns the number of possible vertical twips. Width returns the width, in twips, of the screen.

Use these objects and methods to return information about the objects. For example, you could append the current application pathname to a string variable like this:

strFullName = App.Path & "\" & "Afile.dat"

Although you won't use the system objects in every application, they do come in handy when you're performing interaction with the Windows Clipboard or the screen.

Share ThisShare This

Informit Network