Corel DESIGNER, CorelDRAW, and Corel PHOTO-PAINT provide an integrated development environment (IDE) for creating VBA macro projects. Called the Script Editor, this IDE is similar to the one included with the full version of Visual Basic. You can use the Script Editor to perform various tasks related to VBA macros, such as the following:
You cannot use the Script Editor to edit JavaScript (JS) scripts. If you want to edit a JS file, you must use Notepad or another text editor.
You cannot use the Script Editor to compile executable (EXE) program files.
The Script Editor features three main areas:
The Script Editor also features four main toolbars:
For more information on these toolbars, see Using the Script Editor toolbars.
The Script Editor (CorelDRAW version shown) features the following:
The Script Editor also lets you access the Object Browser, which displays the entire object model of each referenced component and of the host application. For more information, see Using the Object Browser.
Although the Script Editor opens in a separate window from its host application, it runs within the process of that application. To display the Script Editor, do any of the following:
To switch between the Script Editor and the application, use the Windows taskbar, or press Alt + F11 or Alt + Tab.
For more detailed information on constructing code procedures and setting properties, please see the Microsoft Visual Basic for Applications Help file, which is available from the Help menu in the Script Editor.
The Project Explorer is essential for navigating macro projects and their contents: documents and objects, forms, modules, and class modules (or "classes").
Each type of component in the Project Explorer has an icon assigned to it:
The Code window is where you spend most of your time when working on macros. A standard code editor in the style of Microsoft Visual Studio, the Code window lets you do the following:
If you are already familiar with any of the Microsoft Visual Studio editors, the Code window will be entirely familiar to you.
,
To display the Code window, do one of the following:
Formatting code automatically
The Script Editor formats code automatically for you. Even the capitalization of keywords, functions, subroutines, and variables is taken care of by the Script Editor, irrespective of what you type. You cannot custom-format code, although you can set the indentation for each line, as well as the placing of custom line breaks.
If you use the returned value when calling a function, the parentheses around the parameters are mandatory (just as in most modern programming languages):
a = fooFunc (b, c)
However, if the returned value from a function call is being discarded, or if you are calling a subroutine, the parentheses must be left out (unlike in most other languages):
barFunc d, e fooBarSub f
If you prefer always to see the parentheses, use the Call keyword before the function call or subroutine call:
Call barFunc (d, e) Call fooBarSub (f)
Coloring syntax automatically
As you develop code in the Code window, the Script Editor colors each word according to its classification.
The Code window also uses the following colorization techniques:
Syntax coloring and highlighting:
Breakpoints and bookmarks are lost when you quit the application.
The Script Editor lets you modify the default colors for syntax highlighting. Click Tools Options, and choose your settings on the Editor Format page.
Checking syntax automatically
Every time you move the cursor out of a line of code, the Script Editor checks the syntax of the code in that line; if an error is found, the line is colored red and a pop-up warning is displayed. This real-time checking is useful (particularly when you are learning to program macros) because it indicates many possible errors in the code without having you run the code.
The Script Editor lets you disable pop-up warnings. Click Tools Options, click the Editor tab, and then disable the Auto Syntax Check check box. Although the Script Editor still checks the syntax and colors erroneous lines red, it stops displaying a warning when you paste text from another line of code.
Jumping to definitions
The Script Editor lets you jump directly to the definition of a variable, function, or object.
To return to where you requested the definition, right-click anywhere in the Code window, and then click Last Position.
Using contextual pop-up lists for automatic completion
The Script Editor adds the functions you write and the variables you define to an internal list that contains all built-in keywords and enumerated values. As you type, the Script Editor displays a contextual list of words that are valid candidates for insertion at the current position. This auto-completion feature makes code development quicker and more convenient.
An auto-completion pop-up list:
If you type the first few characters of the word you want to use, the pop-up list advances to the nearest candidate that matches those characters. Select the desired word, and then do one of the following:
To force the pop-up menu display, press Ctrl + Spacebar; the menu scrolls to the word that most closely matches the characters that you have typed so far. This technique is particularly useful for filling parameter lists when calling a function or subroutine. If there is only one exact match, the Script Editor inserts the word without popping up the list; to display the pop-up list for the selected keyword at any time without auto-filling it, press Ctrl + J.
The Properties window lists all editable properties for the selected object. Many macro objects — including projects, modules, and forms and their controls — have property sheets that can be modified.
The Properties window, with the properties of a form displayed:
The Properties window is automatically updated when you select an object, or when you change the properties of the selected object by using other methods (for example, by using the mouse to move and resize form controls).
To display or hide the Properties window, do any of the following:
The Script Editor features four toolbars — Standard, Debug, Edit, and UserForm — that you can use to perform macro-related tasks.
The Standard toolbar is the default toolbar.
The Debug toolbar contains buttons for common debugging tasks (see Debugging macros).
The Edit toolbar contains buttons for common code-editing tasks.
The UserForm toolbar contains buttons specific to designing dialog boxes (see Designing dialog boxes).
To display or hide a toolbar, click View Toolbars, and then click the corresponding command. A check mark next to a command indicates that its toolbar is currently displayed.
You can "float" a toolbar by dragging it from the menu bar.
You can dock a toolbar by dragging it to the menu bar.
The Object Browser is one of the most useful tools that is provided by the Script Editor. In an easy-to-use, structured format, the Object Browser displays the entire object model of each referenced component and, most importantly, ofCorel DESIGNER, CorelDRAW, and Corel PHOTO-PAINT.
Referenced components include all ActiveX or Object Linking and Embedding (OLE) objects that are used by the project.
The Object Browser window features the following items:
The Object Browser window (Corel PHOTO-PAINT version shown):
To open the Object Browser from within the Script Editor, do any of the following:
To reference the object model of another application, click Tools References. Referenced components can be accessed by the macro code.
Using the Class list
Every project and library has an object model that contains the following class-related items, which are displayed in the Class list:
Global values apply to an entire project or library, and they include individual members from enumerations (such as text-paragraph alignments, shape types, and import/export filters).
Classes contain properties, methods, and events. For more information, see What is a class?.
For documentation on all classes available to CorelDRAW or Corel PHOTO-PAINT, see the API Reference | Classes section.
Modules contain macro code.
For documentation on all modules available to CorelDRAW, see the API Reference | Modules section.
Types are customized data types that supplement the built-in data types that are provided by the automation environment (see Declaring variables).
For documentation on all types available to CorelDRAW, see the API Reference | Types section.
Enumerations represent fixed values in the procedures and functions of the coding for a macro. For more information, see What is an enumeration?.
For documentation on all enumerations available to CorelDRAW or Corel PHOTO-PAINT, see the API Reference | Enumerations section.
Each type of item in the Class list has an icon assigned to it:
To access the Help topic for a selected item, click the Help button, or press F1.
Using the Member list
When you choose an item from the Class list, the members of that item appear in the Member list. Class members include the following:
A property can be a simple type (such as a Boolean, integer, or string), or it can be a class or enumeration from the Class list. A property that is based on a class from the Class list inherits all members of that class.
Many classes have a default property. The default property is implied if no property name is given when getting or setting the value of the parent object. For example, collection types have the default property Item, which can be indexed; in such instances, it is not necessary to specify the Item property. Here,
ActiveSelection.Shapes.Item(1).Selected = False
is the same as the shorter
ActiveSelection.Shapes(1).Selected = False
because Item is the default or implied property of a collection of shapes.
For documentation on all properties available to CorelDRAW or Corel PHOTO-PAINT, see the API Reference | Properties section.
Methods are commonly known as "member functions" — functions that a class can perform on itself. A good example is the Move method of the Shape class in CorelDRAW, which moves a shape by using an [x, y] vector. The following code moves the selected shapes 2 measurement units to the right and 3 measurement units upwards:
ActiveSelection.Move 2, 3
If the return value of a function is not used, the function call does not take parentheses around the argument list unless the Call keyword is used.
Call
For documentation on all methods available to CorelDRAW or Corel PHOTO-PAINT, see the API Reference | Methods section.
Events are associated with some classes. You can set up an event handler that is called when that event occurs in the application; this functionality lets you develop sophisticated applications that respond automatically to what is happening within the application. Commonly handled events include the BeforePrint, BeforeSave, PageActivate, SelectionChange, and ShapeMove events of the Document class in Corel DESIGNER and CorelDRAW.
For documentation on all events available to CorelDRAW or Corel PHOTO-PAINT, see the API Reference | Events section.
The constants displayed in the Member list are members of enumerations or are defined as public in a module. Enumerations group related items from a closed list — such as Corel DESIGNER and CorelDRAW shape types, import/export filters, and alignments — for use anywhere an integer value is required.
InCorel DESIGNER, CorelDRAW, and Corel PHOTO-PAINT, many constants begin with cdr (for example, cdrEPS and cdrLeftAlignment), while others begin with clr, cui, pdf, pnt, or prn. Visual Basic also has its own constants, including ones (such as vbKeyEnter) for keystrokes and ones (such as vbOK) for dialog-box buttons.
For documentation on all constants available to CorelDRAW or Corel PHOTO-PAINT, see the API Reference | Constants section.
Each type of item in the Member list has an icon assigned to it:
Using the Information window
The Information window provides information about the selected class or class member. This information includes the following:
The Information window for the Document.Application property in Corel PHOTO-PAINT:
The Information window provides hyperlinks to all referenced types and classes that are defined within the current object model. For example, the information for the Document.Application property in Corel PHOTO-PAINT (see the preceding figure) includes the following hyperlinks:
When the Information window is not tall enough to reveal its complete contents, a scroll bar is provided. To increase the height of the Information window, drag the top border of the window upwards.
Using the search controls
The search controls let you search the selected project or library for a given string. Searching is useful when you can only partly remember the name of a class or class member, or when you want to find classes and members that have similar names (such as those containing the word "open").
Searching the CorelDRAW object model
To search the classes and members of the selected object model, type a string into the Search box, and then click the Search button . The Search Results window displays, in alphabetical order, all matches. Clicking a match advances the Class list and Member list to that item and displays the Information window for that item.
Matching class names have a blank Member column in the Search Results window.
To hide the Search Results window, click the Hide Search Results button .