BYVAL - QB64 Wiki

BYVAL

From QB64 Wiki

Revision as of 19:35, 27 January 2013 by Clippy (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The BYVAL statement is used to pass a numerical parameter's value with SUB programs made in other programming languages.


Syntax:

Procedure_Name (BYVAL variable1, BYVAL variable2)


Description:

  • QB64 supported with DECLARE LIBRARY SUB and FUNCTION procedure declarations when passing numerical values only.
  • Passing numerical values BYVAL assures that the original variable value is not changed by another procedure. Do not use with STRING or TYPE variables!
  • QB64 can use BYVAL in DECLARE LIBRARY procedures that add DLL or Operating System API functions.
  • Use parenthesis around SUB or FUNCTION parameters passed BY VALUE in Qbasic or QB64. Ex: CALL Procedure ((x&), (y&))
  • Qbasic versions below 7 do not use BYVAL unless the SUB program referred to is from a different programming language.
  • PDS versions can use BYVAL as it is intended in any SUB or FUNCTION parameters. BYVAL can also be used with ABSOLUTE in Qbasic but not in QB64.
  • NOTE: Many Qbasic keyword variable names CAN be used with a STRING suffix($) ONLY! You CANNOT use them without the suffix, use a numerical suffix or use DIM, REDIM, _DEFINE, BYVAL or TYPE variable AS statements!


Example: Passing parameters "by value" using brackets when calling a SUB or FUNCTION in Qbasic or QB64.

CALL MySUB (a%, (b%), (c%)) 'CALL SUB MySUB a%, b%, (c%) 'call SUB again without CALL PRINT "Outside procedure: "; a%, b%, c% SUB MySUB (a%, b%, c%) a% = a% + 1: b% = b% + 1: c% = c% + 1 PRINT "Inside procedure: "; a%, b%, c% END SUB

Inside procedure: 1 1 1 Inside procedure: 2 1 1 Outside procedure: 2 1 0

Explanation: Both SUB calls pass just the values of b% and c% to the procedure. The first variable, a%, is passed by reference (the default) so the value was changed by the SUB procedure. Brackets can only be used in the CALL or function reference!


See also:



Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page