3: Configuring the counter
Creating an alphabetic counter
The following examples illustrate configuring the counter. First we will set the range for the counter to A-Z. This means that you can create 25 aliases before another character is added to the alias, whereas when you use a digital counter, a character is added after creating 9 aliases.
VBScript example
Private Sub Example_3a()
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.Charset.Clear
First = AscW("A")
Last = AscW("Z")
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_3a()
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.Charset.Clear()
First = AscW("A")
Last = AscW("Z")
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
Notice that the range is specified using the AscW Visual Basic function, which returns an Integer that represents the character in Unicode. We must use this function because the characters must be expressed as their Unicode number. Unicode recognizes the range A-Z, but not Z-A. So if we wanted the counter to be in reverse alphabetical order, we would need to specify the range as 26 single-character ranges (Z, Y, X, W, and so on).
When we run this example, we find the aliases are DDL, DDLB, DDLC, ... DDLY, DDLZ, DDLBA, DDLBB, DDLBC, DDLBD, DDLBE. Notice that DDLZ is followed by DDLBA.
Using ExpandWithZero
If we want DDLAA to follow DDLZ instead of DDLBA, we must useExpandWithZero.
VBScript example
Private Sub Example_3b()
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.Charset.Clear
First = AscW("A")
Last = AscW("Z")
MyCounter.Charset.AddRange First, Last
MyCounter.ExpandWithZero = 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_3b()
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.Charset.Clear()
First = AscW("A")
Last = AscW("Z")
MyCounter.Charset.AddRange(First, Last)
MyCounter.ExpandWithZero = 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
When we run this example, we find the aliases are DDL, DDLA, DDLB ... DDLY, DDLZ, DDLAA, DDLAB, DDLAC, DDLAD.
Using Prefix and Suffix
Use Prefix and Suffix to enclose the counter in parentheses. To do this add the following lines after MyCounter.ExpandWithZero = True:
MyCounter.Prefix = "("
MyCounter.Suffix = ")"
This gives DDL, DDL(A), DDL(B) ... DDL(Z), DD(AA), DD(AB), DD(AC), DD(AD).
Using MinWidth
Use MinWidth to set a minimum width for the counter and PrePad to specify a string to pad the counter when MinWidth has not been filled. For example, add the following lines after MyCounter.ExpandWithZero = True:
MyCounter.MinWidth = 3
MyCounter.PrePad = "xyz"
This gives DDL, D(xyA), D(xyB), D(xyC) ... D(xyY), D(xyZ), D(xAA), D(xAB), D(xAC), D(xAD).
See also