PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Defining Function  (Read 1763 times)

Jeffrey Ferreira

  • Diamond Member
  • *****
  • Posts: 176
  • I must have taken a wrong turn at Albuquerque.
    • View Profile
Defining Function
« on: February 25, 2019, 11:51:13 AM »
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

  • Diamond Member
  • *****
  • Posts: 304
    • View Profile
Re: Defining Function
« Reply #1 on: February 25, 2019, 11:57:20 AM »
You could look into XEQ as a possibility:
https://manual.pvxplus.com/PXPLUS/functions/xeq.htm
James Zukowski
Sr. Developer - J&E

BRAND>SAFWAY
Brand Industrial Services

Jeffrey Ferreira

  • Diamond Member
  • *****
  • Posts: 176
  • I must have taken a wrong turn at Albuquerque.
    • View Profile
Re: Defining Function
« Reply #2 on: February 25, 2019, 12:54:59 PM »
This looks promising James. I will give it a try. Thank you.

Devon Austen

  • Administrator
  • Diamond Member
  • *****
  • Posts: 383
  • Don’t Panic
    • View Profile
    • PVX Plus Technologies
Re: Defining Function
« Reply #3 on: February 25, 2019, 03:40:20 PM »
Hi Jeff,

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

Code: [Select]
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

  • Diamond Member
  • *****
  • Posts: 3817
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: Defining Function
« Reply #4 on: February 26, 2019, 09:29:29 AM »
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
eMail: mike.king@bbsysco.com