In the DateStampConvert.ahk script, the MonthConvert(month) function uses a series of ternary operators to match the text month abbreviation to the corresponding numeral:
Code: Select all
MonthConvert(month)
{
Global NewMonth
NewMonth := InStr(month, "jan") ? "01"
: InStr(month, "feb") ? "02"
: InStr(month, "mar") ? "03"
: InStr(month, "apr") ? "04"
: InStr(month, "may") ? "05"
: InStr(month, "jun") ? "06"
: InStr(month, "jul") ? "07"
: InStr(month, "aug") ? "08"
: InStr(month, "sep") ? "09"
: InStr(month, "oct") ? "10"
: InStr(month, "nov") ? "11"
: InStr(month, "dec") ? "12"
:"Not found!"
}
Code: Select all
MonthConvert(month)
{
Switch SubStr(month,1,3)
{
Case "jan","ene","jän","gen":Return "01"
Case "feb","fév","fev": Return "02"
Case "mar","mär": Return "03"
Case "apr","abr","avr": Return "04"
Case "may","mai","mag": Return "05"
Case "jun","jui","gui":
If (SubStr(month,1,4) = "juil")
Return "07"
Else
Return "06"
Case "jul","lug": Return "07"
Case "aug","ago","aoû","aou","ag": Return "08"
Case "sep","set": Return "09"
Case "oct","okt","ott": Return "10"
Case "nov": Return "11"
Case "dec","dic","dez","déc": Return "12"
}
}
A few basic rules:
- A command statement can appear either on the same line as the Case statement (all one line) or start on the next line—including any number of command statements.
- Unlike multiple line If-Else statements, Case statements do not require curly brackets to enclose multiple command statement lines. (No need to keep track of curly brackets.)
- Up to 20 matching expression values (separated by commas) can appear after the Case command but before the closing colon. These values may come in the form of text, numbers, variables, or functions. The delimiting commas act in the same manner as a logical OR operator between each value (OR or ||) in an If-Else statement.
- The Switch-Case condition can either match an optional SwitchValue expressed in the Switch command line (Switch [SwitchValue]) or execute the first Case statement found true.
- Although not explicitly stated, the Switch command likely uses Short-circuit Boolean Evaluation. That means after finding a match and executing the enclosed Case commands, AutoHotkey exits the Switch without further evaluation.
- It seems that you can add GoTo Labels to the Case statements to allow jumps inside the Switch block. While I haven’t thought through how to use this type of Label jump, AutoHotkey does not support this type of movement between If and Else blocks.
Plus, this DateStampConvertSwitch.ahk script, as shown in the Switch statement above, also supports converting dates formatted in Spanish, German, French, and Italian month names. See "Jack's AutoHotkey Blog" (January 13, 2020) for more information.