*** Archive *** Remove Alternatives From a Locator
17232
17232
Question / Problem:
Is it possible to remove alternatives from a locator?
Answer / Solution:
It is possible to remove alternatives from a locator using scripting. It is easier to use a script locator to remove alternatives from a locator than copy the alternatives from a locator to the script locator. Otherwise you have to create new alternatives, subfields and copy all properties (left, width, top, height, pageIndex, words) manually
Example: A format locator finds 5 digit numbers, and you want to remove "12345".
Use the following locators:
- Format Locator: FL_5Digits
- Script Locator: SL_Clean5Digits
If you use a for loop to remove alternatives, then you must count down to 0.
Simple Solution:
Private Sub SL_5Digit_LocateAlternatives(ByVal pXDoc As CASCADELib.CscXDocument, ByVal pLocator As CASCADELib.CscXDocField) Dim FL As CscXDocField Set FL = pXDoc.Locators.ItemByName("FL_5Digit") Dim a As Integer 'Loop through all alternatives from last to first For a = FL.Alternatives.Count-1 To 0 Step -1 If FL.Alternatives(a).Text="12345" Then FL.Alternatives.Remove(a) Next End Sub
A more generic solution is to remove values that fail a formatter:
Private Sub SL_5Digit_LocateAlternatives(ByVal pXDoc As CASCADELib.CscXDocument, ByVal pLocator As CASCADELib.CscXDocField) 'This formats all alternatives of a locator and removes values that fail formatting Dim Loc As CscXDocField Set Loc = pXDoc.Locators.ItemByName("FL_5Digit") Dim formatter As ICscFieldFormatter Set formatter= Project.FieldFormatters.ItemByName("Clean5Digits") Dim formattedText As String Dim errDescription As String Dim a As Integer For a = Loc.Alternatives.Count-1 To 0 Step -1 If formatter.FormatFieldText(Loc.Alternatives(a).Text, formattedText, errDescription) Then 'This alternative passed the formatter Loc.Alternatives(a).Text = formattedText Else 'This alternative failed to format Loc.Alternatives.Remove(a) End If Next End Sub
Applies to:
Product | Version | Category |
---|---|---|
KTM | 6.3 | Scripting |
KTM | 6.2 | Scripting |