Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
DECLARE Statement (Non-Basic Procedures) Details
◄Summary► ◄Details► ◄Example► ◄Contents► ◄Index► ◄Back►
──────────────────────────────────────────────────────────────────────────────
DECLARE FUNCTION name [CDECL] [ALIAS "aliasname"] [([parameterlist])]
DECLARE SUB name [CDECL] [ALIAS "aliasname"] [([parameterlist])]
Usage Notes
■ The CDECL passes the arguments from right to left, rather than using the
Visual Basic convention of left to right.
■ CDECL also affects the name used in searches of object files and
libraries:
• If there is no ALIAS clause in the DECLARE statement, the type-
declaration character is removed from the name of the procedure, and
an underscore is added to the beginning. This becomes the name used
when searching libraries and external files.
• If CDECL is used with ALIAS, aliasname is used as is.
■ BYVAL can be used only with INTEGER, LONG, SINGLE, DOUBLE, and CURRENCY
types. When BYVAL appears in front of a parameter, the actual argument
is converted to the type indicated in the DECLARE statement before being
passed. The additional data types, FORM and CONTROL, can only be used
when a form or control is passed as an argument to a SUB or FUNCTION
procedure.
■ If the variable is an array, it can be followed by the number of
dimensions in parentheses to maintain compatibility with earlier
versions of Microsoft Basic. For example:
DECLARE SUB EigenValue (A(2) AS DOUBLE)
■ You also can indicate the variable type for parameterlist by either:
• Including an explicit type-declaration character (%, &, !, @, #, or
$) in the variable name
• Relying on the default type
■ When declaring external procedures written in other languages, you can
use the ANY keyword in the AS clause. ANY overrides type checking for
that argument. You cannot use ANY with arguments passed by value.
■ When neither BYVAL nor SEG is used, arguments are passed as near
addresses (offsets).
■ This form of the DECLARE statement allows you to refer to procedures
written in other languages.
■ The DECLARE statement causes the compiler to check the number and type
of arguments used to invoke the procedure.
■ A DECLARE statement can appear only in module-level code and affects
the entire source file.
■ The form of parameterlist determines whether or not argument type
checking is done, as described in the following declarations:
Example Description
═══════════════════════════════════ ══════════════════════════════════
DECLARE SUB First CDECL No argument checking is done when
there is no parameter list.
DECLARE SUB First CDECL ( ) First has no parameters. Arguments
in a call to First generate an
error; empty parentheses indicate
that SUB or FUNCTION has no
parameters and that argument
checking should be done.
DECLARE SUB First CDECL (X AS LONG) First takes one long integer
argument. When an argument list
appears, the number and type of the
arguments are checked in each
invocation.
■ A procedure that appears in a DECLARE statement can be invoked without
the CALL keyword.
■ You cannot have fixed-length strings in DECLARE statements because only
variable-length strings can be passed to SUB and FUNCTION procedures.
Fixed-length strings can appear in an argument list but are converted
to variable-length strings before being passed.
■ Be careful when using the SEG keyword, because Visual Basic may move
variables in memory before the called routine begins execution. Anything
in a CALL statement's argument list that causes memory movement may
create problems. You can safely pass variables using SEG if the CALL
statement's argument list contains only simple variables or arithmetic
expressions.
■ You cannot pass arrays using the SEG keyword.