#------------------------------------------------------------------------------------------------------
# This constant uses a compiler method to initialize its value. It first displays a dialog to ask the
# user for a string, and then it uses that string (as a constant) to call the compiler method to
# perform some type of processing on it (character upper/lower case processing in this case).
#------------------------------------------------------------------------------------------------------
data<string> const UserName = CompilerTextEditDialog("Enter initial name: ","","Aztec Compile-Time Logic")
data<string> const StartupName = CompilerStrUprLwrRange(UserName,'A','z')
# This method is used at compile-time to return a modified version of the string (upr/lwr within range).
public compiler method<string> CompilerStrUprLwrRange(string Text, string LowChar, string HighChar)
{
data<int> Length
data<int> Index = 1
data<string> TmpChar
data<string> RetStr = Text
#------------------------------------------------------------------------------------
# Loop through the entire length and check original string using 'repeat' statement
# and one method of testing for the character being within a range. This logic
# converts upper case and "in range" characters (in original string) to upper case.
# The repeat statement is used alone here, and requires a manual exit from the loop.
#------------------------------------------------------------------------------------
Length = CompilerStrLen(Text)
repeat
{
# Must validate index manually since we always come through at least once.
if ( Index <= Length )
{
# Get the character at this position and determine if it should be changed.
TmpChar = CompilerStrSub(Text,Index,1)
# If upper case and in range, flip the case and overlay it back into the string.
if ( (TmpChar >= LowChar & TmpChar <= HighChar) & (TmpChar in 'A'..'Z') )
{
RetStr = CompilerStrOvr(RetStr,CompilerStrLwr(TmpChar),Index)
}
CompilerInc(@Index)
}
# Perform a manual break from the loop when appropriate.
if ( Index > Length )
{
break
}
}
#--------------------------------------------------------------------------------
# Loop through the entire length and check original string using 'repeat/until'
# combination and the 'in' keyword for testing a character within a range. This
# logic converts lower case and "in range" characters (in original string) to
# upper case.
#--------------------------------------------------------------------------------
Index = 1
repeat
{
# Must validate index manually since we always come through at least once.
if ( Index <= Length )
{
# Get the character at this position and determine if it should be changed.
TmpChar = CompilerStrSub(Text,Index,1)
# If lower case and in range, flip the case and overlay it back into the string.
if ( (TmpChar >= LowChar & TmpChar <= HighChar) & (TmpChar in 'a'..'z') )
{
RetStr = CompilerStrOvr(RetStr,CompilerStrUpr(TmpChar),Index)
}
CompilerInc(@Index)
}
}
until ( Index > Length )
return(RetStr)
}
# This class is used to startup the script.
public class Main from<Thread>
{
public method Main()
{
Thread() # Must invoke base constructor.
}
public virtual method Run
{
data<int> Length
data<int> Index = 1
data<string> TmpChar
data<string> Name = StartupName
#------------------------------------------------------------
# Use the repeat/while combination to change each character.
#------------------------------------------------------------
Length = Name.Len()
repeat
{
# Must validate index manually since we always come through at least once.
if ( Index <= Length )
{
# Get the character and modify it based on lower case vs upper case.
TmpChar = Name.Sub(Index,1)
if ( TmpChar in 'A'..'Z' )
{
# Increase character by one and write it back into the string.
Name.Ovr(TmpChar.Inc(),Index)
}
else if ( TmpChar in 'a'..'z' )
{
# Decrease character by one and write it back into the string.
Name.Ovr(Char(TmpChar.Ascii() - 1),Index)
}
Index.Inc()
}
}
while ( Index <= Length )
Script().WriteLog("And the name is... " + Name)
return
}
}