Tera Term Macro has limited support for writing reusable code. It is possibleto
include
a file but it is not possible to use a goto
or call
command to easily jump to a specific block of code in a file.Tera Term Serial Macro Example In Excel. 3/7/2017 0 Comments. Remember that the VBA in Excel is rather an interpreter than a compiler.
subroutine.ttl emulates a function call syntax and allows you to write moremodular, compartmentalized code. For example, given two files (main.ttl andutil.ttl), you could write something like this in main.ttl:
This will call the
clear_system_logs
subroutine in util.ttl:subroutine.ttl requires Tera Term version 4.66 or higher. It is licensed underthe terms of the MIT license.See LICENSE.txt for the full text of the license.
You will need to copy subroutine.ttl into your source code directory and copythe following code to the top of each of your modular .ttl files:
Then, back in main.ttl, set the
callsub
variable. You can use one of thefollowing formats:<include file>:<goto label>
<include file>
If the goto label is not specified, the hook code above will call the defaultsubroutine. For readability, you can also leave the '.ttl' extension off ofthe filename.
Second, include subroutine.ttl in your main file.
As much as possible, subroutine.ttl attempts to avoid throwing errors. To avoiderrors, it attempts to detect errors before they happen and will return anerror code in the
result
variable. It also defines several constants thatyou can use for more readable error checking. For instance:Here is the complete list of error code constants and their meanings:
Constant name | Meaning |
---|---|
CALLSUB_IS_NOT_DEFINED | The callsub variable has not been set. |
CALLSUB_IS_NOT_A_STRING | The callsub variable is not a string. |
CALLSUB_IS_EMPTY | The callsub variable is an empty string. |
GOTO_LABEL_NOT_DEFINED | The specified goto label is not valid. |
INCLUDE_DEPTH_EXCEEDED | The maximum include depth (9) has been exceeded. |
INCLUDE_FILE_NOT_FOUND | The specified file does not exist. |
Tera Term is designed so that everything is in a global namespace. Because ofthis, it's possible to treat subroutines like functions. For instance, you candefine argument variables before calling a subroutine and check returnvariables defined in the subroutines. For instance:
It's also possible to modify subroutine.ttl to automatically add a directoryprefix to all of the filenames by changing the
__include_filename
variable.For instance, if you have a directory structure like this:You can change the
__include_filename
variable from '
to'includes'
: