Get variables, servo position in VB 2010

I am attempting to read the position of a servo (channel 0) using the following code in VB 2010 with the minimaestro 6, however I am getting the exception appear in the message box when button 1 is clicked as opposed to the servo position data.

‘Index is out of range of the array’

Does anyone know why this might be?

Thanks
hdavy1234

Code:

Public Class MainWindow

    Public Property Stack As Object
    Dim st As Short()

    ''' <summary>
    ''' Attepts to get variables from the stack
    ''' </summary>
    Public Sub TryGetVariables()
        Try
            Using device As Usc = connectToDevice() ' Find a device and temporarily connect.

                device.getVariables(st)
                MessageBox.Show(st(0).ToString())

                ' device.Dispose() is called automatically when the "Using" block ends,
                ' allowing other functions and processes to use the device.
            End Using
        Catch exception As Exception  ' Handle exceptions by displaying them to the user.
            displayException(exception)
        End Try
    End Sub

    Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        TryGetVariables()
        TextBox2.Text = st(0).ToString
    End Sub

Hello.

It looks like you are using the wrong overload of getVariables; you should use getVariables(out ServoStatus[] servos). ServoStatus is a struct that represents the current status of a channel and is defined in Usc_protocol.cs in the Pololu USB SDK. I modified some of your code and tested it, and it worked. Here is what I changed:

Dim st as ServoStatus()

You can look at the source code of UscCmd in the Pololu USB SDK for an example of how to read channel positions.

- Amanda