Derek Dowle


I am using FoxPro 9 and have inserted a graph onto a page of a page frame of a form.

I have been following the principles of the 'How do I create a graph using MSGraph from Marcia Akins white paper Creating Graphs In VFP. This white paper has been very helpful as I did not know where to start before reading it.

I have succeeded in populating the graph with the correct data and displaying the graph that I required, a stacked column, but unfortunately I am unable to format the graph any further.

I have noted that the sample code was written for VFP7 and have therefore SET ENGINEBEHAVIOR TO 70.

The problem occurs within the code for the user procedure 'updategraphdata'. The code in question is:

** * OK, ready to update the graph

SELECT csrGraph

APPEND GENERAL oleGraph CLASS "MsGraph.Chart" DATA lcGraphData

WITH Thisform.oGraph

*** Reset the controlSource of the OleBound control

.ControlSource = "csrGraph.oleGraph"

*** Set the chart type

.object.ChartType = This.nGraphType

*** Set the data to graph the columns as the series

*** Unless, of course, this is a pie chart

IF NOT INLIST( .ChartType, xl3DPie, xlPie, xlPieOfPie, xlPieExploded, xl3DPieExploded, xlBarOfPie )

.Object.Application.PlotBy = xlColumns

ELSE

.Object.Application.PlotBy = xlRows

ENDIF

ENDWITH

The only change that I have made to this abstract is to replace:

WITH Thisform.oGraph

with

WITH Thisform.oGraph.upgf1.page5

The code resets the ControlSource and sets the ChartType.

However, when it attempts to set the graph data in columns or rows error messages appear.

Variable 'XL3PIE' is not found

Variable 'XLCOLUMNS' is not found

Can anyone please explain why this code is not accepted and how the problem can be resolved.

Many thanks in advance.




Re: Formatting Graphs

MarciaAkins


Derek Dowle wrote:

However, when it attempts to set the graph data in columns or rows error messages appear.

Variable 'XL3PIE' is not found

Variable 'XLCOLUMNS' is not found

Can anyone please explain why this code is not accepted and how the problem can be resolved.

I am very glad that you have find the white paper and code samples useful.

Your problem is that xl3Pie and xlColumns are not variables. They are constants defined in an include file that should be specified as the include file for your class or form. This is one reason I seldom use them .

Go to the class or form menu, select Include File, and make sure that Graph9.h is specified as the include file.







Re: Formatting Graphs

Derek Dowle

Hi Marcia

Thank you very much for your very prompt response.

I have included the Graph9.h file on the form that I have taken from the files associated with the white paper.

The inclusion of the Graph9.h file has now enabled me to plot the graph by columns, but to do this I have had to REM out some lines of code as below as the 'xl3Pie' variable still cannot be found. As I do not was the type of graph to be user definable this is not a particular problem. However, I am curious to know why this could be!

WITH THISFORM.UPGF1.Page5.OGraph

.controlsource = "csrGraph.oleGraph"

.object.charttype = THISFORM.ngraphtype

* IF NOT INLIST(.Charttype, xl3Pie, xlPie)

.object.application.plotby = xlColumns

* ELSE

* .object.application.plotby = xlrows

* ENDIF

ENDWITH

I am now going to take the process a little further and format the legend, axes, etc.

I chose the MSGraph route as it appeared from the white paper to be self contained in the VFP environment and less likely to be affected by future changes in other software. In your reply you infer that you have an alternative method of creating graphs, is this the case

Many thanks

Derek






Re: Formatting Graphs

CetinBasoz

Derek,

Because there isn't a constant named xl3Pie but xl3DPie (-4102).





Re: Formatting Graphs

MarciaAkins

Derek Dowle wrote:

but to do this I have had to REM out some lines of code as below as the 'xl3Pie' variable still cannot be found. As I do not was the type of graph to be user definable this is not a particular problem. However, I am curious to know why this could be!

I see that Cetin has given you the answer to this one - those typos will get you every time

Derek Dowle wrote:

I chose the MSGraph route as it appeared from the white paper to be self contained in the VFP environment and less likely to be affected by future changes in other software. In your reply you infer that you have an alternative method of creating graphs, is this the case

I did not imply that I have an alterbative method of creating graphs (although, as you can tell from the white paper, there are many alternatives from which to choose). What I said in my response is that I do not like include files. Most of the time, I just list me #DEFINE statement at the top of a program or method.






Re: Formatting Graphs

Derek Dowle

Hi Marcia

Thanks to your help I can now display a graph on a Form. I have spent some time since your latest reply refining the formating of the graph to emulate a graph in an Excel application. After much trial and error I achieved my goal

My euphoria is somewhat dampened by the fact that I cannot replicate the graph on a Report !

Initially I created a new report and gave it the name 'rptmsgraph' to match your file, placed an OLE object on the report, gave it a control source of csrGraph.OleGraph and the control source type to 'General Field Name'.

