Friday, October 29, 2010

Creating Subroutines With Arguments

This tutorial will now introduce you to the process of creating subroutines that can take in arguments or parameters and return values as well. Let us understand it with a simple example.

Example


First we create a subroutine that will accept 2 integer values, multiply them and return the result in a variable.

SUBROUTINE DEMO.CALLED.RTN(ARG.1,ARG.2,ARG,3)
ARG.3 = ARG.1 * ARG.2
RETURN
END
While defining subroutines in Infobasic, we cannot specify which are the incoming and which are the return parameters. Therefore just specify the arguments one after the other along with the subroutine definition as done above. Since the subroutine is storing the result in the variable ARG.3, the system would understand that ARG.3 is the return parameter.

Now let us call the routine we just made.
SUBROUTINE DEMO.CALLING.RTN
VAR.1 = 10
VAR.2 = 20
VAR.3 = ‘’
CALL DEMO.CALLED.RTN(VAR.1,VAR.2,VAR.3)
PRINT ‘Result “:VAR.3
RETURN
END

in this way we can write and call subroutines with arguments.

0 comments:

Post a Comment

 

Blog Info

A Pakistani Website by Originative Systems

Total Pageviews

Tutorial Jinni Copyright © 2015 WoodMag is Modified by Originative Systems