11.5 Putting it all together

Putting it all together
In Chapter 10, "PowerPoint Basics," we put together a little slide show demonstrating the topics we covered. In this chapter, we use the same basic slides, and add many of the additional features we covered. Listing 1 (PPTSample2.PRG in the Developer Download files available at www.hentzenwerke.com) shows the code, while Figure 12, Figure 13, and Figure 14 show the finished slides. Note that with the addition of color, sound, and animation, this code must be run to see the presentation. Black and white screen shots cannot show all the features. 
Listing 1. A sample presentation for Tasmanian Traders.

CLOSE DATA
#DEFINE ppTitleStyle 2
#DEFINE ppBodyStyle 3
#DEFINE ppLayoutTitle 1
#DEFINE ppLayoutText 2
#DEFINE ppEffectCoverDown 1284
#DEFINE ppEffectDissolve 1537
#DEFINE ppEffectAppear 3844
#DEFINE ppAnimateByFirstLevel 1
#DEFINE ppAdvanceOnTime 2
#DEFINE msoGradientHorizontal 1
#DEFINE ppBulletArabicPeriod 3
#DEFINE msoLineThickBetweenThin 5
#DEFINE autoIn2Pts 72

#DEFINE rgbDarkBlue RGB( 0, 0, 138) 
#DEFINE rgbMediumBlue RGB( 96, 96, 204) 
#DEFINE rgbPaleGray RGB(192, 192, 192) 
#DEFINE rgbYellow RGB(255, 255, 0)
#DEFINE rgbBurgundy RGB(128, 0, 0)
#DEFINE rgbLineColor RGB(255, 255, 0)

SET PATH TO (_SAMPLES + "\TasTrade\Data") ADDITIVE

******************
* Set up the data
******************
OPEN DATABASE TasTrade
LogoFile = (_SAMPLES + "\TasTrade\Bitmaps\TTradeSm.bmp")

USE OrdItems IN 0 
USE Products IN 0

* Select the top 5 selling items of all time
SELECT TOP 5 ;
P.English_Name, ;
SUM(O.Unit_Price * O.Quantity) AS TotQuan ;
FROM OrdItems O, Products P ;
WHERE O.Product_ID = P.Product_ID ;
GROUP BY 1 ;
ORDER BY 2 DESC;
INTO CURSOR TopSellers

* Select the number of products
SELECT Count(*) ;
FROM Products ;
INTO ARRAY aProducts

* Clean out any existing references to servers.
* This prevents memory loss to leftover instances.
RELEASE ALL LIKE o*

* For demonstration purposes, make oPowerPoint and oPresentation
* available after this program executes.
PUBLIC oPowerPoint, oPresentation

* Open PowerPoint
oPowerPoint = CreateObject("PowerPoint.Application")
oPowerPoint.Visible = .T.

* Create the presentation
oPresentation = oPowerPoint.Presentations.Add()

SlideNum = 1

******************
* MASTER SLIDE
******************
WITH oPresentation.SlideMaster

* Set the background to a gradient fill
WITH .Background.Fill 
.ForeColor.RGB = rgbMediumBlue
.BackColor.RGB = rgbPaleGray
.TwoColorGradient(msoGradientHorizontal, 1)
ENDWITH

* Set titles 
WITH .TextStyles[ppTitleStyle].Levels[1].Font
.Name = "Arial"
.Shadow = .T.
.Color.RGB = rgbDarkBlue
ENDWITH

* Set Body Style levels
WITH .TextStyles[ppBodyStyle]
WITH .Levels[1]
WITH .Font
.Name = "Arial"
.Bold = .T.
.Color.RGB = rgbBurgundy
.Size = 20
ENDWITH
WITH .ParagraphFormat.Bullet
* Set bullet character to a dot (use 149 if using PowerPoint 97)
.Character = 8226 
.Visible = .F. && Don't show the bullet! 
ENDWITH
ENDWITH
WITH .Levels[2]
WITH .Font
.Name = "Arial"
.Color.RGB = rgbDarkBlue
.Size = 20
ENDWITH
* Set bullet character to a dot (use 149 if using PowerPoint 97)
.ParagraphFormat.Bullet.Character = 8226 

ENDWITH

ENDWITH

* Add the logo.
.Shapes.AddPicture(LogoFile, .F., .T., ;
8.5 * autoIn2Pts, 6.0 * autoIn2Pts)

* PowerPoint 97 users: the last two parameters,
* height and width, are not optional. Use this 
* code instead:
*.Shapes.AddPicture(LogoFile, .F., .T., ;
* 8.5 * autoIn2Pts, 6.0 * autoIn2Pts, ;
* 1.0 * autoIn2Pts, 1.0 * autoIn2Pts)

ENDWITH

Figure 12. The Tasmanian Traders sample title slide. The gradient fill background, title fonts and colors, and the logo on each slide are done through the Master Slide.
******************
* TITLE SLIDE
******************
* Add the slide
oSlide = oPresentation.Slides.Add(SlideNum, ppLayoutTitle)

