Visual Basic Example #8

Here's an example which illustrates many of Milestones Professional's OLE Automation methods.  It builds an outlined schedule, adds budget and actual cost values SmartColumns, and adds a DataGraph to represent it. Try this example
    
The Code: 
Sub main()
Set objMilestones = CreateObject("Milestones")
With objMilestones
'Start Milestones and Set to Use 20 Columns
.Activate
.Use20Columns

'Set Title
.SetTitle1 "Type 3 DataGraph Example - OLE Automation"
'Setup Symbols in the ToolBox
.SetToolboxSymbolProperty 1, "Type", 43
.SetToolboxSymbolProperty 1, "FillColor", 5
.SetToolboxSymbolProperty 2, "Type", 44
.SetToolboxSymbolProperty 2, "FillColor", 5
.SetToolboxSymbolProperty 3, "Type", 3
.SetToolboxSymbolProperty 3, "FillColor", 3
.SetToolboxSymbolProperty 4, "Type", 3
.SetToolboxSymbolProperty 4, "FillColor", 3
'Setup Horizontal Connectors in the Toolbox
.SetToolboxHorizontalConnectorProperty 1, "Type", 7
.SetToolboxHorizontalConnectorProperty 1, "FillColor", 5
.SetToolboxHorizontalConnectorProperty 2, "Type", 5
.SetToolboxHorizontalConnectorProperty 2, "FillColor", 3
.SetToolboxHorizontalConnectorProperty 2, "OutlineColor", 14
'Set Schedule Start and End Dates
.SetStartAndEndDates "1/1/2004", "12/31/2004"
'Remove Unneeded Columns and Rows From Template
.SetColumnWidth 1, 0
.SetColumnWidth 2, 0
.SetColumnWidth 3, 2.8
.SetLinesPerPage 8
'Put Text in Task Column
.PutCell 1, 3, "Project 1"
.PutCell 2, 3, "Task 1-1"
.PutCell 3, 3, "Task 1-2"
.PutCell 4, 3, "Task 1-3"
.PutCell 5, 3, "Project 2"
.PutCell 6, 3, "Task 2-1"
.PutCell 7, 3, "Task 2-2"
.PutCell 8, 3, "Task 2-3"
'Setup Outline Levels and Summary Bar Settings
.SetColumnProperty 3, "Indent", 0.3
.SetOutlineLevel 2, 2
.SetOutlineLevel 3, 2
.SetOutlineLevel 4, 2
.SetOutlineLevel 6, 2
.SetOutlineLevel 7, 2
.SetOutlineLevel 8, 2
.SetSummaryBarDisplay 2
'Add Symbols and Barlines and Remove Gridlines
.SetScheduleGridlinesAndShades 1, 0, 0, 0, 0, 0, 0
.SetScheduleVerticalGridlines 3, 0, 0, 0
.AddSymbol 2, "2/29/2004", 3, 2, 2
.AddSymbol 2, "9/17/2004", 4
.AddSymbol 3, "5/18/2004", 3, 2, 2
.AddSymbol 3, "9/20/2004", 4
.AddSymbol 4, "7/29/2004", 3, 2, 2
.AddSymbol 4, "11/4/2004", 4
.AddSymbol 6, "5/14/2004", 3, 2, 2
.AddSymbol 6, "10/30/2004", 4
.AddSymbol 7, "5/21/2004", 3, 2, 2
.AddSymbol 7, "10/25/2004", 4
.AddSymbol 8, "5/31/2004", 3, 2, 2
.AddSymbol 8, "10/25/2004", 4
'Insert Budget and Actual Cost Columns
.SetCustomColor 1, 128, 255, 128
.SetCustomColor 15, 255, 255, 128
.SetFontStyle 17, 0, -1, 18
.SetColumnProperty 11, "SmartColumn", "Values"
.SetColumnProperty 11, "ColumnBackgroundColor", 1
.SetColumnProperty 11, "ColumnHeadingLine1", "Budget"
.SetColumnProperty 11, "ColumnHeadingLine2", ""
.SetColumnProperty 11, "ColumnHorzTextAlign", 2
.SetColumnProperty 11, "DisplayColumnAsCurrency", 1
.SetColumnProperty 11, "HeadingBackgroundColor", 1
.SetColumnProperty 11, "NumberDecimals", 2
.SetColumnProperty 11, "Width", 1.23
.SetFontStyle 18, 0, -1, 18
.SetColumnProperty 12, "SmartColumn", "Values"
.SetColumnProperty 12, "ColumnBackgroundColor", 15
.SetColumnProperty 12, "ColumnHeadingLine1", "Actual"
.SetColumnProperty 12, "ColumnHeadingLine2", "Cost"
.SetColumnProperty 12, "ColumnHorzTextAlign", 2
.SetColumnProperty 12, "DisplayColumnAsCurrency", 1
.SetColumnProperty 12, "HeadingBackgroundColor", 15
.SetColumnProperty 12, "NumberDecimals", 2
.SetColumnProperty 12, "Width", 1.17
'Set Up ValueSets
.SetValueSetName 1, "Budget"
.SetValueSetProperty 1, "Type", 3
.SetValueSetProperty 1, "LineType", 1
.SetValueSetProperty 1, "BarPattern", 1
.SetValueSetProperty 1, "LineColor", 5
.SetValueSetProperty 1, "FillColor", 5
.SetValueSetProperty 1, "Show", "GraphOn"
.SetValueSetProperty 1, "Show", "GraphCumulativeOff"
.SetValueSetProperty 1, "Show", "CurrencyOn"
.SetValueSetProperty 1, "Show", "NumericOff"
.SetValueSetProperty 1, "Show", "GraphCumulativeOn"
.SetValueSetProperty 1, "Type3Column", 11
.SetValueSetName 2, "Actual Cost"
.SetValueSetProperty 2, "Type", 3
.SetValueSetProperty 2, "LineType", 1
.SetValueSetProperty 2, "BarPattern", 1
.SetValueSetProperty 2, "LineColor", 4
.SetValueSetProperty 2, "FillColor", 4
.SetValueSetProperty 2, "Show", "GraphOn"
.SetValueSetProperty 2, "Show", "GraphCumulativeOff"
.SetValueSetProperty 2, "Show", "CurrencyOn"
.SetValueSetProperty 2, "Show", "NumericOff"
.SetValueSetProperty 2, "Show", "GraphCumulativeOn"
.SetValueSetProperty 2, "Type3Column", 12
'Fill Budget and Actual Cost Columns
.PutCell 2, 11, 122
.PutCell 3, 11, 124
.PutCell 4, 11, 322
.PutCell 6, 11, 343
.PutCell 7, 11, 333
.PutCell 8, 11, 222
.PutCell 2, 12, 444
.PutCell 3, 12, 333
.PutCell 4, 12, 22
.PutCell 6, 12, 444
.PutCell 7, 12, 432
.PutCell 8, 12, 121
'Remove Legend and Replace with DataGraph
.SetLegendHeight 0
.SetDataGraphProperty 1, "ClearValueSets", 0
.SetDataGraphProperty 1, "Height", 1
.SetDataGraphProperty 1, "LineBar", "Bar"
.SetDataGraphProperty 1, "ShowGraph", "On"
.SetDataGraphProperty 1, "IncludeValueSet", 1
.SetDataGraphProperty 1, "IncludeValueSet", 2
.Refresh
.keepscheduleopen
End With
End Sub


     
Sub main()

