[an error occurred while processing this directive]

HP OpenVMS Systems

BASIC Translator
Content starts here

Compaq BASIC Translator
User Manual


Previous Contents Index

2.5 Hints for Translating and Running Applications

The following list provides hints for optimizing the translation process:

  • The Translator may produce a large number of informational and warning messages that tend to obscure more serious error messages. To suppress informational and warning messages, use the /NOWARNINGS qualifier.
  • DEF definitions within routines are translated to regular functions. These definitions must be pulled outside the routines in which they are defined.
  • OPTION TYPE=EXPLICIT statements within routines are translated to Option Explicit. These statements must be pulled outside the routines.
  • When transferring your translated project files from OpenVMS to Windows, depending on your networking and file transfer software, you may find that files that do not follow the old "eight-dot-three" file naming convention (maximum eight characters in the file name and three in the file type) are invisible from the Windows side or are not copied at all. You may or may not be prompted to rename such files. All the Translator support modules, classes, forms, and other files have short names to avoid this problem. However, the file specification for your translated module or its associated global definition file, as well as any generated MAP or RECORD class files, might very well exceed the "eight-dot-three" convention. If this is a problem for your particular setup, you have to rename the files prior to copying, and then rename them back to their original names after copying them to the Windows system. The .VBP project file expects the files to have their original names when loading the project in Visual Basic. See Suggested Use of /OUTPUT for File Naming and Section 2.2.3 for more information.
  • If you do not specify a path for files manipulated by your application, they might not be located in the project directory. One possible location is


    C:\Program Files\Microsoft Visual Basic
    
  • After a translated program completes execution, the terminal form remains on the screen until you close it by clicking on the close button in the upper right corner.
<recto_head>(cancel_h) <verso_head>(cancel_h)


Chapter 3
Program Concepts and Elements

This chapter describes how the Translator handles certain program concepts and elements or building blocks of BASIC.

3.1 Translator Directives

Translator directives are instructions that cause the Translator to perform certain operations as it converts the VAX BASIC or DEC BASIC source program to Visual Basic source code. Translator directives generally correspond to VAX BASIC or DEC BASIC lexical directives. Table 3-1 represents all the lexical directives that VAX BASIC or DEC BASIC supports and the corresponding level of support that the Translator provides.

Table 3-1 Lexical Directives and Support Levels
Lexical Directive Level of Support in Translator
%ABORT Same level of support as VAX BASIC or DEC BASIC.
%CROSS, %NOCROSS Not supported.

Error message: %DB2VB-W-LEXDIRECUNSUP, lexical directive is unsupported.

%DECLARED Same level of support as VAX BASIC or DEC BASIC.
%DEFINE Same level of support as VAX BASIC or DEC BASIC.
%IDENT Same level of support as VAX BASIC or DEC BASIC.
%IF-%THEN-%ELSE-%END %IF Same level of support as VAX BASIC or DEC BASIC.
%INCLUDE Same level of support as VAX BASIC or DEC BASIC.
%INCLUDE-%FROM %CDD Not supported.

Error message: %DB2VB-W-LEXDIRECUNSUP, lexical directive is unsupported.

%INCLUDE-%FROM %LIBRARY Same level of support as VAX BASIC or DEC BASIC.
%LET Same level of support as VAX BASIC or DEC BASIC.
%LIST, %NOLIST Same level of support as VAX BASIC or DEC BASIC.
%PAGE 1 Same level of support as VAX BASIC or DEC BASIC.
%PRINT Same level of support as VAX BASIC or DEC BASIC.
%REPORT %DEPENDENCY Not supported.

Error message: %DB2VB-W-LEXDIRECUNSUP, lexical directive is unsupported.

%SBTTL Same level of support as VAX BASIC or DEC BASIC.
%TITLE 1 Same level of support as VAX BASIC or DEC BASIC.
%UNDEFINE Same level of support as VAX BASIC or DEC BASIC.
%VARIANT Same level of support as VAX BASIC or DEC BASIC.

1In the Translator, these behave in the same manner as DEC BASIC. The VAX BASIC behavior is slightly different.

3.2 Continuation of Long Program Statements

When a VAX BASIC or DEC BASIC program line is too long for one line of text and is continued using an ampersand (&), the Translator converts the ampersand character to an underscore (_), which is the corresponding continuation character in Visual Basic.

Visual Basic limits the number of continuation lines. The limit varies with the version of Visual Basic, as follows:

  • Version 4.0---9 continuations (10 lines total)
  • Version 5.0---24 continuations (25 lines total)
  • Version 6.0---24 continuations (25 lines total)

