# subroutine statement

The subroutine statement defines a program
as an external subroutine.

## Syntax

```
subroutine {(arg.list)}
subroutine subroutine.name{(arg.list)}
```

## Parameter(s)

| arg.list | Variables to be assigned by the corresponding call statement. |
| --- | --- |
| subroutine.name | Subroutine to define as external. |

## Description

FlashBASIC or BASIC provides
the ability to call subroutines. The subroutine statement must appear on the first line of an external subroutine
invoked by a call statement.

Arguments defined
in the argument list are delimited by , (commas). *arg.list* must contain the same number of arguments as
are in the call statement.

Note: This statement
can be run from TCL provided the subroutine is *not* Flash-compiled
and there are no parameters specified.

If a subroutine is
called from the Update processor, in either a file-defining item,
or an attribute-defining item, no *arg.list* can
be specified by the call statement. If called from
a file-defining item, the item being filed is automatically passed
as a parameter in a call. If called from an attribute-defining item,
the current value of the attribute being processed is automatically
passed. Note that the subroutine is called once for every value in
the attribute.

A subroutine exits with a return statement.

All external subroutines must be cataloged prior
to execution.

## Example(s)

This example prompts for a date
and calls the external subroutine `validate.date` to
make sure the date is legal.

```
*program main
10 input start.date
call validate.date(start.date,ok)
if not(ok) then goto 10
```
Here is the subroutine:

```
subroutine validate.date(pdate,ok)
if pdate matches "1n0n1x1n0n1x2n0n" then
 if iconv(pdate,’d’) # "" then
 ok=1
 end else
 ok=0
 end
end else
 ok=0
end
return
```
The variable `ok` is set to 1 if the date
is valid. Otherwise, `ok` is set to 0 (false).

## See also

- [access() function](https://d3codex.com/pickbasic-flashbasic/access-function/)
- [call statement](https://d3codex.com/pickbasic-flashbasic/call-statement/)
- [clear statement](https://d3codex.com/pickbasic-flashbasic/clear-statement/)
- [common statement](https://d3codex.com/pickbasic-flashbasic/common-statement/)
- [enter statement](https://d3codex.com/pickbasic-flashbasic/enter-statement/)
- [gosub statement](https://d3codex.com/pickbasic-flashbasic/gosub-statement/)
- [hotkey0](https://d3codex.com/attributedefiningitem/hotkey0/)
- [hotkey1](https://d3codex.com/attributedefiningitem/hotkey1/)
- [hotkey2](https://d3codex.com/attributedefiningitem/hotkey2/)
- [hotkey3](https://d3codex.com/attributedefiningitem/hotkey3/)
- [hotkey4](https://d3codex.com/attributedefiningitem/hotkey4/)
- [hotkey5](https://d3codex.com/attributedefiningitem/hotkey5/)
- [hotkey6](https://d3codex.com/attributedefiningitem/hotkey6/)
- [hotkey7](https://d3codex.com/attributedefiningitem/hotkey7/)
- [hotkey8](https://d3codex.com/attributedefiningitem/hotkey8/)
- [hotkey9](https://d3codex.com/attributedefiningitem/hotkey9/)
- [precision statement](https://d3codex.com/pickbasic-flashbasic/precision-statement/)
- [return statement](https://d3codex.com/pickbasic-flashbasic/return-statement/)
- [Statements and functions](https://d3codex.com/pickbasic-flashbasic/statements-and-functions/)

---
Source: https://d3codex.com/pickbasic-flashbasic/subroutine-statement/ - part of the D3Codex reference.
