Compaq BASIC Translator
User Manual


Previous Contents Index


COMMON

The VAX BASIC or DEC BASIC COMMON statement defines a named, shared storage area called a COMMON block or program section (PSECT). VAX BASIC or DEC BASIC program modules can access the values stored in the COMMON block by specifying a COMMON block with the same name.

Translated Equivalent

Visual Basic Class


Remarks

As of Version 1.2 of the Translator, a COMMON declaration in the VAX BASIC or DEC BASIC program is translated to a Visual Basic class. The class simulates the storage of the variables in a PSECT that is shared among the program modules. (In versions prior to Version 1.2, a COMMON was translated to a Visual Basic Public statement.) For detailed information about the COMMON statement, refer to Section 4.2.6.


COMP%

The VAX BASIC or DEC BASIC COMP% function compares two numeric strings and returns --1, 0, or 1, depending on the results of the comparison.

Translated Equivalent

DECBAS_COMP%


Example

VAX BASIC or DEC BASIC Input


I = COMP% (SS, "24.5") 

Translator Output


I=DECBAS_COMP%(SS,"24.5") 


CONTINUE

The VAX BASIC or DEC BASIC CONTINUE statement causes the compiler to clear an error condition and resume execution at the statement following the statement that caused the error or at the specified target.

Translated Equivalent

Resume <label>

or Resume Next


Remarks

In VAX BASIC or DEC BASIC, a context for the CONTINUE statement is provided by WHEN blocks. Visual Basic does not support WHEN blocks; however, a context is provided by the translation of the VAX BASIC or DEC BASIC WHEN statement to the Visual Basic On Error GoTo statement.

The VAX BASIC or DEC BASIC CONTINUE statement provides for an optional specified target that must be a label or a line number. If a label is supplied, the Translator converts the CONTINUE label to Resume label. Visual Basic does not support line numbers.

The OpenVMS and Visual Basic error handling schemes differ in many subtle ways. It is important that you check and test each usage. For more information on exception handling, see Chapter 6.


Example

VAX BASIC or DEC BASIC Input


WHEN ERROR IN 
    X = Y/0 
L1: 
    X = 0 
USE 
    IF ERR = 50 
    THEN 
        CONTINUE L1 
    END IF 
END WHEN 

Translator Output


ON ERROR GOTO DECBAS_000001 
    X=Y/0 
L1: 
    X=0 
GOTO DECBAS_000002 
DECBAS_000001: 
    IF DECBAS_ERR=50 THEN 
        RESUME L1 
    END IF 
RESUME NEXT 
DECBAS_000002: 


COS

The VAX BASIC or DEC BASIC COS function returns the cosine of an angle in radians or degrees.

Translated Equivalent

Cos


Remarks

The process of translation to the Visual Basic Cos function raises floating-point differences. For more information, see Chapter 4.

Only values in radians are supported by Visual Basic.


Example

VAX BASIC or DEC BASIC Input


XX = COS (.5) 

Translator Output


XX=COS(.5) 


CTRLC

The VAX BASIC or DEC BASIC CTRLC function enables Ctrl/C trapping. When Ctrl/C trapping is enabled, Ctrl/C entered at the terminal causes control to be transferred to the error handler currently in effect.

Translated Equivalent

DECBAS_CTRLC


Remarks

For more information on I/O issues, see Chapter 5.


Example

VAX BASIC or DEC BASIC Input


Y% = CTRLC 

Translator Output


Y__%=DECBAS_CTRLC() 


CVT$$/CVTxx

The VAX BASIC or DEC BASIC CVT$$ function is a synonym for the VAX BASIC or DEC BASIC EDIT$ function, which performs one or more string editing functions, depending on the value of its integer arguments. Compaq recommends that you use the EDIT$ function rather than the CVT$$ function for new program development. See the EDIT$ function for more information.

The VAX BASIC or DEC BASIC CVT... conversion functions have the following functions:

Note

VAX BASIC or DEC BASIC CVT functions are supported only for compatibility with BASIC-PLUS. Compaq recommends that you use the dynamic mapping feature or multiple VAX BASIC or DEC BASIC MAP statements for new program development.