VAX BASIC and DEC BASIC allow an unlimited number of continuation lines. Numerous continuation lines are typically found, for example, in long declarations. You should break these up into multiple shorter declarations either before translation or before running the translated program. For example, you could fix some variable declarations as follows in the Visual Basic code:


DEC or VAX BASIC:

DECLARE INTEGER Height, Width, Depth, Distance, Delta_Time, &
    Current_Time, Alarm_Time, Expiration_Time, &
    Day_Start, Day_End

Visual Basic:

Dim Height As Integer, Width As Integer, Depth As Integer
Dim Distance As Integer, Delta_Time As Integer
Dim Current_Time As Integer, Alarm_Time As Integer
Dim Expiration_Time As Integer, Day_Start As Integer
Dim Day_End As Integer

Continuation lines are also found commonly in complex conditional lines of code. These can be fairly simply fixed by deleting the continuation characters, resulting in long lines of code. Visual Basic has a limit of 1,024 characters per line. (The DEC BASIC line limit is 255 characters. Hence this alteration should be made in the Visual Basic output rather than in the source code.) Within the Visual Basic limit of 24 continuation lines (for Versions 5.0 and 6.0) and the Visual Basic limit of 1,024 characters per line, assuming an average length of 80 characters per line in the source code, it would be possible to fit about a 320-line statement without recoding---a very unusual situation.

Extremely long lines lose readability and are difficult to work with. Probably code of great length and complexity should be rewritten, in any case.

