Getting and Setting Control Values
Previous  Top  Next


Getting and setting control values is a little tedious, as some development environments are not very good at dealing with ActiveX array properties.

Before looking at the values of the control, the MixerNumber, DestNumber, SourceNumber and ControlNumber properties must be set to select the particular control under consideration. That might be done (for example) as part of an enumeration process, or alternatively using the FindControl method. See the previous topics in this chapter for examples.

Once a control is selected, we need to find out how many values it has, and what limits the values can take. An on/off switch will have one value; a volume control will normally have one or two values; a multiplexer will typically have more. We can find out using the GetControlInfo method:



' Note that 'controlType', 'nValues' and 'disabled' are short (16-bit) integers whilst 'minValue' and 'maxValue' are long (32-bit) integers

errorCode = MC.GetControlInfo( controlType, nValues, disabled, minValue, maxValue )
If
 errorCode<>MSSMERR_NOERROR Then
    ' Error handling here

End
 If



Assuming this method succeeds, we now know:
·How many values there are (nValues)  
·What the minimum (minValue) and maximum (maxValue) values are that can be set  

So we can now find out what the current control settings are by using the GetControlValue method:



For
 i=0 To nValues-1
    currentValue(i) = MC.GetControlValue(i)
    If
 currentValue(i)=MSSMIX_VALUE_INVALID Then
        ' Could not get the value, for some reason. Handle the error here

    End
 If
Next




To set the values, we have to put the new values into the holding array by using the PutNewControlValue method. Suppose the control is a volume control, and we wish to set the volume to maximum. We first use PutNewControlValue to set the new values into the holding array, then the CommitNewControlValue method to set the control with these values:



' First, set the new control values:
For
 i=0 To nValues-1
    MC.PutNewControlValue(i, maxValue)
Next

' Then transfer them to the control:

errorCode = MC.CommitNewControlValue
If
 errorCode<>MSSMERR_NOERROR Then
    ' The control was not set properly. Handle the error here.

End
 If