home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1997 November
/
Pcwk1197.iso
/
LOTUS
/
Eng-ins
/
ACROREAD
/
SUITE
/
DW09_S7.LSS
< prev
next >
Wrap
Text File
|
1996-07-10
|
12KB
|
296 lines
'//-------------------------------------------
'// Script that shows how to add pages to a presentation
'// based on a bulleted list.
'//---------------------------------------
' This script, CreatePagesFromAgenda, turns
' information in a table into agenda or
' "to do" pages, with the name of the person responsible
' for each task and the task as the title of a page, and
' the due date in the upper right corner of the page.
' Each page has a bulleted list to be filled in by the
' person responsible for the task. It is followed by a
' script called Main, that allows you to call
' CreatePagesFromAgenda from an icon or from
' the menu by choosing Edit - Script - Run.
' Alternatively, you could attach the script to an event
' and avoid using the sub Main.
' CreatePagesFromAgenda is designed to work with a
' three-column table containing the following information:
' The first column contains the date that the task
' is to be completed; the second column contains the task;
' and the third column contains the name of the person
' responsible for completing the task. This script is set
' up to accommodate as many as 40 tasks. You can
' adjust that number to suit your needs. Also, you can
' have more columns containing additional information. If
' you do, you will have to adjust the script as necessary.
' Declare global constants. These constants are text
' strings as well as numerical values. In the case of the
' numerical values, these constants are contained in
' the file LSCONST.LSS. You can use an Include
' statement to include LSCONST.LSS and avoid having to
' declare these constants. However, in the interests of
' completeness, the constants are explicitly
' declared in this script.
Const CreateAgendaPagesMessage = "A page will " + _
"be created for each agenda item you " + _
"entered in the table. Press OK to continue."
Const CreateAgendaPagesTitle = "Create Agenda Pages"
Const ColumnError1 = "Agenda pages can't be " + _
"created because the columns in the table " + _
"have been modified."
Const ColumnError2 = "The table must have " + _
"three columns."
Const EmptyTable = "One or more cells are" + _
"empty. If you continue, the results may " + _
"not be what you expect. " +_
"Click Yes to continue or No to quit."
Const NoTable = "There is no table on this page. "+ _
"The script cannot run."
Const NoTitle = "There is no title for the " + _
"table column. This script will not run without one."
Const ErrorMsg = "Error"
' Use this constant to identify
' which SmartMaster template you want.
Const TemplateIndex = 2
' IDOK stands for OK button clicked.
Const IDOK = 1
' IDNO stands for no button clicked.
Const IDNO = 7
' MB_OK stands for a message box with only an OK button.
Const MB_OK = 0
' MB_OKCANCEL stands for a message box
' with OK and Cancel buttons.
Const MB_OKCANCEL = 1
' MB_YESNO stands for a message box
' with Yes and No buttons.
Const MB_YESNO = 4
' MB_ICONSTOP stands for a message box
' with a "Stop!" icon in it.
Const MB_ICONSTOP = 16
' MB_DEFBUTTON2 stands for a message box with
' the No button as the selected button when the Yes/No
' message box opens.
Const MB_DEFBUTTON2 = 256
Sub CreatePagesFromAgenda()
' Declare the variables that you need for this script.
Dim AgendaTableObj As Table
Dim Cell As TextBlock
Dim TitleTextBlk As TextBlock
Dim DateTextBlk As DrawObject
Dim TitlePB As PlacementBlock
Dim AgendaText(2 To 16, 1 To 8) As String
Dim PageTitle As String
Dim ColumnMessage As String
Dim Row As Integer
Dim Col As Integer
Dim NumRows As Integer
Dim NumCols As Integer
Dim NumChars As Integer
Dim RetVal As Integer
Dim MaxRows As Integer
Dim TableXists As Integer
Dim IsCellEmpty As Integer
Dim NoColumnTitle As Integer
' Put up message box that explains to user what
' this script does and ask if the user wants to
' let the script run to completion, also initialize
' the variable, RetVal, to the return
' value of Messagebox.
RetVal = Messagebox(CreateAgendaPagesMessage, _
MB_OKCANCEL, CreateAgendaPagesTitle)
' Deselect all selected items on the current page.
Selection.ClearSelection
' Initialize variable.
TableXists = 0
' Check to see if user clicked OK in message box.
' If OK was clicked, then begin.
If(RetVal = IDOK) Then
' Check to see that there is a table on the
' page. If found set flag, TableXists.
Forall Obj In CurrentPage.Objects
If (Obj.IsTable) Then
' Assign the table to the
' variable AgendaTableObj.
Set AgendaTableObj = Obj
TableXists = 1
End If
End Forall
' If no table was found then, notify user and
' exit script.
If (TableXists = 0) Then
Messagebox NoTable, MB_OK, ErrorMsg
Exit Sub
End If
' Initialize NumCols to the number of columns
' in the table.
NumCols = AgendaTableObj.ColCount
' Check to see if user added/deleted columns,
' because addition or deletion will result in
' unpredictable results. If number of columns
' was changed, then open message box
' informing user of unpredictable results.
If(NumCols <> 3) Then
' Assemble message with line break spacing.
ColumnMessage = ColumnError1 + Chr$(10) + _
Chr$(10) + ColumnError2
' Open message box with the message you just
' assembled.
Messagebox ColumnMessage, MB_OK, ErrorMsg
Else
' If number of columns is correct, begin
' processing. Determine number of rows in
' table and initialize MaxRows to it.
NumRows = 1
MaxRows = AgendaTableObj.RowCount
' Set variable Cell to the first cell, that is,
' the table column title cell.
Set Cell = AgendaTableObj.GetCell(NumRows, 1)
' Check that column title is filled in.
' Note, you could look for specific text
' at this point rather than simply check that
' the cell is not empty.
If (Strcompare(Cell.Text, "") = 0 ) Then
' Open message box explaining that
' script will not run without a column
' title. Initialize NoColumnTitle to the return
' value of the message box, that is, when
' user clicks the OK button, Messagebox
' returns a value of one.
' When user clicks the OK button, exit script.
NoColumnTitle = Messagebox(NoTitle, MB_OK + _
MB_ICONSTOP, ErrorMsg)
If (NoColumnTitle = IDOK) Then
Exit Sub
End If
End If
' As long as the table cell is not empty and
' the variable NumRows does not exceed the
' number of actual rows in the table, begin
' processing the table cells to check that they
' all contain text.
While((Not Strcompare(Cell.Text, " ")) And _
(NumRows < MaxRows))
' Increment the row count, so that you begin
' processing text with the second row
' (the first row contains column titles).
NumRows = NumRows + 1
Set Cell = AgendaTableObj.GetCell(NumRows, 1)
' Check to see if a cell is empty. If it is
' empty, open a message box, then exit sub.
' The logic here is similar to that of the
' previous message box code.
If (Strcompare(Cell.Text, "") = 0 ) Then
IsCellEmpty = Messagebox _
(EmptyTable, MB_YESNO+MB_ICONSTOP+ _
MB_DEFBUTTON2, ErrorMsg)
If (IsCellEmpty = IDNO) Then
Exit Sub
End If
End If
Wend
' Cycle through the rows of the table and put text
' into a string array.
For Row = 2 To NumRows
' Get cell text and put it in variable Cell.
Set Cell = AgendaTableObj.GetCell(Row, 1)
' Check that cell does not contain only spaces.
' If it does, then skip it: this will result
' in blank entries.
If(Not Strcompare(Cell.Text, " ")) Then
' Cycle through the columns in each row
' and put contents in array AgendaText.
' Note, AgendaText has been declared
' as an array containing 120 elements.
' That means it can process a table with
' forty rows--for a larger table, adjust
' the bounds of the array or use a
' dynamic array.
For Col = 1 To AgendaTableObj.ColCount
Set Cell = AgendaTableObj.GetCell(Row, Col)
AgendaText(Row, Col) = Cell.Text
Next Col
End If
Next Row
' For each row concatenate the text from columns
' two and three. Put the concatenated text
' into the title placement block on the new page.
For Row = 2 To NumRows
' Initialize the variable PageTitle.
PageTitle = ""
' Cycle through columns two and three
' of the current row.
For Col = 2 To NumCols
' If at last column (column three),
' add text of column three to
' the variable PageTitle (that is, add it to
' the text from column two) or else
' take text from column two and put it in
' variable PageTitle.
If(Col = NumCols) Then
PageTitle = PageTitle + AgendaText(Row, _
Col)
Else
PageTitle = PageTitle + AgendaText(Row, _
Col) + ", "
End If
Next Col
' Create a new page for each row in the table
' using the bulleted list SmartMaster look
' and use the contents of the variable
' PageTitle for the page name.
CurrentDocument.CreatePage PageTitle, 2
' Make a dummy text block set variable
' TitleTextBlk to it.
Set TitleTextBlk = CurrentPage.CreateText(1000, _
1000, 1000, 1000)
' Put the concatenated text from columns
' two and three into dummy text block.
' Note, it is easier to manipulate text that is
' text blocks than it is to manipulate text
' strings. Therefore, this script uses
' text blocks to manipulate text.
TitleTextBlk.Text = PageTitle
' Search current page to find the "Click here..."
' block (placement block) amd assign it to the
' variable TitlePB.
Forall Obj In CurrentPage.Objects
If (Obj.PlacementBlock.PromptText = _
"Click here to type page title") Then
Set TitlePB = Obj
End If
End Forall
' Insert text from dummy text block into
' the "Click here..." placement block.
TitlePB.Insert TitleTextBlk
' Deselect the selected items on the page.
Selection.ClearSelection
' Create a text block in the upper right
' corner of the page where the due date,
' from column one, will be inserted. Set
' the variable DateTextBlk as the handle
' to the text block.
Set DateTextBlk = _
CurrentPage.CreateText(12000,10500,1000,1000)
' Insert text from column one into the
' due date text block.
DateTextBlk.TextBlock.Text = "Due: " + _
AgendaText(Row, 1)
' Deselect the text block.
Selection.ClearSelection
Next Row
End If
End If
End Sub
' The following sub, Sub Main, makes it possible for
' you to run the CreatePagesFromAgenda sub when you
' choose Edit - Script - Run, or to run the
' script from an icon; in both cases Freelance Graphics
' looks for a sub named Main to execute.
Sub Main
CreatePagesFromAgenda
End Sub