Macro Recorder. AccuSoft 7
Anuncio
Anuncio
74 AccuTerm 7 Help
2 AccuTerm 7 Automation
2.1
Macro Recorder
Recording a Macro
You can use the Macro Recorder to create an AccuTerm macro by recording a sequence of actions, including sending keystrokes to the host and waiting for responses from the host. To start recording a new macro, use Tools
Macro
Record New Macro from the main menu. When you are finished recording the macro, click the suspend recording by clicking the
button on the Macro Recorder toolbar. You can temporarily
button on the Macro Recorder toolbar. To resume recording, click the button.
When you are finished recording a macro, the Save Macro dialog will be displayed. Here you can give your recorded macro a name (up to 32 characters, letters, numbers or underscore characters only, beginning with a letter), a short description (up to 32 characters) which is displayed in the Tools
Mac ro
Run Macro sub-menu, a detailed description and a shortcut key.
The recorded macro is saved in the "AccuTerm Macros.atsc" script file when you click the Save button.
If you do not have a macro script file open yet, you will be prompted to select the file name for your macro file. When you start AccuTerm, the macro script file (if it exists) is automatically loaded.
Macros are recorded as a sequence of Visual Basic for Applications (VBA) statements.
Running a Macro
To run a macro, select the desired macro from Tools
Macro
Run Macro menu. Alternatively, if the macro has a shortcut key assigned to it, simply press the shortcut key combination to run the macro.
Editing a Macro
You can edit your recorded macros by selecting Tools
Macro
Edit Macros... from the mainmenu.
The macro script will be displayed in the macros tab of the AccuTerm Script Editor window. Macros are written using Visual Basic for Applications (VBA) language. For more information about VBA scripting, see the
.
2.2
Scripting
AccuTerm 7 includes a powerful scripting language based on the popular Microsoft Visual Basic
Programming System, Applications Edition (VBA). The language has been enhanced to allow your script to control almost every aspect of AccuTerm’s operation.
Script Editor
Although the Script Editor is not the only way to create and use VBA scripts with AccuTerm, it is a convenient place to learn about AccuTerm's scripting features. To access the Script Editor, use Tools
Script Editor from AccuTerm's main menu.
The Script Editor window has a standard Windows menu and toolbar with tabs for each of the two script files that AccuTerm supports: Main Script and Macro. User-created script files are loaded into the Main
Copyright 2010-2013 Schellenbach & Assoc., Inc.
AccuTerm 7 Automation 75
Script tab; recorded macros are loaded into the Macro tab.
To quickly locate a function or subroutine in the code pane of the script editor, select it from the Proc drop-down list. If you would like the Run command (or the Debug Step Into) to begin execution with the selected procedure, check the Run selected procedure check-box (normally Run begins execution with
Sub Main()
).
Creating a Script
Scripts are created by entering VBA statements into the script code window. Scripts usually begin with
Sub Main()
and end with
End Sub
. Enter any valid VBA statements between the
Sub Main()
and
End
Sub
statements.
You can create other subroutines and functions which are called by your
Main()
subroutine (or from function keys, popup menus, host commands, etc). Subroutines begin with the
Sub
keyword followed by the name of the subroutine. If the subroutine requires arguments, enclose them in parentheses. The last statement in a subroutine is
End Sub
.
Functions are similar to subroutines, and begin with the
Function
keyword, and end with the
End
Function
statement. Functions return a value; simply assign the return value to the function name within your function code.
Certain declarations must be placed before the
Main()
subroutine. Declare global variables (using the
Global
keyword), DLL functions (using
Declare Function
or
Declare Sub
), and user-defined data types (using
Begin Type
and
End Type
) before
Sub Main()
. Within a subroutine or function, declare any local variables using the
Private
,
Dim
or
Static
statement.
In addition to local references to subroutines and functions defined in your script, those subroutines and functions may also be called from outside of your script in three ways: First, they may be called by script commands sent by the host (see AccuTerm Programming). Second they may be called by script commands programmed into function keys (see
Keyboard Settings ). Third, they may be called by script
commands executed in response to custom menu and toolbar actions (see
Saving a Script File
After the script has been created or modified, save the script by clicking the
Save or File Save As from the Script Editor menu.
button or use File
Loading a Script File
To load a script file, click the button use select File Open from the Script Editor menu.
Loading and Running a Script File
To load and run a script file, use File Run from the Script Editor menu. Enter or browse for the name of the script file to run, and click the OK button. Note: execution always begins with
Sub Main()
.
Closing the Script Window
Select the File Close from the Script Editor menu to close the script window. If there are any unsaved changes to the current script, you will be prompted to save changes.
Copyright 2010-2013 Schellenbach & Assoc., Inc.
76 AccuTerm 7 Help
Instead of closing the Script Editor window, you can hide it by using Window Hide or activate the main AccuTerm window by using Window AccuTerm 7.
Printing a Script
Select File Print from the Script Editor menu to print the current script. Select File
Print Setup
to select the printer used to print the script.
Editing Scripts
The Script Editor Edit menu provides many editing functions such as Undo, Redo, Cut, Copy, Paste,
Delete, Select all, Indent, Outdent, Find and Replace. The font used in the script window may be changed by using Edit Font, and the dialog editor may be invoked by using Edit User Dialog.
See also:
Controlling AccuTerm with Scripts
Script Editor Reference
Script Language Reference
2.2.1
Running a Script
To run a script from the Script Editor, create a new script or load an existing script into the script window. Then use Run Start (resume) from the Script Editor menu or click the toolbar button or press the
F5
key (to single step the script, see
Debugging a Script .) To terminate the script, use Run
End from the menu or click the the menu or click the
toolbar button. To suspend execution, use Run
button on the toolbar. To resume execution, use Start
Pause from
(resume) or click the button.
Unless the Run selected procedure check-box is checked, script execution begins with
Sub Main()
.
Running a Script from the Command Line
To run a script from the command line, append the name of the script file to the target or command line
(click the AccuTerm icon with the right mouse button, then select Properties). When AccuTerm starts, it loads the script into a hidden script window, and executes its
Main
subroutine. You can use a command line script to open up a number of sessions, the log a user on, etc.
You can the file association for AccuTerm's script files (.atsc) to start AccuTerm from a script file (or a shortcut to a script file). This is essentially the same as running a script from the command line.
Running a Script from a Layout File
Copyright 2010-2013 Schellenbach & Assoc., Inc.
AccuTerm 7 Automation 77
You can run a script automatically when opening a layout file. To save a script with a layout file, open all sessions to be included in the layout file. Open the script window, then load the script you want to automatically run. Return to the main AccuTerm window, and select File Save Layout. When the layout file is opened next, the script file will be loaded and its
Sub Main()
will be executed. Note: when
opening a layout file, all sessions are opened before executing the script.
Running a Script from a Function Key
To run a script from a function key, simply program the function key (see
script statements enclosed in brackets
[ ]
. Multiple statements can be separated by a colon (
:
). A script stored in a function key can contain a maximum of 250 characters. If a more complex script is to be executed from a function key, create it as a separate script file and use the
function key to run the script file. For example:
[Chain "MyComplexScript.atsc"]
Running a Script from a Menu or Toolbar
Running a script from a menu item or toolbar button is similar to running a script from a function key. In the
Menu Designer , set the Action property of the menu or toolbar item to the desired script statements
enclosed in brackets
[ ]
.
Running a Script from the Host Computer
To run a script from the host system, send the private AccuTerm command:
ESC STX
P
script
CR
or
ESC STX
R
script
CR
See AccuTerm Programming for details.
2.2.2
Debugging a Script
The Script Editor menu and toolbar provide functions for executing, interrupting, resuming and single stepping a script, and for setting breakpoints and watch expressions.
Run
Start (resume) ( or
F5
) begins execution at
Sub Main
or resumes execution at the current statement. If the Run selected procedure box is checked, then the procedure in the Proc drop-down list is started instead of
Sub Main
.
Run
Pause ( or
CTRL+BREAK
) will interrupt execution and enter Break mode.
Debug
Step Into ( or
F8
) will execute the next statement and then enter Break mode. If the next statement calls into a subroutine or function, Step Into will Break in the called procedure.
Debug
Step Over ( or
SHIFT+F8
) is the same as Step Into except that when it reaches a call into a subroutine or function, it will not step into the called procedure. The procedure will run, and Break mode will be entered at the next statement in the current procedure.
Copyright 2010-2013 Schellenbach & Assoc., Inc.
78 AccuTerm 7 Help
Debug
Step Out ( or
CTRL+F8
) causes a called procedure to continue running and enter Break mode when the called procedure returns.
Debug
Toggle Breakpoint ( or
F9
) sets or clears a breakpoint at the current statement. Lines containing breakpoints are marked with a large dot in the left margin.
Debug
Add Watch adds a watch expression based on the variable or function at the cursor position.
Use Step Into to start the script before adding a Watch expression, otherwise a warning is displayed.
To remove a watch expression, click on the Watch tab, select the expression you want to delete, and press the
DELETE
key.
Debug
Quick Watch ( ) will show the value of a variable or expression in the Immediate window. Position the cursor on the desired expression, then use the menu or toolbar button to view the value.
2.2.3
Controlling AccuTerm with Scripts
From a script’s perspective, AccuTerm consists of a set of objects which can be manipulated. The main object,
, may be used to control the general settings of AccuTerm - those items which are set in the General Options or Files & Folders category of the Settings dialog box. The
object is the most useful object for controlling AccuTerm. Using the
Session
object, you can change any of the session Settings, communicate with the host system, manipulate the screen, etc. The
Object Reference describes the object structure used to control AccuTerm.
There are several built-in objects which can be referenced while executing scripts. These are the
AccuTerm
object, the
Sessions
collection, the
ActiveSession
object, and the
InitSession
object.
The
AccuTerm
object is the top-level application object, and is described in detail in the next topic.
collection
The
Sessions
collection is a collection
Session
objects. There is one
Session
object in the collection for each currently open session. The first session in the collection is
Sessions(0)
.
Sessions
is simply a shortcut for
AccuTerm.Sessions
.
The
Session o bject type is described in detail in the next topic.
ActiveSession
object
The
ActiveSession
object is an object of type
Session
, which refers to the currently active session. The currently active session is the session whose title bar is highlighted.
InitSession
object
The
InitSession
object is an object of type
Session
, which refers to the session which initiated execution of the current script. This may not be the same as
ActiveSession
, since script execution could be initiated from a non-active session under host program control.
Copyright 2010-2013 Schellenbach & Assoc., Inc.
AccuTerm 7 Automation 79
2.2.4
Script Language Extensions
Several new statements have been added to the VBA language used by AccuTerm. These extensions implement features which may be useful in AccuTerm scripts.
2.2.4.1
Extensions
2.2.4.1.1 AppActivate statement
Syntax:
AppActivate(
title$ )
Description:
Activates the application identified by
title$
. If no window exists with
title$
, the first window with a title that begins with
title$
is activated. If no window matches, an error occurs.
2.2.4.1.2 AppClose statement
Syntax:
AppClose
names$
Copyright 2010-2013 Schellenbach & Assoc., Inc.
80 AccuTerm 7 Help
Description:
Closes the named application. The
names$
parameter is a String containing the name of the application.
If the
names$
parameter is absent, then the
AppClose statement closes the active application.
2.2.4.1.3 AppFind function
Syntax:
AppFind(
name$ )
Description:
Returns a String containing the full name of the application matching the partial
name$
.
2.2.4.1.4 AppGetActive function
Syntax:
AppGetActive( )
Description:
Returns a String containing the name of the active application.
2.2.4.1.5 AppGetPosition statement
Syntax:
AppGetPosition
X, Y, width,
height
[
,
name$
]
Description:
Retrieves the position of the named application.
X, Y, width,
height
are integer variables into which the applications position and size are stored.
Name$
is the name of the application whose size is being retrieved. If
name$
is not specified, then the currently active application is assumed.
2.2.4.1.6 AppGetState function
Syntax:
AppGetState(
name$ )
Description:
Returns an Integer specifying the state of the top-level window.
2.2.4.1.7 AppHide statement
Syntax:
AppHide
name$
Description:
Hides the named application.
Copyright 2010-2013 Schellenbach & Assoc., Inc.
AccuTerm 7 Automation 81
2.2.4.1.8 AppList statement
Syntax:
AppList
AppNames$
()
Description:
Fills an array with the names of all open applications. The
AppNames$
parameter must specify either a zero- or one-dimensioned dynamic String array. The array will be redimensioned to match the number of open applications. After calling this function, you can use
LBound
and
UBound
to determine the new size of the array.
2.2.4.1.9 AppMaximize statement
Syntax:
AppMaximize
name$
Description:
Maximizes the named application.
2.2.4.1.10 AppMinimize statement
Syntax:
AppMinimize
name$
Description:
Minimizes the named application.
2.2.4.1.11 AppMove statement
Syntax:
AppMove
X,
Y
[
,
name$
]
Description:
Sets the upper left corner of the named application to a given location.
2.2.4.1.12 AppRestore statement
Syntax:
AppRestore
name$
Description:
Restores the named application.
2.2.4.1.13 AppSetState statement
Syntax:
AppSetState
newstate
[
,
name$
]
Description:
Maximizes, minimizes, or restores the named application, depending on the value of
newstate
. The application is maximized if
newstate
is 1, minimized if
newstate
is 2 and restored if
newstate
is 3.
Copyright 2010-2013 Schellenbach & Assoc., Inc.
82 AccuTerm 7 Help
2.2.4.1.14 AppShow statement
Syntax:
AppShow
name$
Description:
Shows the named application.
2.2.4.1.15 AppSize statement
Syntax:
AppSize
width,
height
[
,
name$
]
Description:
Sets the size of the named application.
2.2.4.1.16 Chain statement
Syntax:
Chain
filename
[
arguments
]
Chain
filename | macroname
[
arguments
]
Description:
This statement transfers control to the specified script file.
Filename
is a string expression, and may contain a complete path name. If
macroname
is present, it must be separated from
filename
by a vertical bar ( | ) and execution begins with subroutine
macroname
. Otherwise, execution begins with
Sub
Main()
in the new script file. Optional
arguments
may be appended to the filename string separated by a space character. The arguments may e retrieved in the chained-to script by using the
Command() function. Execution never returns to the calling script. Note: both
filename
and
macroname
and optional
arguments
are contained in a single string expression, such as:
Chain "C:\ATWIN\SCRIPTS\MYSCRIPT.SCR|FOO IMAGE XX.JPG"
2.2.4.1.17 Command() function
Syntax:
Command()
Data type: string
Description:
This function returns the command line. If the script was invoked from another script using the
Chain statement, the command line is taken from the
Chain
statement argument.
2.2.4.1.18 FileExists function
Syntax:
FileExists(
name$ )
Description:
Returns True if file exists, otherwise returns False.
Copyright 2010-2013 Schellenbach & Assoc., Inc.
AccuTerm 7 Automation 83
2.2.4.1.19 Item function
Syntax:
Item(
text$, first, last
[
,
delimiter$
]
)
Description:
Returns all the items between
first
and
last
within the specified formatted text list. Items are substrings of a delimited text string. Items, by default, are separated by commas and/or end-of-lines. This can be changed by specifying different delimiters in the
delimiter$
parameter.
2.2.4.1.20 ItemCount function
Syntax:
ItemCount(
text$
[
,
delimiter$
]
)
Description:
Returns an Integer containing the number of items in the specified delimited text. Items are substrings of a delimited text string. Items, by default, are separated by commas and/or end-of-lines. This can be changed by specifying different delimiters in the
delimiter$
parameter.
2.2.4.1.21 Line function
Syntax:
Line(
text$, first, last )
Description:
Returns a String containing a single line or a group of lines between
first
and
last
.
2.2.4.1.22 LineCount function
Syntax:
LineCount(
text$ )
Description:
Returns an Integer representing the number of lines in
text$
.
2.2.4.1.23 OpenFileName function
Syntax:
OpenFileName(
[
title$
[
,
extension$
]]
)
Description:
Displays a dialog box that prompts the user to select from a list of files, returning the full pathname of the file the user selects or a zero-length string if the user selects Cancel. If
title$
is specified, then it is used as the title of the dialog box, otherwise, “Open” is used. If
extension$
is specified, then it specifies a list of file types and extensions - type:ext[,ext][;type:ext[,ext]]… where type is a description of the type of file, and ext is the extension pattern. For example, to display “All Files” and “Documents”, the
extension$
argument might be:
"All files:*.*;Documents:*.txt,*.doc"
Copyright 2010-2013 Schellenbach & Assoc., Inc.
84 AccuTerm 7 Help
2.2.4.1.24 Pause statement
Syntax:
Pause
Seconds
Description:
This statement causes the script to pause for the specified number of seconds. While the script is paused, normal terminal functions are operational, including any file transfers in progress.
2.2.4.1.25 Random function
Syntax:
Random(
min , max)
Description:
Returns a Long value greater than or equal to
min
and less than or equal to
max
.
2.2.4.1.26 SaveFileName function
Syntax:
SaveFileName(
[
title$
[
,
extension$
]]
)
Description:
Displays a dialog box that prompts the user to select from a list of files, returning the full pathname of the file the user selects or a zero-length string if the user selects Cancel. If
title$
is specified, then it is used as the title of the dialog box, otherwise, “Save As” is used. If
extension$
is specified, then it specifies a list of file types (see
2.2.4.1.27 Shell function
Syntax:
Shell(
command$
, [
WindowType
]
)
Description:
Executes a Windows or DOS command. If
command
specifies a file or URL, the file or URL is opened using the default application defined for that file. The return value is non-zero if the function succeeds.
The
WindowType
argument is optional and specifies the window state of the executed program:
0=hidden, 1=normal, 2=minimized (default), 3=maximized, 4=normal but not activated, 6=minimized but not activated.
2.2.4.1.28 Sleep statement
Syntax:
Sleep
millieconds
Description:
This statement causes the script to pause for the specified number of milliseconds. While the script is paused, normal terminal functions are operational, including any file transfers in progress.
Copyright 2010-2013 Schellenbach & Assoc., Inc.
Descargar
Anuncio