Enter the following code in a program file, and then run it to create a
project, link the tasks, and calculate the length of the project. This
program will print a Gantt Chart and Pert Chart.
CLEAR
SET SAFETY OFF
ON ERROR DO OLERROR
SET DEFAULT TO "C:\VFP Files"
PUBLIC x
IF FILE('Saltbox.mpp')
ERASE Saltbox.mpp
ERASE Saltbox.mpx
ENDIF
IF USED('k2project')
USE IN k2Project
ENDIF
USE k2project IN 0
* Microsoft Project will only accept FOX2 TYPE FILES
COPY TO xproj TYPE FOX2
USE IN k2project
Myfile = "xproj.dbf"
x=CreateObject("MSProject.Project.4_1")
x.application.Visible=.t.
x.application.FileNew
x.application.FileSaveAs("SaltBox")
* Append Entry table from Myfile
x.application.FileOpen(Myfile,0,1,1,'Entry')
x.application.SelectAll
* Link the tasks together
x.application.LinkTasks
x.application.AppMinimize
Myans =MessageBox("Print Gantt Chart?",4+32,"Print Report")
IF Myans = 6
x.application.FilePrint(1,4)
ENDIF
x.application.AppRestore
x.application.ViewApply("Pert Chart")
x.application.AppMinimize
Myans =MessageBox("Print Pert Chart?",4+32,"Print Report")
IF Myans = 6
x.application.FilePrint(1,2)
ENDIF
x.application.ViewApply("Gantt Chart")
x.application.FileSave
x.application.FileQuit
RELEASE x
RETURN
PROCEDURE OLERROR
ON ERROR
WAIT WINDOW "An error occurred!"
=AERROR(myerror)
CLEAR
? 'The error provided the following information' && Display message
FOR n = 1 TO 7 && Display all elements of the array
? myerror(n)
ENDFOR
IF TYPE("X") = "O"
x.application.Quit
RELEASE X
CANCEL
ENDIF
RETURN