Chapter 6 Managing Models


.convert_name & .convert_code macros

The .convert_name & .convert_code macros use a conversion table to get the corresponding code from a name or the corresponding name from a code.

The .convert_name macro uses the conversion table of a name into a code and the .convert_code macro uses the conversion table of a code into a name. When no occurrence is found in the table, the name or the code is returned.

You can use these macros together with a user-defined conversion table that you select in the Conversion Table dropdown listbox.

Conversion tables are not case sensitive. You can indifferently use lower-or-uppercases in tables.

For more information on conversion tables, see the "Using a conversion table" section.

Syntax

.convert_name (<Expression>[,<Separator Character>[,<Separator Pattern>],<code naming convention>])
.convert_code (<Expression>[,<Separator Character>[,<Separator Pattern>]])

Parameters

Parameter Description
<Expression> Name or code to be converted in the corresponding conversion table
<Separator Character> (optional) Character generated each time a separator declared in <Separator Pattern> is found in <Expression>. For example this character can be "_"
<Separator Pattern> (optional) Declaration of the different separators likely to exist in the <Expression>. These separators will be replaced by the <Separator Character>. You can declare several separators, for example "/-_"
<Code naming convention> <firstLowerWord>: First word in lowercase, then other first letters of other words in uppercase

<FirstUpperChar>: First character of all words in uppercase

<lower_case>: All words in lowercase and separated by an underscore

<UPPER_CASE>: All words in uppercase and separated by an underscore

Code naming conventions

If you use the code naming convention parameter with the convert_name macro, the conversion script will automatically convert names according to the selected parameter. This can be very useful when you need to adapt codes to a particular target, for example PowerBuilder naming conventions require object codes to be always in lowercase and separated by an underscore.

When you use a code naming convention parameter in the conversion script, the conversion table is no longer used and the name is systematically converted according to the pattern defined in the code naming convention parameter.

You can also define a code naming convention for all the instances of a selected metaclass using the resource editor, for more information on this feature, see section Adding a metaclass to a profile in chapter Managing Profiles in the Advanced User Documentation .

Example

You type the following script in the Name to Code page:

.convert_name(%Name%,"_","'-/'")

Note that both the <Separator Character> and the <Separator Pattern> must be defined into a double quoted string, furthermore you should add simple quotes around <Separator Pattern> to define the pattern syntax.

In this script, the separator patterns (- and /) are used to distinguish the different words in the name. The separator character ( _ ) will be used to separate the different characters of the name. So whenever a "-" or a "/" separator pattern is encountered, it will be replaced by the "_" separator character.

The script has to convert the name CLIENT-France/Address and uses the following conversion table:

Name Code
CLIENT CLI
France FR
Address ADDR

The resulting code is:

CLI_FR_ADDR

 


Copyright (C) 2005. Sybase Inc. All rights reserved.