On the form I have placed a command button with the click event code:

FLUSH

GO TOP IN csrGraph

REPORT FORM RptMsGraph PREVIEW

which matches that in your example.

When the code is run a program error appears 'File does not exist'. The debugger indicates the last line of code to be at fault.

To overcome the possibility of 'user error' I replaced my report with your report rptmsGraph in my application, but the error still occurs.

I have presumably omitted to do something, but what

I have simplified the example code to take out the user defined elements but I believe I have kept to the path of your example; i.e.

makegraph()

doquery()

updategraphdata()

formatgraph()

tweakgraph()

especially as the graph is displayed on the form.

Are you able to help me solve this problem please





Re: Formatting Graphs

MarciaAkins

Derek Dowle wrote:

FLUSH

GO TOP IN csrGraph

REPORT FORM RptMsGraph PREVIEW

which matches that in your example.

When the code is run a program error appears 'File does not exist'. The debugger indicates the last line of code to be at fault.

Are you able to help me solve this problem please

I will try - but since the sample code runs flawlessly on my machine, it is kind of like looking into my crystal ball

The form is unable to find either the frx or the cursor - those are the only two possibilities. The cursor csrGraph must be in the currently selected work area before the report runs.

If the frx exists, does it exists in the same folder as the form or in a special folder called reports Are the paths set correctly






Re: Formatting Graphs

Derek Dowle

Hi Marcia

Your clues have helped me to resolve the problems and I can now reproduce the graph in a report.

The 'Data Session' screen confirmed that I was looking at the Cursor csrGraph.

I then placed SYS(2003) in the code to determine where the application was looking for the report. I found it was in the SYS(2023) temporary path where I store the temporary table that provides the data for Cursor csrResults.

In the command button to initiate the report I have now placed code to direct the application to the \Reports subdirectory.

Thank you very much for your help it is greatly appreciated.

However, there is always one last question. When I exit the report and return to the form, the graph that I initially see is one before it was formatted. It is only for a split second before returning to the formatted graph. Is there a way of suppressing this

Many thanks

Derek





Re: Formatting Graphs

MarciaAkins

Derek Dowle wrote:

In the command button to initiate the report I have now placed code to direct the application to the \Reports subdirectory.

When I exit the report and return to the form, the graph that I initially see is one before it was formatted. It is only for a split second before returning to the formatted graph. Is there a way of suppressing this

As far as hard-coding the path to the reports folder in the REPORT FORM command, you would be better off to set the path corrrectly in your main program in a manner similar to this:

*******************************************************************

FUNCTION SetPath()

*******************************************************************

LOCAL lcSys16, lcProgram, lcPath

*** Grab name of program that called this one.

lcSys16 = SYS( 16, 1 )

lcProgram = JUSTFNAME( lcSys16 )

*** Change to the directory that the program is in

CD JUSTPATH( lcSys16 )

*** If we are running the main program directly, then

*** CD up to the parent directory

IF JUSTEXT( lcProgram ) = "FXP"

CD ..

ENDIF

*** Go ahead and set the path

IF VERSION(2) # 0

*** We are in Development Mode

*** Set up Project search path

lcPath = HOME() + ';' + FULLPATH( CURDIR() ) + [;form;libs;include;menu;data;prog;report;graphics]

ELSE

*** We are in Production Mode

*** Set up application search path

lcPath = FULLPATH( CURDIR() ) + [;data;report;graphics;prog]

ENDIF

SET PATH TO ( lcPath )

*** and the classlibs

SET CLASSLIB TO application, BaseForm, BaseCtrl, stdCustom, DataContainer ADDITIVE

SET PROCEDURE TO GlobalProcs ADDITIVE

ENDFUNC

To suppress the visual effects on the form, you might try adding this code as a custom method to the form, call the method ReallyLockScreen and call it before printing the report with a parameter of .T. to lock the screen and then call it again after the report with a parameter of .F. TO unlock it:

* Purpose....: Use the Windows API to force a true screen lock.

LPARAMETERS tlLock

LOCAL ARRAY laJunk[1]

LOCAL lnHWnd

**********************************************************

*** Check that the library has been set up and open it if not already done.

**********************************************************

lnRes = ADLLS( laJunk )

IF lnRes = 0 OR NOT ( ASCAN( laJunk, 'LockWindowUpdate', 1, -1, 1, 15 ) > 0)

*** We don't have the function available

DECLARE INTEGER LockWindowUpdate IN Win32API INTEGER nHandle

ENDIF

*** Now set the Handle to lock according to the parameter

lnHWnd = IIF( tlLock, ThisForm.HWnd, 0 )

*** And call the function

LockWindowUpdate(lnHWnd)

RETURN






Re: Formatting Graphs

Derek Dowle

Hi Marcia

I will study the code which you have sent to fully understand what it is doing and how it does it and then introduce it into my application.

Once again thankyou very much.

Derek