Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

Get DataSocket array values

I'm using the datasocket component (VB6) to read and plot data from a text file stored on a local network. The file contains 100 values and everything works fine, but I can't figure out how to access the individual elements of the CWData array on the update event.

Does anybody know how to do this?

Thanks,

Curt
0 Kudos
Message 1 of 8
(7,390 Views)
Data is always accessible via the Value property of the CWData object. If you are calling CWDataSocket.Update, you can then get the current value from the CWDataSocket.Data property to get the updated CWData object, then get the Value property. If you are using the CWDataSocket.OnDataUpdated event, you can get the current value from the Value property of the Data parameter that is passed to the event.

The CWData.Value property is a Variant. If it currently contains array data, you can create a local array variable of the desired type, assign the Value property to this local variable, then access the elements of the array. For example, if the 100 values were double values, you could do something like this:

Dim values() as Double
values = Data.Value
'
Now access array values via the local values variable.

- Elton
0 Kudos
Message 2 of 8
(7,390 Views)
Thanks Elton, but that didn't work

Curt
0 Kudos
Message 3 of 8
(7,390 Views)
How did it not work? What was the error?

- Elton
0 Kudos
Message 4 of 8
(7,390 Views)
Private Sub CWDataSocket1_OnDataUpdated(ByVal Data As CWDSLib.CWData)

Dim values() As Double

On Error GoTo ErrorHandler
values = Data.Value

Graph3.PlotY Data.Value

Debug.Print values(0)

Exit Sub

ErrorHandler:

Debug.Print Err.Number & " " & Err.Description
End Sub

error message

9 Subscript out of range
0 Kudos
Message 5 of 8
(7,390 Views)
Does the graph plot an array of data in this example? Also, is the lower bounds of the array 0? Here's an example that you can test:


  • Create a new VB6 project. Go to Project->Components and check DataSocket and CW UI.

  • Add a button, a graph, and two DataSocket controls to the form. Name one DataSocket control Reader and name the other one Writer.

  • Select the Reader DataSocket control and go to the Properties window. Set AccessMode to "3 - cwdsReadAutoUpdate", set AutoConnect to true, and set URL to dstp://localhost/test.

  • Select the Writer DataSocket control and go to the Properties window. Set AccessMode to "5 - csdsWriteAutoUpdate", set AutoConnect to true, and set URL to dstp:
    //localhost/test.

  • Add the following code:

    Private Sub Command1_Click()
    Dim values(99) As Double

    Dim i As Integer
    For i = 0 To 99
    values(i) = Rnd * 10
    Next

    Writer.Data.Value = values
    End Sub

    Private Sub Reader_OnDataUpdated(ByVal data As CWDSLib.CWData)
    If IsArray(data.Value) Then
    CWGraph1.PlotY data.Value

    Dim values() As Double
    values = data.Value

    MsgBox _
    "TypeName(values): " & TypeName(values) & vbCrLf & _
    "LBound(values): " & LBound(values) & vbCrLf & _
    "UBound(values): " & UBound(values) & vbCrLf & _
    "values(0): " & values(0)
    End If
    End Sub

    Note that the IsArray check is there because the reader will read the current data when it connects. Before we've written the array, the default value is a Long value set to 0.

  • Run the DataSocket server application, then run the VB application.

  • ul>

    What do you see when you click the button? On my machine, I see:

    TypeName(values): Double()
    LBound(values): 0
    UBound(values): 99
    values(0): 7.05547511577606

    - Elton
0 Kudos
Message 6 of 8
(7,390 Views)
Hi Elton,

I get the same result.
When I set the Reader URL to the text file on my
local server, the data is plots ok, but I get the same array error I was getting before.

Curt
0 Kudos
Message 7 of 8
(7,390 Views)
I'm having trouble reproducing what you're seeing. Could you please post a small test project that reproduces the error? Thanks.

- Elton
0 Kudos
Message 8 of 8
(7,390 Views)