passing a function several times?

passing a function several times?

Postby deanomeano » Mon Jan 09, 2006 2:59 pm

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?
deanomeano
 
Posts: 22
Joined: Wed Nov 09, 2005 9:43 am

Postby Vladimir Grigoriev » Tue Jan 10, 2006 9:29 am

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 )
Vladimir Grigoriev
 
Posts: 54
Joined: Fri Oct 21, 2005 10:45 am
Location: Russia, Moscow

Postby deanomeano » Tue Jan 10, 2006 10:27 am

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!
deanomeano
 
Posts: 22
Joined: Wed Nov 09, 2005 9:43 am

Postby Enrico Maria Giordano » Tue Jan 10, 2006 10:50 am

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
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby deanomeano » Tue Jan 10, 2006 10:56 am

So, should I have a different LOCAL cApp for each refresh?
deanomeano
 
Posts: 22
Joined: Wed Nov 09, 2005 9:43 am

Postby Enrico Maria Giordano » Tue Jan 10, 2006 11:05 am

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

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby deanomeano » Tue Jan 10, 2006 11:07 am

Many Thanks Enrico. :D
deanomeano
 
Posts: 22
Joined: Wed Nov 09, 2005 9:43 am

Postby Vladimir Grigoriev » Tue Jan 10, 2006 11:49 am

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.
Vladimir Grigoriev
 
Posts: 54
Joined: Fri Oct 21, 2005 10:45 am
Location: Russia, Moscow


Return to FiveWin for CA-Clipper

Who is online

Users browsing this forum: No registered users and 6 guests

cron