Altova UModel 2025 Basic Edition

Subroutine declaration

Home Prev Top Next

Subroutines

 

Syntax example:

 

Sub SimpleSub()

 

... lines of code

EndSub

 

Sub is the keyword that denotes the procedure.

SimpleSub is the name assigned to the subroutine.

Round parenthesis can contain a parameter list.

The code block of a subroutine starts immediately after the closing parameter parenthesis.

EndSub denotes the end of the code block.

 

Note:Recursive or cascaded subroutine declaration is not permitted, i.e. a subroutine may not contain another subroutine.

 

Parameters

Parameters can also be passed by procedures using the following syntax:

 

All parameters must be variables

Variables must be prefixed by the $ character

Local variables are defined in a subroutine

Global variables are declared explicitly, outside of subroutines

Multiple parameters are separated by the comma character "," within round parentheses

Parameters can pass values

 

Parameters - passing values

Parameters can be passed in two ways, by value and by reference, using the keywords ByVal and ByRef respectively.

 

Syntax:

 

' define sub CompleteSub()

[Sub CompleteSub( $param, ByVal $paramByValue, ByRef $paramByRef )

] ...

 

ByVal specifies that the parameter is passed by value. Note that most objects can only be passed by reference.

ByRef specifies that the parameter is passed by reference. This is the default if neither ByVal nor ByRef is specified.

 

Function return values

To return a value from a subroutine, use the return statement. Such a function can be called from within an expression.

 

Example:

 

' define a function

[Sub MakeQualifiedName( ByVal $namespacePrefix, ByVal $localName )

if $namespacePrefix = ""

return $localName

else

return $namespacePrefix & ":" & $localName

endif

EndSub

]

© 2018-2024 Altova GmbH