Set objMilestones = CreateObject("Milestones")
With objMilestones
'Start Milestones
    .Activate

'Set to Use 20 Columns
    .Use20Columns

'Set Title
    .SetTitle1 "Type 3 DataGraph Example - OLE Automation"

'Setup Symbols in the ToolBox
    .SetToolboxSymbolProperty 1, "Type", 43
    .SetToolboxSymbolProperty 1, "FillColor", 5
    .SetToolboxSymbolProperty 2, "Type", 44
    .SetToolboxSymbolProperty 2, "FillColor", 5
    .SetToolboxSymbolProperty 3, "Type", 3
    .SetToolboxSymbolProperty 3, "FillColor", 3
    .SetToolboxSymbolProperty 4, "Type", 3
    .SetToolboxSymbolProperty 4, "FillColor", 3

'Setup Horizontal Connectors in the Toolbox
    .SetToolboxHorizontalConnectorProperty 1, "Type", 7
    .SetToolboxHorizontalConnectorProperty 1, "FillColor", 5
    .SetToolboxHorizontalConnectorProperty 2, "Type", 5
    .SetToolboxHorizontalConnectorProperty 2, "FillColor", 3
    .SetToolboxHorizontalConnectorProperty 2, "OutlineColor", 14

'Set Schedule Start and End Dates
    .SetStartAndEndDates "1/1/2004", "12/31/2004"

'Remove Unneeded Columns and Rows From Template
    .SetColumnWidth 1, 0
    .SetColumnWidth 2, 0
    .SetColumnWidth 3, 2.8
    .SetLinesPerPage 8

'Put Text in Task Column
    .PutCell 1, 3, "Project 1"
    .PutCell 2, 3, "Task 1-1"
    .PutCell 3, 3, "Task 1-2"
    .PutCell 4, 3, "Task 1-3"
    .PutCell 5, 3, "Project 2"
    .PutCell 6, 3, "Task 2-1"
    .PutCell 7, 3, "Task 2-2"
    .PutCell 8, 3, "Task 2-3"

'Setup Outline Levels and Summary Bar Settings
    .SetColumnProperty 3, "Indent", 0.3
    .SetOutlineLevel 2, 2
    .SetOutlineLevel 3, 2
    .SetOutlineLevel 4, 2
    .SetOutlineLevel 6, 2
    .SetOutlineLevel 7, 2
    .SetOutlineLevel 8, 2
    .SetSummaryBarDisplay 2

