Domino Code Fragment

Code Name*
OLE/ActiveX
Date*
07/10/2001
Source (or email address if you prefer)*
jaideep_pv@yahoo.com
IP address:.202.88.224.191
Description*
We have used "Olectra" as an Embeded Object to get a graphical display of charts.
The values are passed to the properties of the object.
The graph is displayed by calling the form containing the embeded object using ws.composedocument.
Type*
LotusScript
Categories*
OLE/ActiveX Integration
Implementation:
Modify code
Required Client:
IE5
Server:
5.1
Limitations:
This does not work in the
browser.
Comments:
How can I display this in the browser ?
Files/Graphics attachments (if applicable): Code:
Agent Initialize
Call Main("SATTV", "Statistical Analysis\Tickets by Type")
============================================================
Main Function
Sub Main(viewName As String, message As String)
'viewName is the alias name of the view
'message is the full name of the view - This is used while showing the error messages

On Error Goto Escape
'Declarations
Dim session As New NotesSession
Dim ws As New NotesUIWorkSpace
Dim uiDoc As NotesUIDocument

'Initializing
Set db=session.CurrentDatabase
Set view=db.GetView(viewName)
Set attachView=db.GetView("Attachment")

'Check the platform
IsNT="No"
plat=Evaluate("@Platform([SPECIFIC])")
Forall v In plat
If v="Windows/NT" Then
IsNT="Yes"
End If
End Forall

If IsNT = "Yes" Then
Call IsPlatformNT()
Else
Call IsPlatformNotNT()
End If

If ContinueInstall = "No" Then Exit Sub 'Exit if Chart not installed


Print "2dBar Chart Options............................ .........................................................."

If view Is Nothing Then
answer% = Msgbox ("Unable to find the '" + message + "' view", 16,"Help Desk")
Exit Sub
End If
Set doc=View.GetFirstDocument
If doc Is Nothing Then
answer% = Msgbox ("No documents found in the '" + message + "' view", 16,"Help Desk")
Exit Sub
End If

If viewName = "SATHV" Then 'Statistical Analysis\Turnaround Time
OptionSelected=1
Else
If Not ws.DialogBox ("Chart Options1", True, True, False, False, False, False, "Help Desk", doc) Then
Exit Sub
End If
OptionSelected=doc.ChartOptions(0)
Print "Building 2dBar Chart ............................ .........................................................."
End If



Call GenerateKeyInFo(viewName) 'Get the Key Info into an array
maxofChartTexts=arraycount
maxofChartValues=arraycount
arraycount=0

'Shift with respect to the option which user has selected
Select Case OptionSelected
Case 1:
Call TotalNoOfTickets(viewName)
Case 2:
Call TotalHoursSpent(viewName)
Case 3:
Call AvgMinutesSpentPerTicket(viewName)
Case 4:
Call AvgHoursTicketIsOpen(viewName)
Case 5:
Call AvgTurnaroundTimeInHours() 'Statistical Analysis\Turnaround Time
Case 6:
Call TotalTurnaroundTimeInHours() 'Statistical Analysis\Turnaround Time
End Select

Set uiDoc=ws.composeDocument("","","Chart2d")
Print "Building 2dBar Chart ............................ .........................................................."

'Generating the bar Chart
Set OlecChart = uiDoc.GetObject("Chart2D1")
If Isunknown (OlecChart) Then 'Check if Olectra Chart is installed in the System
Messagebox "The file 'REGSVR32.EXE' is not found in the Windows system directory. The Olectra control is not registered and so the "_
& "chart will not be displayed. To register the Olectra Chart component, contact your System Administrator for the 'REGSVR32.EXE' and "_
& "follow the instructions given below:" _
& Chr(10) & Chr(10) & "From the start menu, run the following:" & Chr(10) & Chr(10) & "1) For Windows 95/98 :- 'regsvr32 c:\windows\system\olch2x32.ocx'" _
& Chr(10) & "2) For Windows NT/2000 :- 'regsvr32 c:\winnt\system32\olch2x32.ocx'" , 16, "File not found."
Call uiDoc.Close
Exit Sub
End If

