HEM Data Support: Helpful Hints
Navigation

Reading Snap-Master’s Instrument List Using Front Panel Library

For users with Snap-Master version 3.0 and later, the GetSMInsList routine shipped with older versions of Front Panel Library does not return the proper list of instruments. This is because the delimiter between instruments returned by the System:Topics DDE command is a comma for Snap-Master version 3.0 (in version 2.0 it was a space).

The following code is an updated version of the GetSMInsList routine:

Public Function GetSMInsList(InsList() As String) As Integer

Dim retList As String, Delimiter As String
Dim a As Integer, n As Integer
Dim LastPos As Integer
Dim tempInsName As String

Const lenRetList = 2048

‘get the list of instruments loaded in Snap-Master
retList = Space$(lenRetList)
a = MainReadInsList(retList, lenRetList)
If a = -2 Then
‘ error getting the list. if SM is loaded, try again
n = SMRunning()
If n = -2 Then
MsgBox “Snap-Master is not responding toDDE requests.”, vbCritical & vbOK, “Error:GetSMInsList”
Exit Function
End If
End If
retList = Left$(retList, a)

‘if only “Main” is returned, then there are no instruments
If retList = “Main” Then
Exit Function
End If

***** CHANGE FOR SNAP-MASTER VERSION 3.0 *****
‘look at the character after Main to determine the delimiter
‘for SM v1.X and v2.X the delimiter is a space
‘for SM v3.X the delimiter is a comma and a space
Delimiter = Mid$(retList, 5, 1)
If Delimiter = “,” Then Delimiter = “, ”

‘look for the delimiter to determine the end of a word
For n = 1 To Len(retList)
n = InStr(LastPos + 1, retList, Delimiter)
‘no more delimiters means no more instruments in the list
If n <= 0 Then Exit For

‘set the new instrument name. do not use Main
tempInsName = Mid$(retList, LastPos + 1, (n – (LastPos + 1)))
If tempInsName <> “Main” Then
‘resize the array for the instrument list
ReDim Preserve InsList(UBound(InsList) + 1)
‘write the new value
InsList(UBound(InsList)) = LTrim(tempInsName)
End If

‘set the value of LastPos
LastPos = n
Next

‘return true
GetSMInsList = True

End Function