Data Model > Extending the UNICOM Intelligence Data Model > Working with the Alias Map component > Examples of configuring the Generator > 4: Further examples of configuring the counter
 
4: Further examples of configuring the counter
Creating a hexadecimal counter
This example defines two ranges to create a hexadecimal counter.
VBScript example
Private Sub Example_4a()
Dim MyConfiguration As MRALIASMAPLib.IGeneratorConfiguration
Dim MyGenerator As New MRALIASMAPLib.Generator
Dim MyMapper As New MRALIASMAPLib.Mapper
Dim MyAlias As MRALIASMAPLib.Alias
Dim MyRule As MRALIASMAPLib.Rule
Dim MyCounter As MRALIASMAPLib.Counter
Dim i As Integer
Dim First As Integer
Dim Last As Integer

Set MyConfiguration = MyGenerator.Configuration

MyConfiguration.Clear
MyConfiguration.MaxLength = 6
Set MyRule = MyConfiguration.Rules.AddNew("$")
MyRule.Replacements.AddOperator ropAutoCounter
MyConfiguration.AutoCounters.AddNew
Set MyCounter = MyConfiguration.AutoCounters.Item(0)
MyCounter.Prefix = "("
MyCounter.Suffix = ")"
MyCounter.Charset.Clear
First = AscW("0")
Last = AscW("9")
MyCounter.Charset.AddRange First, Last
First = AscW("a")
Last = AscW("f")
MyCounter.Charset.AddRange First, Last
MyConfiguration.Rules.AddNew "[^A-Z]+"
Set MyMapper.Generator = MyGenerator
MyMapper.MaxAttempts = 0

For i = 0 To 30
Set MyAlias = MyMapper.CreateAlias("Data Collection Development Library")
Debug.Print MyAlias.Name
Next i
End Sub
mrScript example
Sub Example_4a()
Dim MyConfiguration, MyGenerator, MyMapper, MyAlias, MyRule, MyCounter, i, First, Last
Set MyGenerator = CreateObject("MRALIASMAP.Generator")
Set MyMapper = CreateObject("MRALIASMAP.Mapper")
Set MyAlias = CreateObject("MRALIASMAP.Alias")
Set MyRule = CreateObject("MRALIASMAP.Rule")
Set MyCounter = CreateObject("MRALIASMAP.Counter")

Set MyConfiguration = MyGenerator.Configuration

MyConfiguration.Clear()
MyConfiguration.MaxLength = 6
Set MyRule = MyConfiguration.Rules.AddNew("$")
MyRule.Replacements.AddOperator(2 '!ropAutoCounter!')
MyConfiguration.AutoCounters.AddNew()
Set MyCounter = MyConfiguration.AutoCounters[0]
MyCounter.Prefix = "("
MyCounter.Suffix = ")"
MyCounter.Charset.Clear()
First = AscW("0")
Last = AscW("9")
MyCounter.Charset.AddRange(First, Last)
First = AscW("a")
Last = AscW("f")
MyCounter.Charset.AddRange(First, Last)
MyConfiguration.Rules.AddNew("[^A-Z]+")
Set MyMapper.Generator = MyGenerator
MyMapper.MaxAttempts = 0

For i = 0 To 30
Set MyAlias = MyMapper.CreateAlias("Data Collection Development Library")
Debug.Log(MyAlias.Name)
Next
End Sub
When you run this example, you will find the aliases are DDL, DDL(1), DDL(2) ... DDL(9), DDL(a), DDL(b), DDL(c), DDL(d), DDL(e), DDL(f), DD(10), DD(11), and so on.
Using BestFit
You can use the BestFit property on a counter to force MinWidth to be as small as possible while still accommodating the largest value that will be used by the counter. BestFit applies only when MaxCount > 0. For example:
VBScript example
Private Sub Example_4b()
Dim MyConfiguration As MRALIASMAPLib.IGeneratorConfiguration
Dim MyGenerator As New MRALIASMAPLib.Generator
Dim MyMapper As New MRALIASMAPLib.Mapper
Dim MyAlias As MRALIASMAPLib.Alias
Dim MyRule As MRALIASMAPLib.Rule
Dim MyCounter As MRALIASMAPLib.Counter
Dim i As Integer

Set MyConfiguration = MyGenerator.Configuration
MyConfiguration.Clear
MyConfiguration.MaxLength = 6
Set MyRule = MyConfiguration.Rules.AddNew("$")
MyRule.Replacements.AddOperator ropAutoCounter
MyConfiguration.AutoCounters.AddNew
Set MyCounter = MyConfiguration.AutoCounters.Item(0)
MyCounter.ExpandWithZero = False
MyCounter.MaxCount = 100
MyCounter.BestFit = True
MyConfiguration.Rules.AddNew "[^A-Z]+"
Set MyMapper.Generator = MyGenerator
MyMapper.MaxAttempts = 0

For i = 0 To 30
Set MyAlias = MyMapper.CreateAlias("Data Collection Development Library")
Debug.Print MyAlias.Name
Next i
End Sub
mrScript example
Sub Example_4b()
Dim MyConfiguration, MyGenerator, MyMapper, MyAlias, MyRule, MyCounter, i
Set MyGenerator = CreateObject("MRALIASMAP.Generator")
Set MyMapper = CreateObject("MRALIASMAP.Mapper")
Set MyAlias = CreateObject("MRALIASMAP.Alias")
Set MyRule = CreateObject("MRALIASMAP.Rule")
Set MyCounter = CreateObject("MRALIASMAP.Counter")

Set MyConfiguration = MyGenerator.Configuration

MyConfiguration.Clear()
MyConfiguration.MaxLength = 6
Set MyRule = MyConfiguration.Rules.AddNew("$")
MyRule.Replacements.AddOperator(2 '!ropAutoCounter!')
MyConfiguration.AutoCounters.AddNew()
Set MyCounter = MyConfiguration.AutoCounters[0]
MyCounter.ExpandWithZero = False
MyCounter.MaxCount = 100
MyCounter.BestFit = True
MyConfiguration.Rules.AddNew("[^A-Z]+")
Set MyMapper.Generator = MyGenerator
MyMapper.MaxAttempts = 0

For i = 0 To 30
Set MyAlias = MyMapper.CreateAlias("Data Collection Development Library")
Debug.Log( MyAlias.Name)
Next
End Sub
This gives DDL, DDL001, DDL002, and so on. (Without BestFit being set to True, the results would be DDL, DDL1, DDL2, and so on.)
Note that if CharSet contains overlapping ranges, the counter and MinWidth may give unexpected results. However, the counter will automatically use more digits when necessary.
Setting ResetValue
ResetValue controls the value of the counter when it is reset (that is, before the first increment). In this state only ResetValue affects the value of the counter, and MaxWidth, MinWidth, and so on, do not apply. For example, if you add the following line to the previous example, the first alias is DDL#, and all subsequent aliases are the same.
MyCounter.ResetValue = "#"
By default, ResetValue is an empty string.
See also
Examples of configuring the Generator