Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Return Value in a SUBroutine

is ther any possibility to declare an own Sub like:

sub isACoolName(name)

//return -1 or 0

Endsub

and then use it in if expressions: if isACoolName('JanUlrich') then .... ??

and how does such an return statemant have to look like?

MFG

4 Replies
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

    Try this.

sub isACoolName(name)

isACoolName =1

Endsub

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
Not applicable
Author

okey, thanks. But i still got a problem with writing the return value into a variable or use it in another way.

things like this:

a = isACoolName('test');

or

a = call isACoolName("test");

dont seem to work.

thanks for your input!

gussfish
Creator II
Creator II

Hi,

You can't return values from subroutines.  You might like try using a $-sign expansion, though.  e.g.

SET isACoolName=('$1'='janulrich');

LET a=$(isACoolName('John'));

Not applicable
Author

Managing return values from SUB are possible in this way:

1) define a INLINE table VAR - it is used like a collection in VB or JavaScript
VAR:
LOAD * INLINE [ Name, Val, Dummy_Var, 42 ]

2) create service functions to add or delete records in VAR
return values in SUBs can be stored in VAR with an Var_Add() or you can store directly with an LOAD * INLINE
Name, Val, ReturnVal, $(xyValue)

3) in main-pgm use LOOKUP to read the content of the Variable

Disadventages:
- initial effort to create service routines
- not very transparent

Adventage:
- array() are possible
- unlimited record structure as you can create more fields in VAR  Inline
- the INLINE table is a normal table which can be used in your app to display your VAR-records

Ralf