'set off the properties window in run time
OlecChart.AllowUserChanges = False
'set the NumSeries for chart
OlecChart.ChartGroups(1).Data.NumSeries =maxofChartTexts

'show no precision for Y axis
If OptionSelected = 1 Then
OlecChart.ChartArea.Axes("Y").Precision.Value = 0
End If
'draw the chart
For row = 1 To maxofChartTexts
OlecChart.ChartGroups(1).Data.y(row, 1) = ChartValues(row)
OlecChart.Header.Text = TitleText
OlecChart.ChartGroups(1).SeriesLabels.Add ChartTexts(row)
Next row

'show legend
With OlecChart.Legend
.IsShowing = True
.Font.Size = 8
.Orientation = 1 'oc2dOrientHorizontal
.Border = 1 'oc2dBorder3dOut
End With
Print "Done."
Exit Sub

Escape:
If Err()=8501 Then 'This error will occur if Olectra Chart is not installed.
answer% = Msgbox (Error() +Chr(13)+Chr(13)+"You must have Olectra Chart installed in order to create charts.", 16,"Help Desk")
Call uiDoc.Close
Exit Sub
End If
If Err = 53 Then 'file not found - regsvr32.exe
Messagebox "The file 'REGSVR32.EXE' is not found in the windows system directory. The Olectra control is not registered and so the "_
& "chart will not be displayed. To register the Olectra Chart component, contact your System Administrator for the 'REGSVR32.EXE' and "_
& "follow the instructions given below:" _
& Chr(10) & Chr(10) & "From the start menu, Run the following:" & Chr(10) & Chr(10) & "1) For Windows 95/98 :- 'regsvr32 c:\windows\system\olch2x32.ocx'" _
& Chr(10) & "2) For Windows NT/2000 :- 'regsvr32 c:\winnt\system32\olch2x32.ocx'" , 16, "File not found."
End If
Msgbox Cstr(Err) & Error
'To handle all other errors
answer% = Msgbox ("An error '"+Error() +"' has occured.", 16,"Help Desk")
Exit Sub
End Sub
======================================================================Function to check Platform
Sub IsPlatformNT()
pathName1 = "C:\WinNT\System32\olch2x32.ocx"

pathName2 = "C:\WinNT\System32\olchart.lic"

fileName1 = Dir$(pathName1, 0)
fileName2 = Dir$(pathName2, 0)
If fileName1="" Or fileName2 = "" Then
If attachView Is Nothing Then
answer% = Msgbox ({Unable to find the view Attachment for Charting.}, 16,"ProjecTrak Help Desk")
ContinueInstall = "No"

Exit Sub
End If
Set doc=attachView.GetFirstDocument
If Not doc Is Nothing Then
Print "Detaching files into 'C:\WinNT\System32' Directory ........................................................"
'Set rtitem=doc.GetFirstItem("AttachmentCharting")
Set rtitem=doc.GetFirstItem("Attachment")
If (rtitem.Type=RICHTEXT) Then
Forall o In rtitem.EmbeddedObjects
If (o.Type=EMBED_ATTACHMENT) Then