'Add Symbols and Barlines and Remove Gridlines
    .SetScheduleGridlinesAndShades 1, 0, 0, 0, 0, 0, 0
    .SetScheduleVerticalGridlines 3, 0, 0, 0
    .AddSymbol 2, "2/29/2004", 3, 2, 2
    .AddSymbol 2, "9/17/2004", 4
    .AddSymbol 3, "5/18/2004", 3, 2, 2
    .AddSymbol 3, "9/20/2004", 4
    .AddSymbol 4, "7/29/2004", 3, 2, 2
    .AddSymbol 4, "11/4/2004", 4
    .AddSymbol 6, "5/14/2004", 3, 2, 2
    .AddSymbol 6, "10/30/2004", 4
    .AddSymbol 7, "5/21/2004", 3, 2, 2
    .AddSymbol 7, "10/25/2004", 4
    .AddSymbol 8, "5/31/2004", 3, 2, 2
    .AddSymbol 8, "10/25/2004", 4

'Insert Budget and Actual Cost Columns
    .SetCustomColor 1, 128, 255, 128
    .SetCustomColor 15, 255, 255, 128
    .SetFontStyle 17, 0, -1, 18
    .SetColumnProperty 11, "SmartColumn", "Values"
    .SetColumnProperty 11, "ColumnBackgroundColor", 1
    .SetColumnProperty 11, "ColumnHeadingLine1", "Budget"
    .SetColumnProperty 11, "ColumnHeadingLine2", ""
    .SetColumnProperty 11, "ColumnHorzTextAlign", 2
    .SetColumnProperty 11, "DisplayColumnAsCurrency", 1
    .SetColumnProperty 11, "HeadingBackgroundColor", 1
    .SetColumnProperty 11, "NumberDecimals", 2
    .SetColumnProperty 11, "Width", 1.23
    .SetFontStyle 18, 0, -1, 18
    .SetColumnProperty 12, "SmartColumn", "Values"
    .SetColumnProperty 12, "ColumnBackgroundColor", 15
    .SetColumnProperty 12, "ColumnHeadingLine1", "Actual"
    .SetColumnProperty 12, "ColumnHeadingLine2", "Cost"
    .SetColumnProperty 12, "ColumnHorzTextAlign", 2
    .SetColumnProperty 12, "DisplayColumnAsCurrency", 1
    .SetColumnProperty 12, "HeadingBackgroundColor", 15
    .SetColumnProperty 12, "NumberDecimals", 2
    .SetColumnProperty 12, "Width", 1.17

'Set Up ValueSets
    .SetValueSetName 1, "Budget"
    .SetValueSetProperty 1, "Type", 3
    .SetValueSetProperty 1, "LineType", 1
    .SetValueSetProperty 1, "BarPattern", 1
    .SetValueSetProperty 1, "LineColor", 5
    .SetValueSetProperty 1, "FillColor", 5
    .SetValueSetProperty 1, "Show", "GraphOn"
    .SetValueSetProperty 1, "Show", "GraphCumulativeOff"
    .SetValueSetProperty 1, "Show", "CurrencyOn"
    .SetValueSetProperty 1, "Show", "NumericOff"
    .SetValueSetProperty 1, "Show", "GraphCumulativeOn"
    .SetValueSetProperty 1, "Type3Column", 11
    .SetValueSetName 2, "Actual Cost"
    .SetValueSetProperty 2, "Type", 3
    .SetValueSetProperty 2, "LineType", 1
    .SetValueSetProperty 2, "BarPattern", 1
    .SetValueSetProperty 2, "LineColor", 4
    .SetValueSetProperty 2, "FillColor", 4
    .SetValueSetProperty 2, "Show", "GraphOn"
    .SetValueSetProperty 2, "Show", "GraphCumulativeOff"
    .SetValueSetProperty 2, "Show", "CurrencyOn"
    .SetValueSetProperty 2, "Show", "NumericOff"
    .SetValueSetProperty 2, "Show", "GraphCumulativeOn"
    .SetValueSetProperty 2, "Type3Column", 12

'Fill Budget and Actual Cost Columns
    .PutCell 2, 11, 122
    .PutCell 3, 11, 124
    .PutCell 4, 11, 322
    .PutCell 6, 11, 343
    .PutCell 7, 11, 333
    .PutCell 8, 11, 222
    .PutCell 2, 12, 444
    .PutCell 3, 12, 333
    .PutCell 4, 12, 22
    .PutCell 6, 12, 444
    .PutCell 7, 12, 432
    .PutCell 8, 12, 121

'Remove Legend and Replace with DataGraph
    .SetLegendHeight 0
    .SetDataGraphProperty 1, "ClearValueSets", 0
    .SetDataGraphProperty 1, "Height", 1
    .SetDataGraphProperty 1, "LineBar", "Bar"
    .SetDataGraphProperty 1, "ShowGraph", "On"
    .SetDataGraphProperty 1, "IncludeValueSet", 1
    .SetDataGraphProperty 1, "IncludeValueSet", 2
    .Refresh
    .keepscheduleopen
End With
End Sub

To try this example:
Click here to download a Zip file (MilestonesVBExample8.Zip) containing the above VB code.
 
Click here to visit our main programmer's page.