Reference Materials > How to Extract Information from a Variant

Previous | Next

How to Extract Information from a Variant

The Variant information returned by the Active X controls is not always easy to work with. We can extract certain information from the variant. When the Active X control gets data from a hardware device it places each sample into an array such as the following: A(0) = sample1; A(1)=sample2; A(2)=sample3; and so on. When there are multiple channels the software stores them in order according to the channel list. If there are three channels it would store them as follows: A(0)=sample1 from the first channel; A(1)=sample1 from the second channel; A(2)=sample1 from the third channel; A(3)=sample2 from the first channel; and so on. Note the following program in Visual Basic:

Dim V As Variant

 

Private Sub DataqSdk1_ NewData(ByVal Count As Integer)

'the data will be returned to V as a Variant

V = DataqSdk1. GetData

'cn = number of channels minus 1

cn = UBound(V, 1)

'pts = number of data points minus 1

pts = UBound(V, 2)

'create an array to accept channel 1 data

ReDim Channel1(0, 0 To pts) As Integer

For i = 0 To pts

    Channel1(0, i) = V(0, i)

Next

'plot channel 1

DQChart1. Chart (Channel1)

'plot all channels

DQChart2. Chart (V)

End Sub

 

Private Sub Start_Click()

DataqSdk1. ADChannelCount = 2

DataqSdk1. EventPoint = 10

DataqSdk1. Start

End Sub

 

Private Sub Stop_Click()

DataqSdk1. Stop

End Sub

 

Using and extracting information from a variant is slightly different in VB.NET. Consult your program's help files for more information regarding variants. Use the following example as a guideline to get you started.

 

VB.NET

 

To access the data returned by GetData, instead of using a variant, declare it as a "short" directly. Note the following example:

 

Public Class Form1

Inherits System.Windows.Forms.Form

Dim v(,) As Short

#Region " Windows Form Designer generated code "

....

#End Region

 

Private Sub AxDataqSdk1_NewData(ByVal sender As Object, ByVal e As AxDATAQSDKLib._DDataqSdkEvents_NewDataEvent) Handles AxDataSdk1.NewData

     v = AxDataSdk1.GetData()

     ' the data can be accessed as v(chn, pt),

     ' where chn=0 for the first channel,

     ' pt =0 for the first pts

End Sub

 

 

Top