Sub func1(param1 As Word, param2 As Single)
Msg_WriteHex(param1)
Msg_WriteFloat(param2)
End Sub
Similar to local variables passed parameters are only visible within the function itself.
In order to call up function func1 by use of the parameters the parameters for call up should be
written in the same succession as they have been defined in func1. If the function does not get
parameters the parenthesis will stay empty.
Sub main()
Dim a As Word
Dim f As Single
func1(128,12.0)
a=100
f=12.0
func1(a+28,f)
End Sub
When calling up a function all parameters must always be stated. The following call up is
inadmissible:
func1()
func1(128)
Return Parameters
It is not only possible to pass parameters. A function can also offer a return value. The data type of
this value is during function definition entered after the parameter list of the function.
Sub func1(a As Integer) As Integer
Return
End Sub
The return value is within the function stated as instruction "return Expression". If there is a function
without return value then the return instruction can be used without parameters in order to leave the
function.
References
Since it is not possible to pass on arrays as parameters the access to parameters is possible
through references. For this the attribute "ByRef" is written ahead of the parameter name in the
parameter declaration of a function.
Sub StringLength(ByRef str As Char) As Integer
Dim i As Integer
i=0
© 2008 Conrad Electronic
' first parameter output
' you can pass Numerical constants
' or yet variables too and even numerical expressions
'
func1 gets 2 parameters!
'
func1 gets 2 parameters!
a-10
' second parameter output
Compiler
122
Need help?
Do you have a question about the C-Control Pro Mega Series and is the answer not in the manual?
Questions and answers