Translated Equivalent

DECBAS_EDIT$

DECBAS_CVTSP

DECBAS_CVTSF

DECBAS_CVTPS

DECBAS_CVTFS


Remarks

VAX BASIC or DEC BASIC CVT functions reverse the order of the bytes when moving them to or from a string. Therefore, you can mix MAP and MOVE statements, but you cannot use FIELD and CVT functions on a file if you also plan to use MAP or MOVE statements.

Note the following information about each of the CVT support routines:


Example

The following example illustrates that because CVT$F and CVTF$ are mirror functions, the same result (1.23456) is produced in either case.

VAX BASIC or DEC BASIC Input


SS = CVT$$ (SS, 32+2) 
SS = CVT%$ (I) 
I = CVT$% (SS) 
XX = CVT$F (CVTF$ (1.23456)) 

Translator Output


SS=DECBAS_EDIT$(SS,32+2) 
SS=DECBAS_CVTPS(I) 
I=DECBAS_CVTSP(SS) 
XX=DECBAS_CVTSF(DECBAS_CVTFS(1.23456)) 


DATA

The VAX BASIC or DEC BASIC DATA statement creates a data block for the VAX BASIC or DEC BASIC READ statement.

Translated Equivalent

No exact translated equivalent


Remarks

Although there is no simple, exact equivalent for the VAX BASIC or DEC BASIC DATA statement, the Translator provides a way to convert programs that contain DATA (and READ) statements. A subroutine is created and called at the beginning of your program to initialize the data array DECBAS_DATA to the set of values specified. See the Example section.


Example

VAX BASIC or DEC BASIC Input


SUB RD 
DATA ABC,DEF,GHI 
READ X, Y, Z 
END SUB 

Translator Output


SUB RD 
DIM DECBAS_DATA() 
DIM DECBAS_DATA_INDEX AS INTEGER 
DECBAS_DATA_INDEX = 0 
DECBAS_DATA_RD  DECBAS_DATA 
DECBAS_READ DECBAS_DATA,DECBAS_DATA_INDEX, X,Y,Z 
END SUB 
SUB DECBAS_DATA_RD( ByRef DECBAS_DATA ) 
REDIM DECBAS_DATA(3) 
DECBAS_DATA(0) = "ABC" 
DECBAS_DATA(1) = "DEF" 
DECBAS_DATA(2) = "GHI" 
END SUB 


DATE$

The VAX BASIC or DEC BASIC DATE$ function returns a string containing a day, month, and year in the form dd-mmm-yy.

Translated Equivalent

DECBAS_DATE$


Example

VAX BASIC or DEC BASIC Input


SS = DATE$ (28123) 

Translator Output


SS=DECBAS_DATE$(28123) 


DATE4$

The VAX BASIC or DEC BASIC DATE4$ function returns a string containing a day, month, and year in the form dd-mmm-yyyy.

Translated Equivalent

DECBAS_DATE4$


Remarks

The DATE4$ function is not available in DEC BASIC Version 1.2 and earlier, nor in VAX BASIC Version 3.7 and earlier.


Example

VAX BASIC or DEC BASIC Input


SS = DATE4$ (28123) 

Translator Output


SS=DECBAS_DATE4$(28123) 


DECIMAL

The VAX BASIC or DEC BASIC DECIMAL function converts a numeric expression or numeric string to the DECIMAL data type.

Translated Equivalent

Variant with subtype Decimal


Remarks

In Visual Basic Version 4.0, there is no data type that corresponds to the VAX BASIC or DEC BASIC DECIMAL data type. Visual Basic Version 4.0 will flag the CDec function, which the Translator uses to perform the conversion, as an error. For more information, see Chapter 4.

In Visual Basic Version 5.0 or 6.0, the DECIMAL data type is implemented as a Variant with the subtype Decimal. This differs from the VAX BASIC or DEC BASIC implementation in the following ways:

The Translator converts a DECIMAL entity to a Variant and then uses the CDec function to set the subtype to Decimal. The following sections describe how DECIMAL is converted for the following:

Simple Variable
Array
Constant
Element in COMMON
Element in MAP
Element in RECORD
DECIMAL Function

Simple Variable

The Translator converts a simple variable declaration to a Variant declaration, followed by an assignment using the CDec function to set the subtype to Decimal.

Example

VAX BASIC or DEC BASIC Input


DECLARE DECIMAL A 
DECLARE DECIMAL A1, A2 
DECLARE DECIMAL(5,3) B 

Translator Output


DIM A:A =CDec(0) 
DIM A1:A1 =CDec(0) : DIM  A2:A2 =CDec(0) 
DIM B:B =CDec(0) 

Array

The Translator converts a DECIMAL array declaration to a Variant declaration, followed by a call on the routine DECBAS_DECIMAL_INIT, which sets the subtype to Decimal for all the elements of the array.

Note

DECBAS_DECIMAL_INIT only supports the initialization of arrays with up to three subscripts. An error message is generated for arrays with more than three subscripts and a zero value is generated for the DECBAS_DECIMAL_INIT parameter, so that a run-time error will also be generated.

Example

VAX BASIC or DEC BASIC Input


DECLARE DECIMAL(10,6) C1(2) 
DECLARE DECIMAL(10,6) C2(5,3) 
DECLARE DECIMAL(10,6) C3(3,4,2) 
DECLARE DECIMAL(10,6) C4(2,3,7,2) 

Translator Output


DIM C1(2):DECBAS_DECIMAL_INIT C1,1 
DIM C2(5,3):DECBAS_DECIMAL_INIT C2,2 
DIM C3(3,4,2):DECBAS_DECIMAL_INIT C3,3 
DIM C4(2,3,7,2):DECBAS_DECIMAL_INIT C4,0 

In the last line of this example, note the zero, which is generated because there are four subscripts (more than the maximum three). The zero value will cause a run-time error.

Constant

The Translator converts a DECIMAL constant declaration to a Variant declaration, followed by an assignment using the CDec function to set the subtype to Decimal. The Translator is not able to translate a DECIMAL constant to a Visual Basic Decimal constant because a conversion function cannot be used in the constant expression in Visual Basic. The Translator, therefore, converts the constant to a Decimal variable.

Example

VAX BASIC or DEC BASIC Input


DECLARE DECIMAL(5,3) CONSTANT  B2 = "12.3"P 

Translator Output


DIM B2 AS VARIANT: B2=CDec(12.3) 

DECIMAL Element in COMMON

The Translator converts a DECIMAL element in a COMMON declaration as a Variant in the globals file. The Translator generates assignments to the DECIMAL COMMON elements in the main program.

Example

VAX BASIC or DEC BASIC Input


COMMON (foreign_sales_rec) DECIMAL(4,2) D1, DECIMAL(5,3) D2 

Translator Output


Main Program: 
 
D1 =CDec(0):D2 =CDec(0) 
 
Globals File: 
 
PUBLIC D1 AS VARIANT,D2 AS VARIANT 

DECIMAL Element in MAP

The Translator treats a DECIMAL element in a MAP as a Variant that occupies 16 bytes. It reserves that amount of space in the map.

The Translator adds the CDec conversion function to the fetch and store routines in the accompanying class to get the Decimal subtype.

Example

VAX BASIC or DEC BASIC Input


MAP (BUF1) BYTE AGE, STRING EMP_NAME = 20,               & 
         DECIMAL(5,2) DEC_NUM, SINGLE EMP_NUM 

Translator Output


Main Program: 
 
    DIM BUF1 AS NEW BUF1DECIMALEXAMPLESMAINCLS 
    BUF1.DEC_NUM2 =CDec(0) 
 
Globals File: 
 
REM PUBLIC AGE AS BYTE,EMP_NAME AS STRING*20, _ 
       DEC_NUM AS VARIANT,EMP_NUM AS SINGLE 
Public BUF1_PSECT (41) As Byte 
 
Class File: 
 
