CALL/de

(Difference between revisions)
Jump to: navigation, search
(Remarks)
(Remarks)
Line 43: Line 43:
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
Mann kann Subroutinen mit oder ohne Parameterübergabe aufrufen.
+
Man kann Subroutinen mit oder ohne Parameterübergabe aufrufen.
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
Line 69: Line 69:
 
Der CALL-Befehl ermöglicht es, eigene Befehle zu definieren.
 
Der CALL-Befehl ermöglicht es, eigene Befehle zu definieren.
  
MAn muss CALL nicht explizit schreiben:
+
Man muss CALL nicht explizit schreiben:
  
 
Test2 ruft ebenfalls die Subroutine test2 auf.
 
Test2 ruft ebenfalls die Subroutine test2 auf.

Revision as of 00:33, 13 March 2013

Contents

Funktion

Ruft eine Subroutine auf und führt sie aus.

 

 

Syntax

CALL Test [ (var1, var-n) ]

 

 

Remarks

Var1

BASCOM-Variable oder Konstante.

Var-n

BASCOM-Variable oder Konstante.

Test

Name der Subroutine. In diesem Fall Test.

 

Man kann Subroutinen mit oder ohne Parameterübergabe aufrufen.

 

Es ist wichtig, dass die Subroutine deklariert wird bevor sie aufgerufen wird. Natürlich muss die Anzahl der deklarierten Parameter mit der Anzahl der übergebenen Parameter übereinstimmt.

 

 

Es ist außerdem wichtig, dass die Parameter bei Übergabe von Konstanten mit BYVAL deklariert werden.

 

Mit dem CALL-Befehl kann man Prozeduren und Subroutinen aufrufen.

 

Zum Beispiel: Call Test2

 

 

Der CALL-Befehl ermöglicht es, eigene Befehle zu definieren.

Man muss CALL nicht explizit schreiben:

Test2 ruft ebenfalls die Subroutine test2 auf.

 

 

Wenn man CALL nicht explizit schreibt dann müssen die Klammern weggelassen werden.

Also muss Call Routine(x,y,z) geschrieben werden als Routine x,y,x

 

Im Gegensatz zu normalen Unterprogrammen die mit GOSUB aufgerufen werden erlaubt der CALL-Befehl die Übergabe von Parametern.

 

Notice.jpg
Durch Benutzung von CONFIG SUBMODE=NEW braucht man nicht jede Subroutine bzw. Fuktion vorher zu deklarieren.

 

 

See also

DECLARE , SUB , EXIT , FUNCTION , LOCAL , CONFIG SUBMODE

 

 

Example


$regfile = "m48def.dat" ' specify the used micro
$crystal = 8000000 ' used crystal frequency
$baud = 19200 ' use baud rate
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
 
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
 
 
Dim A As Byte , B As Byte 'dimension some variables
Declare Sub Test(b1 As Byte , Byval B2 As Byte) 'declare the SUB program
A = 65 'assign a value to variable A
Call Test(a , 5)'call test with parameter A and constant
Test A , 5 'alternative call
Print A 'now print the new value
End
 
Sub Test(b1 As Byte , Byval B2 As Byte) 'use the same variable names as 'the declared one
Print B1 'print it
Print Bcd(b2)
B1 = 10 'reassign the variable
B2 = 15 'reassign the variable
End Sub

Notice.jpg
One important thing to notice is that you can change b2 but that the change will not be reflected to the calling program!

Variable A is changed however.

 

This is the difference between the BYVAL and BYREF argument in the DECLARE ration of the SUB program.

 

When you use BYVAL, this means that you will pass the argument by its value. A copy of the variable is made and passed to the SUB program. So the SUB program can use the value and modify it, but the change will not be reflected to the calling parameter. It would be impossible too when you pass a numeric constant for example.

 

 

If you do not specify BYVAL, BYREF will be used by default and you will pass the address of the variable. So when you reassign B1 in the above example, you are actually changing parameter A.


Languages   English Deutsch  
Personal tools
Namespaces
Variants
Actions
Navigation
In other languages
Language