Home Up Next

Using SXY/COM in Visual Basic

Here comes a few steps that should the taken to use SXY as a COM application inside Visual Basic.

Creating the SXY Application

Before creating and manipulating graphs and curves, you must start the SXY/COM application:

Public sxycom_obj as Object
sxycom_obj = CreateObject(“SXYCOM.Application”)

Then, you can construct the objects.

Public graph as Object
Public curve as Object
Set graph = sxycom_obj.createSimpleGraph(LINEAR_SIMPLE_GRAPH, 300, 300)
Set curve = sxycom_obj.createArrayCurve()

And manipulate them.

graph.setTitle “Test”
curve.setTitle "Sample Curve"
graph.attachCurveById curve.getId()
graph.redrawGraph
 

Getting Type Information inside Visual Basic

To get information about the the objects and methods available in SXY/COM, you can use the Visual Basic Object browser. To do so, you need to add a reference to SXY/COM type library, as follows:

  1. Go to the “Project” menu;
  2. Select the “References” item;
  3. Find in the list the “SXY/COM Type library” and select it.

Now the SXY/COM types will be accessible in the Object Browser. There you can see the interfaces, their methods and some help about each method. It also allows the use of enumerations members like LINEAR_SIMPLE_GRAPH.

Dealing with Events

The default operation of SXY/COM does not generate events. Nevertheless, the default interface of the graphics can be extended with the use of themes. A theme may add menus and buttons to the default interface. The events generated by these interface elements can be sent to the client application through a Visual Basic function. Do do so, SXY/COM must be started in a different fashion.

Public WithEvents sxycom_obj_evt As sxycom.Application
Public sxycom_obj As Object


Set sxycom_obj_evt = New sxycom.Application
Set sxycom_obj = sxycom_obj_evt

To initialize SXY/COM this way, you must add a reference to its type library inside VB (see the former section). This initialization ensures that Visual Basic will received events from SXY/COM.

 In fact, it generates only one event: genericEvent. It can be captured implementing the following function:

Sub sxycom_obj_evt_genericEvent(ByVal graph As Object, ByVal event_name As String)
‘ Put your code here
End Sub

Notice that the prefix of the function is the name of the variable holding the reference to the SXY/COM object created with New. This variable must be used only for this. You should not call SXY/COM methods on it. Use otherwise the one of type Object.

by Vinícius Almendra