DataEntry.SearchSamples

Syntax Parameters Return Value
Function DataEntry.SearchSamples( _
    Option As SampleSearchOptions) As Samples
Option [in]

The filtering options to search with.

Type: SampleSearchOptions

Samples

SVB Example

Data Entry Example 10: Searching samples for a pattern:

Sub Main

    Dim oOM As New ObjectManager
    'Reconnect into Enterprise
    oOM.Reconnect Application

    'We will search the samples by first specifying what to search for.
    Dim searchInfo As New SampleSearchOptions
    'Search for only approved and completed samples
    searchInfo.IncludeApprovalAndCompleteData = True
    searchInfo.CompleteStatus = swcSampleCompleted
    searchInfo.ApprovalStatus = swcSampleApproved
    'If you wish to include sample labels in the search results then specify that here
    searchInfo.AddSampleLabel(oOM.Labels("/Blake's Materials/Bakeries"))
    'The data entry setup that we wish to search through
    searchInfo.Profile = oOM.Profiles("/Blake's Materials/Bread Measurements")
    'Searching requires a separate connection
    searchInfo.UseSeparateConnection = True

    'Launch the search
    Dim foundSamples As Samples
    Set foundSamples = oOM.DataEntry.SearchSamples(searchInfo)

    'A message that we will format for our output report
    Dim rptMsg As String, bakeryMismatch As String
    rptMsg = "Approved Samples with Unreasonable Entries:" + vbCrLf + _
        "---------------------------------------------------" + vbCrLf

    Dim currentSample As Sample
    Set currentSample = foundSamples.Next 'connect to the first sample in the search results

    'Store our reasonable low and high values for performance
    Dim reasonableLow As Double, reasonableHigh As Double
    reasonableLow = oOM.Characteristics("/Blake's Materials/Grain Level").ReasonableLow
    reasonableHigh = oOM.Characteristics("/Blake's Materials/Grain Level").ReasonableHigh
    'Iterate through the search results. Here, we will make a report of all unreasonably low grain-level
    'measurements that were approved. We will list the sample ID, the baker, the approver, and the unreasonable
    'grain level.
    While Not(currentSample Is Nothing)
        Dim i As Long
        For i = 1 To currentSample.Data.Pieces.Count
            Dim grainValueEntry As Double
            grainValueEntry = currentSample.Data.Pieces(i).FindCharData(oOM.Characteristics("/Blake's Materials/Grain Level")).Value
            If grainValueEntry < reasonableLow Or _
             grainValueEntry > reasonableHigh Then
                rptMsg = rptMsg & "Sample #:" & Trim(Str(currentSample.ID)) & vbTab & _
                    "BAKER: " & currentSample.Data.Pieces(i).FindLabelData(oOM.Labels("/Blake's Materials/Bakers")).Value & vbTab + _
                    "APPROVER: " + currentSample.Approver & vbTab & _
                    "(VALUE=" & Trim(Str(grainValueEntry)) & ", reasonable range is " & _
                    Trim(Str(reasonableLow)) & "-" & _
                    Trim(Str(reasonableHigh)) & ")" & vbCrLf
            End If
        Next

        Set currentSample = foundSamples.Next
    Wend

    'Show our report. If running this after the "Entering data samples" example,
    'you will notice a rather odd pattern: Blake approved 3 samples where Gabi
    'was the baker and she had an unacceptable bread mixture.
    'Also, two mixtures had the same grain level (3), which is a strange coincidence.
    'What is even more odd is that these samples were from different bakeries--the same baker can't be
    'at 3 bakeries. We have discovered an interesting pattern in our samples that may
    'warrant a further review.
    Dim rpt As New Report
    rpt.SelectionText = rptMsg
    rpt.Visible = True

    oOM.Disconnect

End Sub