Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you create a function that is global to the application? 2

Status
Not open for further replies.

rleiman

Programmer
May 3, 2006
258
US
Hi Everyone,

I have some code that I would like to transfer into a function that I can call from anywhere within my application.

I would like to call the function: GetWeekEndingDate() where I would pass into it a date.

Can you tell me how to set this up?

Thanks.

Emad
 
Hi Emad,

Create the function in the Application as a SOURCE Procedure and set the Procedure properties to be a Global Procedure. Example Source Procedure given below (paste into a text file with an extension of TXA and import into application)


[PROCEDURE]
NAME SelectDate
PROTOTYPE '(LONG, <<*QUEUE>, <<*LONG>),LONG'
GLOBAL
[COMMON]
DESCRIPTION 'Select Date'
FROM ABC Source
MODIFIED '2003/04/01' ' 9:34:22'
[DATA]
[SCREENCONTROLS]
! PROMPT('Date Var:'),USE(?DateVar:prompt)
! ENTRY(@n-14),USE(DateVar)
[REPORTCONTROLS]
! STRING(@n-14),USE(DateVar)
DateVar LONG(0)
!!> IDENT(4294966461),INITIAL('0'),PROMPT('Date Var:'),HEADER('Date Var'),PICTURE(@n-14)
[PROMPTS]
%Parameters DEFAULT ('(INP:Date, InpQ, InpQDate)')
%GenerateOpenClose LONG (0)
%GenerateSaveRestore LONG (0)
[EMBED]
EMBED %ProcessedCode
[DEFINITION]
[SOURCE]
PROPERTY:BEGIN
PRIORITY 3600
PROPERTY:END
DateVar = INP:Date

PopCal.SetCalendarWallPaper('~wall.gif')
PopCal.SetCalendarDayColors (COLOR:Red, COLOR:Navy, 255)
PopCal.CalDayMarkerStyle = 1
IF OMITTED(2)
PopCal.Calendar('', DateVar)
ELSE
PopCal.Calendar('', DateVar, InpQ, InpQDate)
END
DISPLAY()
RETURN(DateVar)


[END]
EMBED %DataSection
[DEFINITION]
[SOURCE]
PROPERTY:BEGIN
PRIORITY 4000
PROPERTY:END
PopCal HNDDates2

[END]
[END]


Regards
 
Hi ShankarJ,

Thanks for the sample. Could you tell me what the code in the square brakets are for?

This will be my first attempt at doing a function.

Thanks.

Truly,
Emad
 
Hi Emad,

This is not program code. This is an Exported Source Procedure Function from an Application. So don't waste you time trying to understand the code.

When you are inside any application, click on File and you will see three option somewhere in the middle called Import Text, Export Text and Selective Export. Export Text exports the whole application into a Text format. Selective Export allows you to choose which procedures you want to export into Text. Import Text imports all the procedure in the Text file. These text files have an extension of TXA (Template Exported Application) and are useful for many purposes. What I have pasted (in bold) is a Selective Export of a Source Procedure Function in one of my applications. Copy that and paste it into a file called SelectDate.TXA. Open your application and click on File --> Import Text and choose SelectDate.TXA. The SelectDate procedure is imported into your application. You can modify that procedure toy your needs.

Regards
 
Hi ShankarJ,

Thanks for the additional information.

I will work on it.

Truly,
Emad
 
!I'm not quite sure what you want your function to do
!However I think that this is close
!Note: % is the modulus operator
!Clarion dates are LONGS, representing the number of days
!Since Dec 28th, 1800
!----------------------------------------------------------
MAP
GetWeekEndingDate(DATE xInputDate),DATE
END

GetWeekEndingDate PROCEDURE(DATE xInputDate)!,DATE
DayOfWeek LONG
RetVal DATE
CODE
DayOfWeek = xInputDate % 7 !0 is Sunday, 1 is Monday, ... 6 is Saturday
RetVal = xInputDate + (6 - DayOfWeek) !Always return a Saturday
!The code gets slightly trickier
! if you want a different day of the week.
RETURN RetVal
 
Hi ShankarJ,

Thanks for the function. The timing is right since I did not get time to start coding my function.

What you have is what I was wanting. Thanks again for writing it. They are using Thursday as the end of the week.

I would be using it like this:

Code:
!----------------------------------------------------------
 MAP
   GetWeekEndingDate(DATE xInputDate),DATE
 END

GetWeekEndingDate  PROCEDURE(DATE xInputDate)!,DATE
DayOfWeek  LONG
RetVal     DATE
  CODE
  DayOfWeek = xInputDate % 7  !0 is Sunday, 1 is Monday, ... 6 is Saturday
  ! My case logic needs to be changed, that's why it looks
  ! like pl/sql code. I will do that at home.
  !------------------------------------------
  CASE DayOfWeek
     OF 1
        RetVal = xInputDate + 3

     OF 2
        RetVal = xInputDate + 2

     OF 3
        RetVal = xInputDate + 1

   ! The other of statements will go here.
  END CASE   

  RETURN RetVal

Truly,
Emad
 
Hi Emad,

Thank Mark. It was he who posted the function. :)

Regards
 
Ooooooooooooooops!

Sorry Mark,

My thanks fly out to you!

Truly,
Emad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top