.NET Example: Complex Properties and Methods

Procedure

  1. Click the Popup button to the right of the Action field.
  2. Select New Script on the Popup menu.
  3. Right-click the Edit Script window in the location where the method should be inserted.

    Note: In this script, the method is entered under the rs.Open line.

  4. Select ActiveX Methods>Call on the extended Popup menu.

    An Edit Method dialog box opens.

  5. Select and enter the following.
    Field Select/Enter
    A Method name DataBindTable. Note: Select the method from a dropdown list of methods.
    B DataSource rs (Recordset variable name in the script)
    C xField String column in the selected table. Example "CustomerID"
    D Click OK.
    Result. The Edit Method dialog box closes; the line created from your selections and entries is entered into the script where you opened the Popup menu.
    1. Chart: Test the Script - Part 1
    1. Compile the script; close the Edit Script window.
    2. Close the control's Properties - Object dialog box.
    3. Click the Test Button on the CimEdit Ribbon bar.

Results

If the configuration is correct .NET Chart displays as a bar chart with data pulled from SQL Server.

Chart: Script - Part 2

Since the Generic ActiveX Wrapper exposes component events defined by an underlying .NET control as ActiveX events, they can be handled with CimEdit scripting.

1 Chart: Add three mouse events.
2 Chart: Complete (sample) script: Parts 1 and 2.
3 Chart: Test the Script - Parts 1 and 2.
  1. Chart: Add Three Mouse Events
Note:
  • This configuration that demonstrates rotating the chart using MouseMove handler logic is simplified to emphasize the main points of event handling.
  • The mouse event handlers that will be used are converted by the Data Conversion module from the corresponding .NET mouse event handlers.

Key event handlers are also converted to the forms similar to their respective Win32 key messages.

  1. Re-open the control chart's Properties - Object dialog box.
  2. Select Events.
  3. Add events and create new scripts as follows.
1 Add a MouseDown event. Create a new script.
2 Add a MouseMove event. Create a new script
3 Add a MouseDown event. Create a new script.

The chart's script will now include three additional event handlers.

Sub OnMouseDown(state As Long, x As Long, y As Long)
 
End Sub
 
Sub OnMouseMove(state As Long, x As Long, y As Long)
 
End Sub
 
Sub OnMouseUp(state As Long, x As Long, y As Long)
 
End Sub
Note:
  • The .NET control events have the conventional two-parameter signature,
  • Sender (Object)
  • e (EventArg)

However, the Data Conversion module has converted these mouse events into those with Win32-style parameters.

  • The x and y values are the x and y coordinates of the mouse pointer
  • The state value is the mouse button state (not used here).
  1. Add a mouse down state variable and some simple handling code.
Sub OnMouseDown(state As Long, x As Long, y As Long)
    mouseDown = True
End Sub
Sub OnMouseMove(state As Long, x As Long, y As Long)
    If mouseDown = True Then
        area.Area3DStyle.Inclination = (x Mod 90) / 2
        area.Area3DStyle.Rotation = (y Mod 180) / 2
    End If
End Sub
Sub OnMouseUp(state As Long, x As Long, y As Long)
    mouseDown = False
End Sub
 
Private Sub Chart1_MouseUp(ByVal state As Long, ByVal x As Long, ByVal y As Long)
    mouseDown = False
End Sub
  1. Add Private mouseDown As Boolean to the beginning of the script.
Private cimOleObj As Occ_System_Windows_Forms_DataVisualization.IOccChart
Private area As Object
Private mouseDown As Boolean
                        
  1. Compile the script; close the Edit Script window and Properties - Object dialog box.
  1. Chart: Complete (Sample) Script: Parts 1 and 2

This is the complete (sample) script (Parts 1 and 2) that includes pulling data from SQL server and using mouse events to rotate the chart.

Private cimOleObj As Occ_System_Windows_Forms_DataVisualization.IOccChart
Private area As Object
Private mouseDown As Boolean
 