Public Property Get DEC_NUM () As Variant 
    Dim Offset As Long 
    Offset = 21 
    Dim RtnValue As VARIANT 
    Call FldMoveAV (Base_Address + Offset, RtnValue, 16) 
    DEC_NUM =CDec( RtnValue) 
End Property 
 
Public Property Let DEC_NUM (NewValue As Variant) 
    Dim Offset As Long 
    Offset = 21 
    Dim RtnValue As VARIANT 
    RtnValue = CDec(NewValue) 
    Call FldMoveVA (RtnValue, Base_Address + Offset, 16) 
End Property 

DECIMAL Element in RECORD

The Translator treats a DECIMAL element in a RECORD as a Variant.

The Translator generates the CDec conversion function for each assignment to a Decimal record element.

Note that the Translator does not correctly handle decimal values in records associated with maps.

Example

VAX BASIC or DEC BASIC Input


RECORD MYRECTYPE 
    INTEGER ELEM1 
    STRING ELEM22V2 = 4 
    BYTE B1 
    DECIMAL(5,3) D1 
    REAL ELEM22V1   
END RECORD MYRECTYPE 
 
DECLARE MYRECTYPE AREC 
 
AREC::D1 = "12.34"P 

Translator Output


Main Program: 
 
DIM AREC AS MYRECTYPE 
AREC.D1=CDEC(12.34) 
 
Globals File: 
 
TYPE MYRECTYPE 
    ELEM1 AS LONG 
    ELEM22V2 AS STRING*4 
    B1 AS BYTE 
    D1 AS VARIANT 
    ELEM22V1 AS SINGLE 
END TYPE 

DECIMAL Function

The Translator converts the DECIMAL function to the Visual Basic CDec function.

Example

VAX BASIC or DEC BASIC Input


B = DECIMAL(NUM_VALUE,5,3) 

Translator Output


B=CDEC(NUM_VALUE) 


DECLARE

The VAX BASIC or DEC BASIC DECLARE statement explicitly assigns a name and a data type to a variable, an entire array, a function, or a constant.

Translated Equivalent

Variables
Dim decl-item As data-type

DEF Functions
Not Applicable

Named Constants
Const const-name As data-type = const-exp


Remarks

Unlike the VAX BASIC or DEC BASIC DECLARE statement, Visual Basic does not propagate the data type throughout the Dim statement. For this reason, the Translator must explicitly specify the data type for each item within the Dim.

There are a number of data representation differences between VAX BASIC or DEC BASIC on the OpenVMS platform and Visual Basic on the Windows NT platform. For a complete discussion of these differences, see Chapter 4.

Because of the nature of the Visual Basic development environment, Function and Sub statements defined within the same project do not need to be prototyped using a DECLARE statement.

Note that DEF statements are not supported in Visual Basic and are translated to Visual Basic Function statements. Declarations for translated DEF statements are not needed and not supported, and the Translator issues a message to this effect.


Example

VAX BASIC or DEC BASIC Input


DECLARE LONG MYVAR 
DECLARE LONG CONSTANT MYCONST = 42 

Translator Output


DIM MYVAR AS LONG 
PUBLIC CONST MYCONST AS LONG=42 


DEF

The VAX BASIC or DEC BASIC DEF statement lets you define a single line or multiline function.

Translated Equivalent

Function


Remarks

Visual Basic does not have DEF statements; they are translated to Visual Basic Function statements.

When translating programs containing DEF statements, review the documentation for the DEF statement in the DEC BASIC and VAX BASIC for OpenVMS Systems Reference Manual. There are several pages of description regarding the subtle differences between FUNCTION statements and DEF statements. Note that DEF statements are declared within programs, subroutines, or functions. The resulting Visual Basic code needs to be manually rearranged to move the resulting nested Function declaration out of the enclosing routine.


Example

VAX BASIC or DEC BASIC Input


DEF DOUBLE OVER (DOUBLE T, B) = T / B 

Translator Output


FUNCTION OVER(ByRef T AS DOUBLE,ByRef B AS DOUBLE)AS DOUBLE 
                              OVER=T/B 
END FUNCTION 


Previous Next Contents Index