Using AutoScript – PB Docs 120

Using AutoScript

AutoScript is a tool designed to help you write PowerScript
code more quickly by providing a lookup and paste service inside
the Script view. It is an alternative to using the paste toolbar
buttons or the Browser—you do not need to move your hands
away from the keyboard to paste functions, events, variables, properties,
and templates for PowerBuilder TRY, DO, FOR, IF,
and CHOOSE statements into your script.

If you are not sure what the name or syntax of a function
is or what the names of certain variables are, AutoScript can show
you a list to choose from and paste what you need right into the
script. If you can remember part of the name, start typing and select
Edit>Activate AutoScript (or do nothing if automatic pop-up
is turned on). If you cannot remember the name at all, turn atomatic pop-up
on, place your cursor in white space, and select Edit>Activate AutoScript.

note.gif Assign a shortcut key If you plan to use AutoScript, assign a shortcut key to the
Activate AutoScript menu item. See “Creating shortcut keys”.

Where you use AutoScript

You can use AutoScript in three different contexts:

  • When you can remember part of the name and you want
    AutoScript to finish typing it for you or show you a list of alternatives.
  • When you cannot remember the name or you just want
    a list. AutoScript options can help you narrow the list if you do
    not know the name but you do know the type you are looking for.
    For example, you can choose to see a list showing all variables,
    or only all local variables.
  • When you want a list of the properties and/or
    functions and events that apply to an identifier followed by a dot.

For how to use AutoScript options, see “Customizing AutoScript”.

Two ways to use AutoScript

AutoScript can pop up a list automatically when you pause
while typing, or when you request it:

  • Turn
    automatic pop-up on to have AutoScript pop up the list or complete what
    you are typing when you pause for a few seconds after typing one
    or more characters or an identifier followed by a dot. See “Using automatic pop-up”.
  • Invoke AutoScript when you need it by pressing the
    shortcut key you assigned to the Edit>Activate AutoScript
    menu item when you have typed one or more characters or an identifier
    followed by a dot. Pressing the shortcut key activates AutoScript
    only once. It does not turn automatic pop-up on.

For how to paste an item from the pop-up window into a script,
see “Using the AutoScript pop-up
window”
.

Using the AutoScript pop-up window

If there is more than one property, variable, method, or statement
that could be inserted, AutoScript pops up an alphabetical list
of possible completions or insertions. An icon next to each item
indicates its type. The following screen includes an instance variable,
events, properties, statements, and a function:

sc02.gif

If a function is overloaded, each version displays on a different
line in the AutoScript pop-up window.

If you have started typing a word, only completions that begin
with the string you have already typed display in the list.

Case sensitivity

If you have set the PasteLowerCase PB.INI variable
to 0 as described in “Pasting statements”, AutoScript always pastes uppercase characters.
Otherwise, AutoScript always pastes lowercase characters.

The case of any characters you have already typed is preserved.
For example, if you are using AutoScript to complete a function
name and you want to use mixed case, you can type up to the last
uppercase letter before invoking AutoScript. AutoScript completes
the function name in lowercase characters and pastes an argument
template.

Pasting an item into the script

To paste an item into the script, press Tab or Enter or double-click
the item. Use the arrow and page up and page down keys to scroll
through the list. If the item is a function, event, or statement,
the template that is pasted includes descriptive comments that you
replace with argument names, conditions, and so forth. The first
commented argument or statement is selected so that it is easy to
replace. You can jump to the next comment by selecting
Edit>Go
To>Next Marker.

note.gif Go to next marker You can use Edit>Go To>Next Marker to jump
to the next comment enclosed by /* and */ anywhere
in the Script view, not just in AutoScript templates. For the steps
to create a shortcut for this menu item, see “Customizing AutoScript”.

If you do not want to paste from the list

Press the Backspace key or click anywhere outside the pop-up
window to dismiss it without pasting into the script.

If nothing displays

AutoScript does not pop up a list if the cursor is in a comment
or string literal or if an identifier is complete. If neither of
these conditions applies and nothing displays when you select Edit>Activate
AutoScript, there may be no appropriate completions in the current
context. Check that the options you need are selected on the AutoScript
options page as described in “Customizing AutoScript”.

Customizing AutoScript

There are four ways to customize AutoScript:

Creating shortcut keys

AutoScript is easier to use if you create shortcuts for the
menu items that you use frequently.

proc.gif To modify or create shortcut keys for using AutoScript:

  1. Select Tools>Keyboard Shortcuts
    from the menu bar and expand the Edit menu in the Keyboard Shortcuts
    dialog box.

  2. Scroll down and select Activate AutoScript and
    type a key sequence, such as Ctrl+space.

  3. Expand the Go To menu, select Next Marker, and
    type a key sequence, such as Ctrl+M.

    After you click OK, the shortcuts display in the Edit menu.

Specifying what displays
in the list

You can select different items to include in three different
contexts:

  • When you have started typing a variable
    or method name or the beginning of a PowerScript statement
  • When you have typed the name of an object followed
    by a dot
  • When the cursor is at the beginning of a new line
    or in white space