Sub OnScreenOpen()
    Dim conn As Object
    Dim rs As Object
    Dim series As Object
 
    Set area = cimOleObj.ChartAreas.Add("area1")
    area.BackColor = &H8000FF00
    area.Area3DStyle.Enable3D = True
    
    Set conn = CreateObject("ADODB.Connection")
    Set rs = CreateObject("ADODB.Recordset")     
    conn.ConnectionString = "Provider=SQLNCLI10;Data Source=.\sqlexpress;" _
        & "AttachDbFilename=C:\SQLSampleDatabases\NORTHWND.MDF;Integrated Security=SSPI;"
    
    conn.Open
    rs.Open "Select Top 12 CustomerID, Freight from Orders", conn
    cimOleObj.DataBindTable rs, "CustomerID"
    rs.Close    
    conn.Close
    Set series = cimOleObj.Series.Item(0)
    series.ChartType = SeriesChartType_Column
    series.SetCustomProperty "DrawingStyle", "Cylinder"
End Sub
Sub OnMouseDown(state As Long, x As Long, y As Long)
    mouseDown = True
End Sub
Sub OnMouseMove(state As Long, x As Long, y As Long)
    If mouseDown = True Then
        area.Area3DStyle.Inclination = (x Mod 90) / 2
        area.Area3DStyle.Rotation = (y Mod 180) / 2
    End If
End Sub
Sub OnMouseUp(state As Long, x As Long, y As Long)
    mouseDown = False
End Sub
 
Private Sub Chart1_MouseUp(ByVal state As Long, ByVal x As Long, ByVal y As Long)
    mouseDown = False
End Sub
 
  1. Chart: Test the Script - Parts 1 and 2

The chart should rotate as you hold the mouse button down and move it.

Chart: Script: Part - 3

More sophisticated code than the mouse handling logic used in Sample Script 1 is needed to make the graph move more smoothly in rotation and inclination.

1 Chart: Complete (sample) script: Parts 1 and 3.
2 Chart: Test the script - Parts 1 and 3
  1. Chart: Complete (Sample) Script: Parts 1 and 3

The following chart graph uses the same event handling script used in Sample Script 1, but selects two numeric columns from another table.

Replace the code in Sample Script - Parts 1 and 2 from the conn.Open line in the OnScreenOpen( ) subroutine to the End Sub with the code that is now in that location.

Private cimOleObj As Occ_System_Windows_Forms_DataVisualization.IOccChart
Private area As Object
Private mouseDown As Boolean
Sub OnScreenOpen()
    Dim conn As Object
    Dim rs As Object
    Dim series As Object
 
    Set area = cimOleObj.ChartAreas.Add("area1")
    area.BackColor = &H8000FF00
    area.Area3DStyle.Enable3D = True
    
    Set conn = CreateObject("ADODB.Connection")
    Set rs = CreateObject("ADODB.Recordset")     
    conn.ConnectionString = "Provider=SQLNCLI10;Data Source=.\sqlexpress;" _
        & "AttachDbFilename=C:\SQLSampleDatabases\NORTHWND.MDF;Integrated Security=SSPI;"
    
    conn.Open
    rs.Open "select Top 50 OrderID, UnitPrice, Quantity from [Order Details]", conn
    cimOleObj.DataBindTable rs, "OrderID"
    rs.Close    
    conn.Close
    Set series = cimOleObj.Series.Item(0)
    series.ChartType = SeriesChartType_Column
    series.SetCustomProperty "DrawingStyle", "Cylinder"
    Set series = cimOleObj.Series.Item(1)
    series.ChartType = SeriesChartType_Column
    series.SetCustomProperty "DrawingStyle", "Cylinder"
End Sub
Sub OnMouseDown(state As Long, x As Long, y As Long)
    mouseDown = True
End Sub
Sub OnMouseMove(state As Long, x As Long, y As Long)
    If mouseDown = True Then
        area.Area3DStyle.Inclination = (x Mod 90) / 2
        area.Area3DStyle.Rotation = (y Mod 180) / 2
    End If
End Sub
Sub OnMouseUp(state As Long, x As Long, y As Long)
    mouseDown = False
End Sub
 
Private Sub Chart1_MouseUp(ByVal state As Long, ByVal x As Long, ByVal y As Long)
    mouseDown = False
End Sub
  1. Chart: Test the Script - Parts 1 and 3

If the script details have been entered correctly two columns will display. The chart should also rotate more smoothly.