Call o.ExtractFile("C:\WinNT\System32\" & o.Source) 'Extract Olectra files
End If
End Forall
'Register the olectra chart control
registerOCX% = Shell("regsvr32 c:\winnt\system32\olch2x32.ocx")
End If
Else
answer% = Msgbox ({Unable to find documents in the view Attachment for Charting.}, 16,"Help Desk")
ContinueInstall = "No"
Exit Sub
End If
End If

End Sub
====================================================================
Public Function GenerateKeyInfo(ViewName As String)

'The key is the first viewable categorized column of each Statistical Analysis vew
On Error Goto Escape

Redim ChartTexts(0) As String
arraycount=0
Set doc=View.GetFirstDocument
While Not doc Is Nothing 'Loop through the view
Select Case viewName
Case "SATAV", "SATURNV": 'Statistical Analysis\Tickets by Assignee, 'Statistical Analysis\Turnaround Time
If doc.AssignedTo(0) = "" Then
keyText = "Unassigned"
Else
keyText = doc.AssignedTo(0)
End If
Case "SATCV": 'Statistical Analysis\Tickets by Caller
If doc.Caller(0) = "" Then
keyText = "Anonymous"
Else
keyText = doc.Caller(0)
End If
Case "SATDV": 'Statistical Analysis\Tickets by Day
keyText = Cstr(doc.DayDiscovered(0))
Case "SATMV": 'Statistical Analysis\Tickets by Month
keyText = Cstr(doc.MonthDiscovered(0))
Case "SATHV": 'Statistical Analysis\Tickets by Hour
keyText = Cstr(doc.HourSpanDiscovered(0))
Case "SATPV": 'Statistical Analysis\Tickets by Priority
keyText = doc.TicketPriority(0)
Case "SATTV": 'Statistical Analysis\Tickets by Type
If doc.KnowledgeBaseType(0) = "" Then
keyText = "Unspecified Category"
Else
keyText = doc.KnowledgeBaseType(0)
End If
End Select

For k=1 To arraycount 'Searching to check if the keyText already exists in array.
Exists="No"
If Ucase(ChartTexts(k))=Ucase(keyText) Then 'Skip to next if exists
Exists="Yes"
Goto incrementarray
End If
Next
incrementarray:
If exists<>"Yes" Then 'Incrementing array by 1 and set new value
arraycount=arraycount+1
Redim Preserve ChartTexts(arraycount) As String
ChartTexts(arraycount)=keyText
End If
Set doc=View.GetNextDocument(doc)
Wend
'Exit Sub
Escape:
answer% = Msgbox ("An error ' "+Error() +" ' has occured.", 16,"Help Desk")
'Exit Sub
End Function
======================================================================Sub TotalNoOfTickets(ViewName As String)
On Error Goto Escape

'Initialize the array with value=0
Redim ChartValues(maxofChartValues) As Double
Dim assignedTo As String
For i=1 To maxofChartValues
ChartValues(maxofChartValues)=0
Next

'Loop through the view
Set doc=View.GetFirstDocument
While Not doc Is Nothing
Select Case viewName
Case "SATAV": 'Statistical Analysis\Tickets by Assignee
If doc.AssignedTo(0) = "" Then
compareText = "Unassigned"
Else

compareText = doc.AssignedTo(0)

End If



Case "SATCV": 'Statistical Analysis\Tickets by Caller
If doc.Caller(0) = "" Then
compareText = "Anonymous"
Else
compareText = doc.Caller(0)
End If
Case "SATDV": 'Statistical Analysis\Tickets by Day
compareText = Cstr(doc.DayDiscovered(0))
Case "SATMV": 'Statistical Analysis\Tickets by Month
compareText = Cstr(doc.MonthDiscovered(0))
Case "SATHV": 'Statistical Analysis\Tickets by Hour
compareText = Cstr(doc.HourSpanDiscovered(0))
Case "SATPV": 'Statistical Analysis\Tickets by Priority
compareText = doc.TicketPriority(0)
Case "SATTV": 'Statistical Analysis\Tickets by Type
If doc.KnowledgeBaseType(0) = "" Then
compareText = "Unspecified Category"
Else
compareText = doc.KnowledgeBaseType(0)
End If
End Select

For i=1 To maxofChartTexts 'Loop through the item in the 'ChartTexts' array
If Ucase(compareText)=Ucase(ChartTexts(i)) Then
ChartValues(i)=ChartValues(i)+1 'if there is a match, increment the counter
Goto GetNext
End If
Next
GetNext:
Set doc=View.GetNextDocument(doc)
Wend
TitleText="Total Number of Calls"
Exit Sub
Escape:
answer% = Msgbox ("An error ' "+Error() +" ' has occured.", 16,"Help Desk")
Exit Sub

End Sub
========================================================================