Download Now | Pricing / Purchase 


ActiveX is a broad term that generally refers to a Microsoft binary standard for sharing code and data between separate programs or "components". The actual protocol is specified by the Component Object Model (COM). COM has undergone many upgrades and enhancements since its original introduction as Object Linking and Embedding (OLE).

ActiveX Automation

One important feature of COM is Automation. Automation allows a "client" program to control a "server" or component program just as if the component functionality was built into the client. For example, DADiSP can fully control Microsoft Word, placing a DADiSP Worksheet into a document and printing the results all from within DADiSP. Likewise, a Visual Basic program can hand off data to DADiSP for processing without DADiSP ever being visible to the user. In this way, DADiSP acts as a powerful data analysis library for any program that supports Automation.

ActiveX components generally expose three basic constructs: Properties represent the various settings of the component such as color, font, size, etc.

Events are notifications the component makes to the client program. Some possible events are mouse was clicked, canvas was sized, button was pushed, etc. After receipt of the notification, the client can respond appropriately.

Methods are functions the client program can direct the component to execute.

DADiSP Automation Server

DADiSP as an ActiveX server or component supports several extremely powerful methods, including: Getdata retrieves data from a DADiSP Window or variable to the client. For example, here's a Visual Basic code fragment that obtains the series in W2 of a DADiSP Worksheet into a Visual Basic variable:

Dim DADiSP As Object ''' Connect to DADiSP Set DADiSP = CreateObject("DADiSP.Application") VbVar = DADiSP.Getdata("W2")

In this example, Visual Basic acts as the "client" and DADiSP the ActiveX "server".

We declare DADiSP as an ActiveX object with the

Dim DADiSP As Object

declaration. Visual Basic establishes a connection to DADiSP with the

Set DADiSP = CreateObject("DADiSP.Application")

statement. The connection is made by checking the Registry for ActiveX components and capabilities. For faster ActiveX communication, DADiSP also provides a COM "Type Library" (dadisp.tlb) that provides in depth information on the ActiveX capabilities offered by DADiSP. Finally,

VbVar = DADiSP.Getdata("W2")

copies the series or table in W2 into the Visual Basic array VbVar. ActiveX data transfers are quite flexible and efficient. DADiSP transparently supports multi-column data using the COM standard SafeArray. Byte, Integer, Float, and Double scalar values are also supported.

Here's a code fragment that generates a Visual Basic array and then transfers the array to DADiSP.

''' Create VB Data Array For i = 0 To 999 VBData(i) = Rnd() Next i ''' Connect to DADiSP Set DADiSP = CreateObject("DADiSP.Application") ''' Put Array to DADiSP Call DADiSP.PutData("W1", VBData)

You can also "get" or "put" data to a DADiSP variable. For example:

Call DADiSP.PutData("DArray", VBData) Call DADiSP.PutData("DNum", 12.3) Vb1 = DADiSP.GetData("DArray") Vb2 = DADiSP.GetData("DNum")

Here we transfer an array and a scalar to the DADiSP variables DArray and DNum and then retrieve the data from DADiSP back to Visual Basic.

The Execute method is perhaps the most powerful. Execute allows any DADiSP command, including SPL routines, built-in functions, macros and command files to be executed from ActiveX. For example, the following code fragment creates a 2 Window Worksheet and generates a 1000 point random series in DADiSP:

''' Create a 2 Window Worksheet (unconditional) Call DADiSP.Execute("NewWorksheet(2, 0)") ''' Generate Random Data Call DADiSP.Execute("Grand(1000,.01)")

Because Execute accepts any valid DADiSP command as input, all the features, functions and capabilities of DADiSP are available to any program that supports ActiveX Automation.

Now for a full example of ActiveX with Visual Basic controlling DADiSP. We'll use each of the above methods to 1) create data in VB, 2) transfer it to DADiSP, 3) use DADiSP to process the data and 4) retrieve the processed result from DADiSP.

Sub DSPTest() Dim DADiSP As Object Dim VBData(1000) As Double ''' Create VB Data Array For i = 0 To 999 VBData(i) = Rnd() Next i ''' Connect to DADiSP Set DADiSP = CreateObject("DADiSP.Application") ''' Create a 2 Window Worksheet (unconditional) Call DADiSP.Execute("NewWorksheet(2, 0)") ''' Put Array to DADiSP Call DADiSP.PutData("W1", VBData) ''' Label W1 Call DADiSP.Execute("Label('Data from VB')") ''' Moveto W2 Call DADiSP.Execute("Moveto(W2)") ''' Calculate Power Spectrum Call DADiSP.Execute("PSD(Hamming(W1))") ''' Add Y Log and Grids Call DADiSP.Execute("SetyLog(1);GridSol;GridHV") ''' Show DADiSP DADiSP.Visible = 1 ''' Get PSD from DADiSP newdata = DADiSP.GetData("W2") End Sub

To make DADiSP appear on the screen, we set the "visibility" property with:

DADiSP.Visible = 1

You could also use the DADiSP SETVISIBLE function:


DADiSP Automation Client

So far, we've shown examples of controlling DADiSP from Visual Basic. In this case, Visual Basic is the "client" and DADiSP acts as the ActiveX "server". However, DADiSP can also function as an ActiveX client to control and make use of the features of ActiveX servers such as Excel, Word, database programs or data acquisition drivers.

The DADiSP SPL syntax for ActiveX is very similar to the Visual Basic syntax mentioned above. For example, to connect to an ActiveX object, you use the CreateObject function. Properties can be set and retrieved with standard variable assignments and methods executed with the "dot" syntax. For example, the following SPL code fragment connects to Word and makes it visible:

/* start and display Word using ActiveX */ ShowWord() { local word; // start Word word = CreateObject("Word.Application"); // let's see it! word.Visible = 1; }

DADiSP can access any function exposed by the ActiveX Automation server. For example, Word has a very elaborate ActiveX hierarchy, consisting of Documents, Ranges, Tables and a host of other objects all accessible to DADiSP.

Finally, the full SPL example below demonstrates the use of these objects to create and copy a DADiSP Worksheet to a Word document.

// SPL Code: DADiSP to MS Word ActiveX calls msw() { local word, doc; // new 2 Window worksheet if (newworksheet(2) == 0) return; // generate noisy sine in W1 gnorm(1000,.01) * 0.1 + gsin(1000,.01); // set units to Volts setvunits("V"); // add a nice label label("Noisy Sinewave"); // moveto W2 moveto(w2); // set log scales setxlog(1); setylog(1); // calculate the PSD psd(w1); // copy worksheet into clipboard copyworksheet(); // start Word word = CreateObject("Word.Application"); // get "Document" object doc = word.Documents; // Add a new Document and get range object range = doc.Add().Range(); // paste worksheet as Enhanced Metafile word.Selection.PasteSpecial(0, 0, 0, 0, 9); // let's see it! word.Visible = 1; }

In conclusion, ActiveX is a very powerful, standardized means of sharing the capabilities of separate programs in a flexible and robust manner. The SPL\ActiveX subdirectory included with your DADiSP distribution provides several additional examples of using ActiveX with DADiSP.