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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling a UDF from the ON EXIT portion of the report summary band

Status
Not open for further replies.

Hank1953

Technical User
May 11, 2009
3
US
Hello,

I have been trying to get the lines of code that I found in faq184-2919 to work correctly.

I put the following lines of code into a program called myfunction.prg.


Code:
FUNCTION PRINTED
IF WEXIST("Printing...")
  lPrinted = .T.
ENDIF
ENDFUNC


Then on my form's PRINT command button click event I put the following lines of code:


Code:
nTotalPages = 0
REPORT FORM c:\foxpro1\reports\by_ticket_number.frx noconsole
nTotalPages = _pageno
lPrinted = .F.
REPORT FORM C:\foxpro1\reports\by_ticket_number TO PRINTER PROMPT NOCONSOLE


IF lPrinted = .T.
	MESSAGEBOX("The Monthly Report by Ticket Number was sent to the printer that you selected.",0+64,thisform.caption)
ELSE
	MESSAGEBOX("The Monthly Report by Ticket Number was cancelled.",0+64,thisform.caption)
ENDIF


In the LOAD procedure for my form I put the following lines of code:


Code:
PUBLIC lPrinted
SET PROCEDURE TO c:\foxpro1\progs\myfunction.prg


In the UNLOAD procedure for my form I put the line of code to release the PUBLIC variable lPrinted:


Code:
RELEASE lPrinted.


In my report form's ON EXIT portion of the summary band I tried putting the following line of code:


Code:
myfunction()


When I try to rebuild my VFP9 project I get the following error message:



Report c:\foxpro1\reports\by_ticket_number.frx has the following errors:
Unknown MYFUNCTION - Undefined



If I change the line of code in the ON EXIT portion of the report summary band to just:

Code:
myfunction

The VFP9 project will rebuild and compile without any errors, but when I run the resulting executable program and click on my PRINT command button I get the following error message:



Variable 'MYFUNCTION'is not found.


I've even tried putting this line of code into the ON EXIT portion of the report summary band:

Code:
Do myfunction

The VFP9 project will rebuild and compile without any errors, but when I run the resulting executable program and click on my PRINT command button I get the following error message:


Syntax error.


Can any of you look at my lines of code and tell me what I'm doing wrong?

I'm not familiar with using or calling UDF's in a report, so any help would be appreciated.

Thanks.



 
A couple of issues.

1. If you have used it as you describe, I noticed you called your function Printed, yet you are tring to call a function called myfunction (which is the name of your procedure file).
2. You may want to use
Code:
SET PROCEDURE TO c:\foxpro1\progs\myfunction.prg ADDITIVE
So you don't clear any other procedures already loaded.
3. The call is "PRINTED()" (no quotes) in the On Exit band.



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Mike,

I used your suggestion about putting the word "ADDITIVE" without the quotes at the end of the line of code that reads:


Code:
SET PROCEDURE TO c:\foxpro1\progs\myfunction.prg ADDITIVE 
/[code]


I changed this SET PROCEDURE TO line of code to read:

[code]
SET PROCEDURE TO c:\foxpro1\progs\printed.prg ADDITIVE 
/[code]

I changed the name of my program back to printed.prg, since you had said that I was calling a function called "PRINTED()", but my procedure file or program was called "MYFUNCTION".


I put this SET PROCEDURE TO line of code in my form's INIT event lines of code.


I also found that I had to change the lines of code in my form's PRINT button click event to read:


[code]
nTotalPages = 0
REPORT FORM c:\foxpro1\reports\by_ticket_number.frx noconsole
nTotalPages = _pageno

REPORT FORM C:\foxpro1\reports\by_ticket_number TO PRINTER PROMPT NOCONSOLE


IF lPrinted 
    MESSAGEBOX("The Monthly Report by Ticket Number was sent to the printer that you selected.",0+64,thisform.caption)
ELSE
    MESSAGEBOX("The Monthly Report by Ticket Number was cancelled.",0+64,thisform.caption)
ENDIF
/[code]

I found that if I left the line of code that read:
[code]
lPrinted = .F.
/[code]
in my form's PRINT button click event code that the PRINTED() function would always return a value of FALSE, even if I had clicked the PRINT button on the Printer Dialog Box.

In my form's LOAD event lines of code I put the following code:

[code]
PUBLIC lPrinted
lPrinted = .F.
/[code]

In my form's UNLOAD event lines of code I put the following line of code:

[code]
RELEASE lPrinted
/[code]

In my report form's PAGE HEADER BAND PROPERTIES, under the GENERAL tab of this popup window I put [code]printed()/[code]
in the area where it says RUN EXPRESSION On entry:

Then I rebuilt my VFP9 project and made an executable out of my VFP9 project and ran the resulting program without any errors.

If I click on the PRINT CANCEL button on the Printer Dialog Box it now shows that the printing was cancelled and if I click on the PRINT button on Printer Dialog Box it shows that the document was sent to the printer that I selected.

So everything is working like it should now.

Thanks.
 
I changed the name of my program back to printed.prg, since you had said that I was calling a function called "PRINTED()", but my procedure file or program was called "MYFUNCTION".

Just to be clear. A program can contain many functions. A program called MYFUNCTIONS can hold many functions. So to load up the procedures into memory you would use:

Code:
 SET PROCEDURE TO myFunction ADDITIVE

MyFunction being the name of the program.

Then you can call any functions within that procedural file (ie. PRINTED). You did not need to rename anything other than the call to the function. Anyways glad you have going.



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Mike,

Thanks for explaining the calling of a function to me.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top