Defining Function

Started by Jeffrey Ferreira, February 25, 2019, 11:51:13 AM

Previous topic - Next topic

Jeffrey Ferreira

Hello List,

I'm trying to avoid using a global function but I would like function available in multiple programs.  I tried doing the following: 

PROG01

10 perform "PR0G02;DEFINE_FUNCTIONS"
20 PRINT fnPAIR$("Key","Value")

but I can't access the function defined in PR0G02

is my only recourse  a Global Function?

jeff

James Zukowski

James Zukowski
Sr. Developer - J&E

BRAND>SAFWAY
Brand Industrial Services

Jeffrey Ferreira

This looks promising James. I will give it a try. Thank you.

Devon Austen

Hi Jeff,

You could make it an object with the functions defined as methods and call it something like myUtilities.


DEF CLASS "myUtilities"
FUNCTION pair$(key$, value$)pair
END DEF
pair:
ENTER key$, value$
...
return result$


Then in programs you want to use it you do a myUtilies=NEW("myUtilties"). Then you simply call the functions like myUtilities'pair$("Key","Value")
Principal Software Engineer for PVX Plus Technologies LTD.

Mike King

Simply make your function global by the inclusion of the % in the function name as in:

DEF FN%PAIR$(local a$, local b$)
....
END DEF

-or-

DEF FN%PAIR$(local a$, local b$)=A$+"="+quo+b$+quo

See the description on "Global User-defined Functions" at the bottom of this page:
https://manual.pvxplus.com/page/PxPlus%20User%20Guide/Programming%20Constructs/Called%20Procedures/Overview.htm
Mike King
President - BBSysco Consulting - http://www.bbsysco.com
eMail: mike.king@bbsysco.com