Macro Language Reference > Macros > System > defstr
  
defstr
Description
Defines a new PTC ALD string, or copies the contents of one string into a new string.
 
Example 226. Define a dialog box with the ^wdb variable and macros
The example below shows a simple use of the ^wdb variable, along with condition macros, in a stripped down version of the script used in stuk.3ad to define the search/replace dialog box.
"ts", "320"
$defstr 349,"@/ @|Search / Replace\n"<>
$addstr 349,"--\n"<>
$addstr 349,"Search for:\n"<>
$addstr 349," ^_sr_s_str%1..40sn!?7,@\\\\%d\\\\!\n"<>
$addstr 349,"Replace with (blank for Search only):\n"<>
$addstr 349," ^_sr_r_str%0..40sn!?7,@\\\\%d\\\\!\n"<>
$addstr 349,"Options: ^_sr_o_str%0..20snx!348!\n"<>
$addstr 349,"--\n"<>
$addstr 349,"|Keep above settings: ^_sr_k_keep%0..1B[Yes]
[No]\n"<>
$addstr 349,"--\n"<>
$addstr 349,"|%2..1e [OK] [Cancel]"<>
$defstr 348,"Search/Replace Options:\n"<>
$addstr 348," t -- start from Top|@t\n"<>
. . . .
$addstr 348," num repeat num times\n"<>
#if REGEXPS
$addstr 348,"Standard search:\n"<>
#endif
$addstr 348," ? -- wildcard ? on|@?\n"<>
$addstr 348," [ -- search/insert|@[\n"<>
$addstr 348," ] -- search/append|@]\n"<>
#if REGEXPS
$addstr 348,"Regular expressions:\n"<>
$addstr 348," r -- normal|@r\n"<>
$addstr 348," x -- eXtended . matching|@x\n"<>
#endif
$wdb 349<>
$^wdb----<>
$?0^wdb trun 0<>
$^blank=<>
$?=^_sr_r_str,^blank /^_sr_s_str/^_sr_o_str^<>
$?+^_sr_r_str,^blank /^_sr_s_str/^_sr_r_str/^_sr_o_str^<>
 
Example 227. Define a string depending on a getvar value
The simple example below uses getvar to determine the current operating mode and, depending on the value of that test, defines string no.390 with a macro that could appropriately be assigned to the keystroke +.
"ts", "389"
$getvar 01505 "Mode"<>
$defstr 390,""<>
$?=^Mode addstr 390,"tdpctrl\n" }end<>
$^Mode- -<>
$?=^Mode addstr 390,"tfbgc\n" }end<>
$^Mode- -<>
$?=^Mode addstr 390,"tic\n" }end<>
$^Mode- -<>
$?=^Mode addstr 390,"tgfcol\n" }end<>
$:end<>
$trun 390<>
"ts", "389": String header. (In this illustration the script is shown as if it was set in an suser.3ad file).
$getvar 01505 "Mode"<>: Use getvar to obtain a numeric code, from 0..3, for the current operating mode.
$defstr 390,""<>: Define an empty string no.390.
$?=^Mode addstr 390,"tdpctrl\n" }end<>: If the ^Mode variable has a value of 0, then assign macro to be accessed from Document Mode, and jump to the label on line 11.
$^Mode- -<>: Decrease the value of the ^Mode variable by 1. If getvar had returned a value of 1, the new value will be 0, allowing the next line to be run, and so on. Decreasing the value of a variable in this way is efficient and allows simpler tests than for a specific value.
$trun 390<>: Run the script that has just been defined.
Syntax
defstr string:s first_line:s exact:n?
defstr string:s old_string:s
string
The number of the new string: there are certain string numbers available to users please refer to the stuk.3ad file for these numbers.
first_line
The characters to be included in the first line of the string, if any.
exact
Ø|0
Process characters in first_line: for example, \n is converted to a new line, \\ is a single backslash.
1
Do not process characters in first_line: for example, leave a file path that contains backslashes exactly as it appears.
string
The name of the string whose contents are to be replaced by the contents of old_string
old_string
The name of the string whose contents are to be copied into string.
Additional Information
The PTC ALD strings file, stuk.3ad on normal UK systems, contains all of PTC ALD language-dependent strings and other user configurable strings. These strings define, for example, PTC ALD menus and dialog boxes. By using defstr and addstr to define your own strings, you can either overwrite existing strings or define new strings, usually in order to describe menus and dialog boxes from within a script.
Each string is identified by a number. Certain ranges of numbers have been allocated and you as a user will normally be interested in the range 350..399 (refer to the last section of stuk.3ad for additional user definable string numbers). You can define your own new strings within this range without any danger of clashing with current or future versions of PTC ALD
If you have used a user strings file (usually suser.3ad) to create new strings within the range 350. . .399 you must take care not to overwrite them from scripts within your documents. We suggest that string numbers are used as follows to avoid confusion:
350 - 379: scripts in a user file
380 - 389: scripts internal to a document
390 - 399: 'temporary' user strings, i.e. those defined within a particular script which can be overwritten by other scripts run on different occasions.
To check if a string is already being used use getvar with a code of 31nnn, where nnn is the string number. This will pass up to 80 characters from a string into a variable. If the string is empty the variable returned will be emptied of any contents that it had before getvar was run.
Related Links