DADiSP Automation Methods

 

DADiSP as an ActiveX Server supports several extremely powerful methods:

 

GetData("src name")

PutData("des name", data)

GetComplexData("src name", real data, imag data, type)

PutComplexData("des name", real data, imag data, type)

GetComplexSeries("src name", real arrau, imag array, type)

PutComplexSeries("des name", real array, imag array, type)

Execute("command string")

Quit(verify)

 

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".

 

The Dim DADiSP As Object statement declares DADiSP as an ActiveX object. Set DADiSP = CreateObject("DADiSP.Application") establishes a connection between Visual Basic and DADiSP. 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

DADiSP.PutData "W1", VBData

 

 

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

 

''' Put data to DADiSP

DADiSP.PutData "DArray", VBData

DADiSP.PutData "DNum", 12.3

 

''' Get data from DADiSP

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)

DADiSP.Execute("NewWorksheet(2, 0)")

 

''' Generate Random Data

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.

 

The Calculate method combines the functionality of Execute and PutData  method to execute a DADiSP function by directly passing client based data values.

 

Dim DADiSP as Object

Dim val as Variant

 

Connect to DADiSP

Set DADiSP = CreateObject("DADiSP.Application")

 

Create a 2 Window Worksheet without prompting

Call DADiSP.Execute("Newworksheet(2, 0)")

 

Generate 10x3 random array, return result as a variant

val = DADiSP.Calculate("rand", 10, 3)

 

The position of the input arguments can also be specified by the $1, $2, etc. placeholder variables.

 

Dim DADiSP as Object

Dim val as Variant

 

Connect to DADiSP

Set DADiSP = CreateObject("DADiSP.Application")

 

Create a 2 Window Worksheet without prompting

Call DADiSP.Execute("Newworksheet(2, 0)")

 

Generate a scaled 100 point random series with formula

Call DADiSP.Calculate("W1 := gnorm($1, 1)*$2", 100, 10)

 

Now for a full example of ActiveX with Visual Basic controlling DADiSP. We'll create a VB routine to perform the following steps:

  1. create data in Visual Basic

  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)

DADiSP.Execute("NewWorksheet(2, 0)")

 

''' Put Array to DADiSP

DADiSP.PutData "W1", VBData

 

''' Label W1

DADiSP.Execute("Label('Data from Visual Basic')")

 

''' Moveto W2

DADiSP.Execute("Moveto(W2)")

 

''' Calculate Power Spectrum

DADiSP.Execute("PSD(Hamming(W1))")

 

''' Add Y Log and Grids

DADiSP.Execute("SetyLog(1);GridSol;GridHV")

 

''' Show DADiSP

DADiSP.Visible = 1

 

''' Get PSD from DADiSP

newdata = DADiSP.GetData("W2")

 

End Sub

 

The DADiSP.Visible = 1 statement is an example of setting the "visibility" property to make DADiSP appear on the screen. You could also use the DADiSP setvisible function: DADiSP.Execute("SetVisible(1)")