* Set the title text. 
oSlide.Shapes[1].TextFrame.TextRange.Text = "Tasmanian Traders"

* Set the subtitle text 
oSlide.Shapes[2].TextFrame.TextRange.Text = "Welcomes you..."

WITH oSlide.SlideShowTransition
.EntryEffect = ppEffectCoverDown 
.AdvanceOnTime = .T.
.AdvanceTime = 2
ENDWITH

SlideNum = SlideNum + 1


Figure 13.
The Tasmanian Traders sample second slide. As with the first slide, there is minimal formatting in the code, because the SlideMaster takes care of the majority of the formatting.


******************
* SECOND SLIDE
******************

* Add the slide
oSlide = oPresentation.Slides.Add(SlideNum, ppLayoutTitle)

* Bring the slide to the front
oSlide.Select()

* PowerPoint 97 users: oSlide.Select() will
* generate an error. Use this line instead:
* oPresentation.ActiveWindow.View.GoToSlide(2)

* Set the text of the title
oSlide.Shapes[1].TextFrame.TextRange.Text = "Tasmanian Traders " + CHR(13) + ;
"has what you need" 

* Move the title up about half an inch
WITH oSlide.Shapes[1]
.Top = .Top - (.5 * autoIn2Pts)
ENDWITH

* Add a line half an inch below the title that is centered and 6" long
LineTop = oSlide.Shapes[1].Top + oSlide.Shapes[1].Height + ;
(.5 * autoIn2Pts)
LineLeft = 2 * autoIn2Pts
LineEnd = LineLeft + (6.0 * autoIn2Pts)

oLine = oSlide.Shapes.AddLine(LineLeft, LineTop, LineEnd, LineTop)

* Format the line to be a thick line 
* with two thin lines on either side
WITH oLine.Line
.ForeColor.RGB = rgbLineColor
.Style = msoLineThickBetweenThin
.Weight = 8
ENDWITH 

* Set the text of the subtitle, and change the number to bold and blue
WITH oSlide.Shapes[2].TextFrame.TextRange
.Text = "With a selection of " + ALLTRIM(STR(aProducts[1])) + ;
" items, you're sure to be pleased."
.Words[5].Font.Color = rgbDarkBlue
ENDWITH

WITH oSlide.SlideShowTransition
.EntryEffect = ppEffectDissolve 
.AdvanceOnTime = .T.
.AdvanceTime = 5
ENDWITH

SlideNum = SlideNum + 1



Figure 14. The Tasmanian Traders sample third slide. Again, the bulk of the formatting is done in the SlideMaster. Fonts, colors, and backgrounds are extremely consistent, and your code is easy to maintain.

***********************
* TOP SELLERS SLIDE
***********************
* Add the slide
oSlide = oPresentation.Slides.Add(SlideNum, ppLayoutText)

* Bring the slide to the front
oSlide.Select()

* PowerPoint 97 users: oSlide.Select() will
* generate an error. Use this line instead:
* oPresentation.ActiveWindow.View.GoToSlide(3)

* Insert the title (note the use of the Title object, instead of 
* an enumerated shape object). 
oSlide.Shapes.Title.TextFrame.TextRange.Text = "Tasmanian Traders" + ;
CHR(13) + "Top Sellers"

* Build the string to use for the top 5 sellers. 
* Use a CR between each item to make each a separate bullet.
BulletString = ""
SELECT TopSellers
SCAN
BulletString = BulletString + ;
TRIM(TopSellers.English_Name) + CHR(13) + "$" + ;
ALLTRIM(TRANSFORM(TopSellers.TotQuan, "99,999,999")) + ;
CHR(13)
ENDSCAN

* Add the bullet string to the text frame.
WITH oSlide.Shapes[2]
WITH .TextFrame.TextRange
.Text = BulletString

* Indent all the sales quotas
FOR I = 1 TO 5
.Lines[I*2, 1].IndentLevel = 2
ENDFOR 
ENDWITH 

* Move it to the right about 1.5"
.Left = .Left + (1.5 * autoIn2Pts)

* Each bullet (with subordinates) appears at 1 second intervals
WITH .AnimationSettings
.EntryEffect = ppEffectAppear
.TextLevelEffect = ppAnimateByFirstLevel
.AdvanceMode = ppAdvanceOnTime
.AdvanceTime = 0.5
.SoundEffect.Name = "Whoosh"
ENDWITH
ENDWITH 

oSlide.SlideShowTransition.EntryEffect = ppEffectDissolve

* Run the slideshow. 
oPresentation.SlideShowSettings.Run()

This chapter explored the visual world of PowerPoint. We've covered many of the commonly used features of PowerPoint. There is a lot more to PowerPoint, though, so don't hesitate to use that macro recorder, the Object Browser, and the Help files to find those features that your application needs.


Copyright 2000 by Tamar E. Granor and Della Martin All Rights Reserved



Microsoft Office Automation with Visual FoxPro
Microsoft Office Automation with Visual FoxPro
ISBN: 0965509303
EAN: 2147483647
Year: 2000
Pages: 128

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net