passing a function several times?

Post Reply
deanomeano
Posts: 22
Joined: Wed Nov 09, 2005 9:43 am
Contact:

passing a function several times?

Post by deanomeano »

I am using a function in my program to pass a filename variable to a field, but i need to pass it to several fields. I know I could repeat the function for each variable but I also know that I can change where the variable is placed.

Here is the code ;

STATIC FUNCTION FileName
LOCAL cDir := ALLTRIM(CURDIR())
LOCAL cApp := ""

cApp := cGetFile( "*.rpt","Report Files",1,cDir)

IF cApp == "*.rpt"
cApp := "default"
ELSE
IF "\"$cApp
cApp := ALLTRIM(subst(cApp , rat("\",cApp)+1,12))
cApp := LEFT(cApp, LEN(cApp) - 4)
ENDIF
ENDIF

IF !Empty(cApp)
mReportID := Alltrim(cApp)+".rpt"
oReportID:Refresh()
ENDIF
RETURN NIL

What I need to know is, how can I tell my program to change where the outcome is stored without rewriting it for each variable?
Vladimir Grigoriev
Posts: 54
Joined: Fri Oct 21, 2005 10:45 am
Location: Russia, Moscow
Contact:

Post by Vladimir Grigoriev »

What I need to know is, how can I tell my program to change where the outcome is stored without rewriting it for each variable?
Sorry I have not understood exactly what do you want.
Maybe the code below can give you some ideas?

STATIC cApp := ""

STATIC FUNCTION SetRptName()
/*
the body of the function almost the same as the body of your function FileName()
*/
...
RETURN ( NIL )

STATIC FUNCTION GetRptName()
RETURN ( cApp )
deanomeano
Posts: 22
Joined: Wed Nov 09, 2005 9:43 am
Contact:

Post by deanomeano »

maybe this will explain my question better?

CODE ;

STATIC FUNCTION FileName
LOCAL cDir := ALLTRIM(CURDIR())
LOCAL cApp := ""

cApp := cGetFile( "*.rpt","Report Files",1,cDir)

IF cApp == "*.rpt"
cApp := "default"
ELSE
IF "\"$cApp
cApp := ALLTRIM(subst(cApp , rat("\",cApp)+1,12))
cApp := LEFT(cApp, LEN(cApp) - 4)
ENDIF
ENDIF

IF !Empty(cApp)
mReportID := Alltrim(cApp)+".rpt"
oReportID:Refresh()
ENDIF

IF !Empty(cApp)
mFileProof := Alltrim(cApp)+".rpt"
oFileProof:Refresh()
ENDIF

IF !Empty(cApp)
mFinalFile := Alltrim(cApp)+".rpt"
oFinalFile:Refresh()
ENDIF

IF !Empty(cApp)
mReprint := Alltrim(cApp)+".rpt"
oReprint:Refresh()
ENDIF

RETURN NIL

the problem is, they all refresh with the same value, and I want each o:refresh to be able to hold a seperate value?

thanks for any help!
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

They refresh with the same value because you are assigning to all of them the same value. Try assigning different values and you will get different values.

EMG
deanomeano
Posts: 22
Joined: Wed Nov 09, 2005 9:43 am
Contact:

Post by deanomeano »

So, should I have a different LOCAL cApp for each refresh?
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

Yes. Or anyelse assign different values to the different objects.

EMG
deanomeano
Posts: 22
Joined: Wed Nov 09, 2005 9:43 am
Contact:

Post by deanomeano »

Many Thanks Enrico. :D
Vladimir Grigoriev
Posts: 54
Joined: Fri Oct 21, 2005 10:45 am
Location: Russia, Moscow
Contact:

Post by Vladimir Grigoriev »

I think you should rewrite your function such a way that it returns not NIL but cApp. In your main code you will have the following

LOCAL cApp
.....

IF ( !EMPTY( cApp := FileName() ) )
mReportID := Alltrim(cApp)+".rpt"
oReportID:Refresh()
ENDIF
.....

Or you can write general function as for example AssignVal()

FUNCTION AssignVal( &cVarName, oObject )

and call it for various arguments as below

AssignVal( &mReportID, oReportID )
AssignVal( &mFileProof, oFileProof )

and so on.
Post Reply