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:

<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:

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:

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:

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:

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