FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for CA-Clipper passing a function several times?
Posts: 22
Joined: Wed Nov 09, 2005 09:43 AM
passing a function several times?
Posted: Mon Jan 09, 2006 02: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?

Posts: 54
Joined: Fri Oct 21, 2005 10:45 AM
passing a function several times?
Posted: Tue Jan 10, 2006 09: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 )
Posts: 22
Joined: Wed Nov 09, 2005 09:43 AM
passing a function several times?
Posted: 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!

Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
passing a function several times?
Posted: 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

Posts: 22
Joined: Wed Nov 09, 2005 09:43 AM
passing a function several times?
Posted: Tue Jan 10, 2006 10:56 AM

So, should I have a different LOCAL cApp for each refresh?

Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
passing a function several times?
Posted: Tue Jan 10, 2006 11:05 AM

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

EMG

Posts: 22
Joined: Wed Nov 09, 2005 09:43 AM
passing a function several times?
Posted: Tue Jan 10, 2006 11:07 AM

Many Thanks Enrico. :D

Posts: 54
Joined: Fri Oct 21, 2005 10:45 AM
passing a function several times?
Posted: 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.

Continue the discussion