Page 1 of 1

passing a function several times?

Posted: Mon Jan 09, 2006 2:59 pm
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?

Posted: Tue Jan 10, 2006 9:29 am
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 )

Posted: Tue Jan 10, 2006 10:27 am
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!

Posted: Tue Jan 10, 2006 10:50 am
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

Posted: Tue Jan 10, 2006 10:56 am
by deanomeano
So, should I have a different LOCAL cApp for each refresh?

Posted: Tue Jan 10, 2006 11:05 am
by Enrico Maria Giordano
Yes. Or anyelse assign different values to the different objects.

EMG

Posted: Tue Jan 10, 2006 11:07 am
by deanomeano
Many Thanks Enrico. :D

Posted: Tue Jan 10, 2006 11:49 am
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.