Pattern Property

Sets search criteria for a subset definition.

Syntax

FindQuery.Pattern

Applies To

FindQuery Object

Discussion

Use this property to control how the SearchText property is used by a subset definition. With Pattern, you can determine if the

  • search string is found anywhere in a word, at the start of a word only, or the end of a word only
  • pattern matching is on or off
  • search text is to match the whole word or any part of the word
  • search is case sensitive

Each of the search options has a numeric value. For example, matching the text case equals 32, while matching the text with the end of the word equals 4. Add the different search option values to provide a unique value that sets the overall search options.

Unless a pattern value is given, the search option is not in effect. For example, to make a search case sensitive, the value 32 must be included. Add the values to set various search options. Adding values that cannot be used together causes an exception error. For example, do not combine the Contains, Begins With, or Ends With values because they are mutually exclusive, and do not use any of these with MatchWhole. Also, do not use Pattern Matching with MatchCase or MatchWhole.

When the Pattern Matching value is used (Pattern = 8), the Find operation recognizes some characters in the text string as wildcards and some metacharacters are treated as reserved characters when Pattern Matching is used. If the metacharacters are included, an error message appears. If pattern matching is not used, wildcards and metacharacters are treated as normal characters.

Examples of valid combinations include

  • Begins With + Pattern Matching = (10)
  • MatchCase + Contains = (33)
  • MatchCase + Begins With = (34)
  • MatchCase + Ends With = (36)
  • MatchCase + Use Patterns = (40)
  • MatchCase + MatchWhole = (48)

The order of the components in the subset definition are important. First, set the Dimension property, followed by the SearchShortName, SearchText, and Pattern properties, and then the Execute and AddToReport methods. Set the Name property anywhere within the subset definition.

Parameter

Description

PatternValue

Required. Specifies a numeric value that determines the search options. It defaults to 1.

1 - Contains: the search text can be found anywhere in a word 2 - Begins With: the search text must be found at the start of a word 4 - Ends With: the search text must be found at the end of a word 8 - Pattern Matching: certain characters are treated as wildcards 16 - MatchWhole: the search text must match the whole word 32 - MatchCase: the search is case sensitive

Type

Integer

Access

Write

Wildcard Characters for Pattern Matching

Wildcard

Description

^

Match anchored at beginning of string (^ball matches balloon but not baseball).

$

Match anchored at end of string (^ball matches baseball but not balloon).

?

Match any character

#

Match zero or occurrences of the preceding character (or sub-expression)

@

Match one or more occurrences of the preceding character (or sub-expression)

~

Match zero or one occurrences of the preceding character (or sub-expression)

*

Matches zero or more occurrences of any characters.

|

Match either the preceding character (or sub-expression) or the following one; for example, abc|def matches either abcef or abdef.

[ ]

[ - ]

[! ]

Match any character within the brackets; for example, [aeiou] matches a, e, i, o, u. A hyphen between two characters within the brackets indicates a range; for example, [am-px] matches a, m through p and x. A hyphen at the start or end matches itself; for example, [-] matches a hyphen. An exclamation point at the beginning causes the set of characters to be inverted; for example, [!a-m] matches everything except a through m.

( )

Sub-expression. Enables nesting of an expression within the expression, so that repetition and alternative operators can be applied more generally. For example, ab(cd)#e matches a followed by b followed by zero or more cd combinations followed by e.

\

Escape. Match the next character literally. Generally used to allow metacharacters to be treated as normal characters; for example, \? Matches ?.

Metacharacters

Metacharacter

Description

<

Match the beginning of a word.

>

Match the end of a word.

{m,n}

Match at least m and no more than n occurrences of the preceding character (or sub-expression). {n} matches n times. {n,} matches at least n times.

\:x

Extended metacharacter x (where x represents any letter or digit).

Example

This example creates a FindQuery (type 1) subset definition that searches for all products that begin with the name Star.

Sub Main()
   Dim strCubePath As String
   Dim objPPRep As Object
   Dim objFind As Object
   strCubePath = "C:\Cubes and Reports\Great Outdoors.mdc"
   Set objPPRep = CreateObject("CognosPowerPlay.Report")
   objPPRep.New strCubePath, 1
   objPPRep.ExplorerMode = False
   objPPRep.Visible = True
   Set objFind = objPPRep.ReportQueries.Add(1)
   With objFind
      .Name = "Find Star"
      .Dimension = "Products"
      .SearchShortName = False
      .SearchText = "Star"
      .Pattern = 2
   End With
   Set objFind = Nothing
   Set objPPRep = Nothing
End Sub

Related Topics