Continuation lines are often found in long program comments. Here too the Visual Basic limit applies. In this case the lines may be rewritten with the apostrophe (') comment character at the beginning of each line and the continuation characters omitted. Comments in general are discussed in Section 3.3.

3.3 Program Documentation

In both VAX BASIC or DEC BASIC and Visual Basic, program documentation can appear in either of the following two forms:

  • Comment fields (including empty statements)
    Text within a comment field is nonexecutable.
  • REM statements, also nonexecutable

In VAX BASIC or DEC BASIC, a comment field begins with an exclamation point (!) and ends with a carriage return, as follows:


! comment

The Translator changes the exclamation point to a single quotation mark or apostrophe ('), which is the Visual Basic syntax:


' comment

VAX BASIC and DEC BASIC also allow the following syntax to be embedded within a statement---which is not allowed by Visual Basic:


! comment !

The Translator moves any comment with this syntax to the end of the program line and converts the leading exclamation point (!) into a single quotation mark or apostrophe (').

VAX BASIC or DEC BASIC and Visual Basic also use the nonexecutable statement REM to convey comments. In VAX BASIC or DEC BASIC, a REM statement begins with the REM keyword and ends when a new line number is encountered. The text that you supply between the REM keyword and the next line number documents your program. Like comment fields, REM statements do not affect program execution. Therefore, the REM statement can be continued without the ampersand continuation character. REM should be the only statement on the line or the last of several statements in a multistatement line.

The following example shows the use of the REM statement in VAX BASIC or DEC BASIC:


10 REM This is a comment
   PRINT "This does not execute"
20 PRINT "This will execute"

Output


This will execute

Although Visual Basic has a Rem statement, it does not support the VAX BASIC or DEC BASIC multiline format; therefore, the Translator converts the example to the following:


10 REM This is a comment
   REM    PRINT "This does not execute"
20 DECBAS_PRINT 0,"This will execute",DECBAS_EOL

Output


This will execute

3.4 Statement Separators

If a VAX BASIC or DEC BASIC program line contains multiple statements and each statement is separated by a backslash (\), the Translator converts each backslash (\) to a colon (:), which is the corresponding separation character in Visual Basic.

3.5 Identifiers and Variable Names

In VAX BASIC or DEC BASIC, an identifier can have up to 31 characters. The name must begin with a letter. The remaining characters, if any, can be any combination of letters, digits, dollar signs ($), underscores (_), and periods (.).

Visual Basic does not allow either periods (.) or dollar signs ($) in identifiers (with the exception that the dollar sign can be the last character; see Table 3-2). The Translator changes periods and dollar signs in identifiers to underscores (_). A period is translated into three underscores, and a dollar sign is translated into two underscores. For example, DEC$BASIC is converted to DEC__BASIC . An informational message is given whenever either of these translations occur. For information about the /ID_CHARACTER and /ID_SUFFIX qualifiers, see Section 2.1.1.1.

Table 3-2 summarizes the rules for naming identifiers for VAX BASIC and DEC BASIC and for Visual Basic.

Table 3-2 Rules for Naming Identifiers
Attribute VAX BASIC and DEC BASIC Visual Basic
Maximum length (characters) 31 40
First character A to Z, a to z A to Z, a to z
Remaining characters A to Z, a to z A to Z, a to z
  0 to 9 0 to 9
  Underscore (_) Underscore (_)
  Period (.), dollar sign ($)  
Last character (optional) Percent sign (%), dollar sign ($) Percent sign (%), ampersand (&), exclamation point (!), pound sign (#), at sign (@), dollar sign ($)
Can be reserved word? No No
Case sensitive? No No

In VAX BASIC or DEC BASIC, you specify the data type of a variable in one of two ways. With implicit data typing, you specify the data type by a suffix on the variable name as follows:

  • A percent sign suffix (%) specifies the INTEGER data type.
  • A dollar sign suffix ($) specifies the STRING data type.
  • Any other ending character specifies a variable of the default data type.

Alternatively, you can create variables and allocate storage using one of the following declarative statements:

DECLARE
DIMENSION
COMMON
MAP

VAX BASIC or DEC BASIC treats X, X$, and X% as three distinct variables of differing data types with differing ranges and precision and differing amounts of storage allocated for the variables.

Visual Basic, however, treats all three as the same variable. How it treats them depends on which of the three it sees first. The one it sees first determines the data type and allocation of storage. After that, all such names are treated as synonyms and the suffix is ignored.

The following example illustrates this point:


C% = 3
C = "1.5"
PRINT C

Output


 2

Visual Basic treats C as the same variable as C%, which is an integer. It therefore rounds up 1.5 to 2 and prints 2.

The Translator attempts to preserve the original uniqueness of the variables by:

  • Preserving the suffix
    For example, X$ is converted to X_$ and X% is converted to X__%.
  • Preserving the original case
    The Translator preserves the case of the words in the input file where possible. In general, all user identifiers appear in the original case, whereas some language keywords appear in the original case and others, in particular, generated words that did not appear in the input file, will appear in uppercase.

3.6 Numeric Literals

Numeric constants represented in the usual way are translated without change.

Numeric constants represented using the following VAX BASIC or DEC BASIC format are translated as shown in Table 3-3 and Table 3-4:


[radix] "<num-str>" [datatype]

The radix is one of the values shown in Table 3-3.

Table 3-3 Radix Table
Radix Description Translation
D Decimal <num-str>
B Binary Unsupported
O Octal &O<num-str>
X Hex &H<num-str>
A ASCII Asc("<num-str>")

The data type is one of the values shown in Table 3-4.

Table 3-4 Data Type Translations
Data Type Description Translation
B Byte <num-str>
W Word <num-str>
L Long <num-str>
F Ffloat <num-str>
D Double <num-str>
G Gfloat <num-str>
H Hfloat Unsupported
P Decimal <num-str>
C Character Chr(<num-str>)

Consider the following examples in Table 3-5.

Table 3-5 Numeric Literal Translation Examples
VAX BASIC and DEC BASIC Visual Basic Translation
D"3"F 3
O"1"W &O1
A"0"B ASC("0")
X"3f2D" &H3f2D
"9.9"G 9.9
X"23"C CHR(&H23)

3.7 String Literals

In VAX BASIC or DEC BASIC, pairs of either double quotation marks (" ") or single quotation marks (' ') are the quoting characters for string constants; therefore, it is easy to include either double or single quotation marks in a string by using the other form as the quoting character.

Visual Basic allows only double quotation marks as the quoting character, but the double quotation mark character can be included in a string by doubling it.

The following illustrates how typical string constants are translated:

'xx"xx' translates to "xx""xx"
"xx'xx" translates to "xx'xx" -- unchanged

Exercise caution because the single quotation mark character is used in Visual Basic as a comment character and the exclamation point (!) character is used as a comment character in VAX BASIC or DEC BASIC.

VAX BASIC and DEC BASIC support a number of predefined string constants. Table 3-6 summarizes these predefined constants and their translations.

Table 3-6 Predefined String Constants
Constant VAX BASIC and DEC BASIC Visual Basic
Back Space BS BS
Bell BEL CHR(7)
Carriage Return CR CR
Delete DEL CHR(127)
Escape ESC CHR(27)
Form Feed FF FF
Horizontal Tab HT HT
Line Feed LF LF
Shift In SI CHR(15)
Shift Out SO CHR(14)
Space SP CHR(32)
Vertical Tab VT VT

Note that VAX BASIC and DEC BASIC also support the predefined constant PI for representing the ratio of a circle's diameter to its circumference. PI translates to 3.14159265358973238462643383279502.


Previous Next Contents Index