Subroutines

118 views
Skip to first unread message

Jackson Ramos

unread,
Jan 14, 2022, 1:33:42 PM1/14/22
to Pick and MultiValue Databases
I'm still a little confused on how subroutines work. Where in the program itself does it read the parameters passed through? and how does the program know which parameters its reading?

Steve Trimble

unread,
Jan 14, 2022, 2:35:47 PM1/14/22
to mvd...@googlegroups.com
Jackson
SUBROUTINE 101
when a program states:

CALL GET.INPUT(DIO)
for example, technically,
DIO should (at a minimum) be set to NULL prior to the call subroutine.

so, if we send DIO into GET.INPUT subroutine, you should expect DIO to be returned with a value including 'null'.
if you have the statement:
CRT \NAME \:;INPUT DIO
you should expect DIO to be returned based on user input.
now the subroutine GET.INPUT can do all sorts of things to DIO after the operator enters characters from the keyboard or they merely hit the 'Enter' key (returning NULL)
NULL here is 'nothing' or 'empty' data value.

hope this helps a little bit,

Computerized Data Mgmt Inc
Steve Trimble
(501) 772-3450 cell / text


On Fri, Jan 14, 2022 at 12:33 PM Jackson Ramos <jackso...@qualco.com> wrote:
I'm still a little confused on how subroutines work. Where in the program itself does it read the parameters passed through? and how does the program know which parameters its reading?

--
You received this message because you are subscribed to
the "Pick and MultiValue Databases" group.
To post, email to: mvd...@googlegroups.com
To unsubscribe, email to: mvdbms+un...@googlegroups.com
For more options, visit http://groups.google.com/group/mvdbms
---
You received this message because you are subscribed to the Google Groups "Pick and MultiValue Databases" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mvdbms+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mvdbms/2d3098ba-9b53-4c5c-b471-ca542c304fbdn%40googlegroups.com.

chandru murthi

unread,
Jan 14, 2022, 11:00:39 PM1/14/22
to Pick and MultiValue Databases
Jackson:

Arguments are **passed both ways** if simple variables or arrays as in CALL SUB( DIO, MAT WHATEVER, .... ). The subroutine sees any values transferred, and the caller sees values returned.
Arguments must be one-to-one matched between the Calling program and the sub:    CALL WHOSIS (DIO, MAT WHATEVER, 9)  --->  SUBROUTINE WHOSIS( VAR1, MAT ARRAY2, VAR3)

The exception is when you want to pass a value to the subroutine, and NOT have any changes reflected in the variable on return. You then decouple the variable in one of the following ways:
Generically,      CALL SUB ( (DIO) )   ... the extra parentheses is the magic.
Often if the variable is a number,   CALL  SUB ( DIO  + 0 )   or,  if a string, CALL SUB ( DIO:'' )  but these are less efficient than the parentheses enclosure.
An array cannot be decoupled (imsr).

AND any expression's value is passed to the sub, but obviously cannot be returned:   CALL SUB( DIO* XXX+1 )

Hope this helps
Chandru Murthi

Dick Thiot

unread,
Jan 15, 2022, 1:56:44 PM1/15/22
to mvd...@googlegroups.com
A subroutine is simply a piece of code (self-contained logic) that can be executed but multiple programs. Variables are mainly "passed" to the subroutine in the header line.  These variables are referenced in the subroutine like any other variables and the value of those variables are returned to the calling program.  For example, if I have a subroutine to add two numbers and return the result it could look like this:
SUBROUTINE ADDTWONUMBERS( num1, num2, finalSum )
finalSum = num1 + num2
RETURN
END

Then a program could use this subroutine as:
* Call Subroutine
a = 5
b = 3
c = 0
CALL ADDTWONUMBERS( a, b, result)
CRT "The answer of ":a:" plus ":b": is ":c
END

Running this program would display:
The answer of 5 plus 3 is 8

I hope that clears it up for you.


On Fri, Jan 14, 2022 at 12:33 PM Jackson Ramos <jackso...@qualco.com> wrote:
I'm still a little confused on how subroutines work. Where in the program itself does it read the parameters passed through? and how does the program know which parameters its reading?

--

Wol

unread,
Jan 15, 2022, 4:25:39 PM1/15/22
to mvd...@googlegroups.com
Note that DataBASIC sometimes calls them functions, and they are
effectively interchangeable if you know the rules ...

But a function MUST have its result in the first argument. In the
calling program you Could call ADDTWONUMBERS as a function by declaring
it as a function (can't remember how) and then saying

RESULT = ADDTWONUMBERS( 1, 2)

You could then define and implement it as a function (again can't
remember the syntax) or declare it as a subroutine

SUBROUTINE ADDTWONUMBERS( RESULT, ARG1, ARG2)
RESULT = ARG1 + ARG2
RETURN
END

Cheers,
Wol
> <mailto:mvd...@googlegroups.com>
> To unsubscribe, email to: mvdbms+un...@googlegroups.com
> <mailto:mvdbms%2Bunsu...@googlegroups.com>
> For more options, visit http://groups.google.com/group/mvdbms
> <http://groups.google.com/group/mvdbms>
> ---
> You received this message because you are subscribed to the Google
> Groups "Pick and MultiValue Databases" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to mvdbms+un...@googlegroups.com
> <mailto:mvdbms+un...@googlegroups.com>.
> <https://groups.google.com/d/msgid/mvdbms/2d3098ba-9b53-4c5c-b471-ca542c304fbdn%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
> --
> You received this message because you are subscribed to
> the "Pick and MultiValue Databases" group.
> To post, email to: mvd...@googlegroups.com
> To unsubscribe, email to: mvdbms+un...@googlegroups.com
> For more options, visit http://groups.google.com/group/mvdbms
> <http://groups.google.com/group/mvdbms>
> ---
> You received this message because you are subscribed to the Google
> Groups "Pick and MultiValue Databases" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to mvdbms+un...@googlegroups.com
> <mailto:mvdbms+un...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mvdbms/CAAbj8ipFTOzptaWaMhv6D2P0T%2Bd%3Df6_A7nGe-o%3DnSe0CyHPa8Q%40mail.gmail.com
> <https://groups.google.com/d/msgid/mvdbms/CAAbj8ipFTOzptaWaMhv6D2P0T%2Bd%3Df6_A7nGe-o%3DnSe0CyHPa8Q%40mail.gmail.com?utm_medium=email&utm_source=footer>.

Marcus Rhodes

unread,
Jan 24, 2022, 10:07:59 AM1/24/22
to Pick and MultiValue Databases
It's crucial to understand that there are TWO types of subroutines in Pick: Internal and external.

Internal subroutines are local to the program in which they are defined, and share all the same variables as the larger program, so there is no need, or even possibility for passing parameters.  These are executed with the GOSUB {label} command.

External subroutines are distinct, separate programs with their own variables, and which are executed with a CALL {subroutine-name} command.  These subroutines can pass variables by copy in a parameter list, or they can pass variables by reference in a COM(MMON) statement.
Reply all
Reply to author
Forward
0 new messages