To make these customizations, select Design>Options
from the menu bar and select the AutoScript tab.

Table 7-3 shows
what is included in the list or pasted when you check each box.

Table 7-3: Setting options for AutoScript
Check box Displays
Arguments Arguments for the current function or
event.
Local Variables Variables defined in the current script.
Instance Variables Variables defined for and associated
with an instance of the current object or, after a dot, variables
associated with the object preceding the dot.
Shared Variables Variables defined for the current object
and associated with all instances of it.
Global Variables Variables defined for the current application.
Properties Properties for the current object or,
after a dot, properties for the object preceding the dot. Includes
controls on the current window.
Methods Functions and events for the current
object or, after a dot, functions and events for the object preceding
the dot.
Statement Templates PowerScript statement templates for each
type of IF, FOR, CHOOSE CASE, TRY,
or DO statement with comments indicating what
code should be inserted. This option is off by default.

Turning options off reduces the length of the list that displays
when you invoke AutoScript so that it is faster and easier to paste
a completion or insert code into the script:

  • To
    show all variables and methods when typing, check all the boxes
    except Statement Templates in the Partial Name Resolution Include
    group box. When you pause or press the Activate AutoScript shortcut
    key, the list shows variables and methods that begin with the string
    you typed.
  • To quickly find functions on an object, clear all
    the boxes except Methods in the After A Dot Include group box. When
    you type an instance name followed by a dot, only function and event
    names for the instance display.
  • To see a list of arguments and local variables when
    the cursor is in white space, check the Arguments and Local Variables
    boxes in the When No Context Include group box. When you press the
    Activate AutoScript shortcut key, the list shows only arguments
    and local variables.

note.gif Using name completion shortens the list You might not need to clear boxes on the AutoScript page to
reduce the length of the list if you are using name completion and
the Activate AutoScript shortcut key to invoke AutoScript. For example,
suppose you have created an instance called inv_ncst_dssrv of
the class n_cst_dssrv and
you know the function you want to use begins with of_g.
Type the following into a script and then press the Activate AutoScript
shortcut key:

AutoScript displays a pop-up window showing only the functions
on n_cst_dssrv that begin
with of_g.

Using automatic pop-up

Most of the time you will probably use a shortcut key to invoke
AutoScript, but you can also have AutoScript pop up a list or paste
a selection automatically whenever you pause for several seconds
while typing. To do so, check the Automatic Popup box on the AutoScript
options page. Automatic pop-up does not operate when the cursor
is at the beginning of a line or in white space.

This feature is most useful when you are entering new code.
You can customize the options in the Partial Name Resolution Include
and After A Dot Include group boxes to reduce the number of times
AutoScript pops up.

When you are editing existing code, it is easier to work with
automatic pop-up off. AutoScript might pop up a list or paste a
template for a function when you do not want it to. Using only the
shortcut key to invoke AutoScript gives you complete control.

Using AutoScript only with
dot notation

If you want AutoScript to work only when
you have typed an identifier followed by a dot, check the Activate
Only After a Dot box on the AutoScript options page. The effect
of checking this box applies whether or not you have checked Automatic
Popup. You might find it most useful when you have checked Automatic
Popup, because it provides another way to limit the number of times
AutoScript pops up automatically.

Example

The following simple example illustrates how AutoScript works
with automatic pop-up turned off and different settings for each
context. The example assumes that you have set up F8 as the Activate
AutoScript shortcut key. To set up the example:

  • Create
    a new window and place on it a DataWindow control and a CommandButton
    control.
  • Select all the boxes in the Partial Name Resolution
    Include group box.
  • Clear all the boxes in the After A Dot Include group
    box except Methods.
  • Clear all the boxes in the When No Context Include
    group box except Arguments and Local Variables.
  • Clear both boxes in the Options group box.
Table 7-4: AutoScript example
Context Do this What happens
Partial name resolution In the Clicked event script for cb_1,
type long ll_rtn.
On a new line, type ll and
press F8.
AutoScript pastes the local variable ll_rtn into
the script because it is the only completion that begins with ll.
Type = d and
press F8.
The list displays all properties, events, functions,
variables, and statements that begin with d.
Type w and
press Tab or Enter.
The list scrolls to dw_1 and
AutoScript pastes it into the script when you press Tab or Enter.
After a dot Type a dot after dw_1 and press
F8.
The list shows all the functions and events
for a DataWindow control.
Type GetNextM and
press Tab or Enter.
AutoScript pastes the rest of the GetNextModified function
name and template into the script, retaining your capitalization.
Select Edit>Go To>Next Marker. AutoScript selects the next function argument
so you can replace it. Complete or comment out the statement.
No context In the empty ItemChanged event for dw_1,
declare some local variables, press Tab or Enter, and then press F8.
The list displays the local variables
and the arguments for the ItemChanged event.

Document get from Powerbuilder help
Thank you for watching.
Was this article helpful?
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x