CALL: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
Tag: Reverted
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 5: Line 5:
: [[CALL]] {{Parameter|ProcedureName}} ({{Parameter|parameter1}}, {{Parameter|parameter2}},...)]
: [[CALL]] {{Parameter|ProcedureName}} ({{Parameter|parameter1}}, {{Parameter|parameter2}},...)]


===Alternative syntax===
=== Alternative syntax ===
: {{Parameter|ProcedureName}} {{Parameter|parameter1}}, {{Parameter|parameter2}},...]
: {{Parameter|ProcedureName}} {{Parameter|parameter1}}, {{Parameter|parameter2}},...]




{{PageDescription}}
* CALL requires [[SUB]] program parameters to be enclosed in brackets (parenthesis).
* CALL requires [[SUB]] program parameters to be enclosed in brackets (parenthesis).
* CALL is not required to call a subprocedure. Use the SUB-procedure name and list any parameters without parenthesis.
* CALL is not required to call a subprocedure. Use the SUB-procedure name and list any parameters without parenthesis.
Line 14: Line 15:
* To pass parameters by value, instead of by reference, enclose passed variables in parenthesis.
* To pass parameters by value, instead of by reference, enclose passed variables in parenthesis.


 
=== QBasic/QuickBASIC ===
==QBasic/QuickBASIC==
* PDS or QuickBASIC 7 up could use [[BYVAL]] to pass variables by values instead of reference.
* PDS or Quickbasic 7 up could use [[BYVAL]] to pass variables by values instead of reference.
* QuickBASIC 4.5 could use [[BYVAL]] only for procedures created in Assembly or another language.
* QuickBASIC 4.5 could use [[BYVAL]] only for procedures created in Assembly or another language.
* QBasic required [[CALL ABSOLUTE]] only. It did not have to be DECLAREd.
* QBasic required [[CALL ABSOLUTE]] only. It did not have to be DECLAREd.

Latest revision as of 23:10, 2 February 2023

CALL sends code execution to a subroutine procedure in a program. In QB64 the subroutine doesn't need to be declared.


Syntax

CALL ProcedureName (parameter1, parameter2,...)]

Alternative syntax

ProcedureName parameter1, parameter2,...]


Description

  • CALL requires SUB program parameters to be enclosed in brackets (parenthesis).
  • CALL is not required to call a subprocedure. Use the SUB-procedure name and list any parameters without parenthesis.
  • Neither syntax can be used to call GOSUB linelabel sub procedures.
  • To pass parameters by value, instead of by reference, enclose passed variables in parenthesis.

QBasic/QuickBASIC

  • PDS or QuickBASIC 7 up could use BYVAL to pass variables by values instead of reference.
  • QuickBASIC 4.5 could use BYVAL only for procedures created in Assembly or another language.
  • QBasic required CALL ABSOLUTE only. It did not have to be DECLAREd.


Examples

Example: How parameters are passed in two SUB calls, one with CALL using brackets and one without CALL or brackets:

DIM a AS INTEGER 'value not shared with SUB
DIM SHARED b AS INTEGER 'value shared with any SUB
a = 1
b = 2
c = 3

CALL helloworld (a) 'a passed to c parameter with CALL
helloworld a        'a passed to c parameter w/o CALL

END

SUB helloworld (c) 'SUB parameter variables are always inside of brackets in SUB code
PRINT "Hello World!"
PRINT a,  b, c
a = a + 1 'a is a SUB value of 0 when printed which may increase inside SUB only
b = b + 1 'b is a shared value which can increase anywhere
c = c + 1 'c is a SUB parameter value from a in calls which may increase inside SUB only
END SUB

Returns:

Hello World!
 0            2            1
Hello World!
 0            3            1
Explanation: Variable a that is outside of the subroutine isn't SHARED so it will have no effect inside the subroutine, the variable a inside the subroutine is only valid inside the subroutine, and whatever value a has outside of it makes no difference within the subroutine.
The variable b on the other hand is SHARED with the subroutines and thus can be changed in the subroutine. The variable a is initiated with 0 as default when created, thus it will return 0 since it wasn't changed within the subroutine.
The variable c is the SUB parameter variable that passes values into the sub. Its value could be changed by the passed parameter value or inside of the subroutine. The un-shared c variable value outside of the sub is irrelevant within the subroutine.


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link