下面是一个更大的脚本的片段,该脚本使用 GUI 为大多数目的提供的主变量 %Month%。然后,我需要将该缩写的 %Month% 变量更改为 MM 日期格式(例如:Jul = 07)并将该数据存储为新变量 %month%。
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. ; #Warn ; Enable warnings to assist with detecting common errors. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
Gui, Add, Text,, Abbrivated Month (Case Sensitive Ex: Jul):
Gui, Add, Edit, vMonth
Gui, Add, Button, default, Submit ; The label ButtonOK (if it exists) will be run when the button is pressed.
Gui, Show,, Date at the end of the target file
return
GuiClose:
ButtonSubmit:
Gui, Submit
if (%Month% = Jan)
{
month = 01
}
else
{
if (%Month% = Feb)
{
month = 02
}
else
{
if (%Month% = Mar)
{
month = 03
}
else
{
if (%Month% = Apr)
{
month = 04
}
else
{
if (%Month% = May)
{
month = 05
}
else
{
if (%Month% = Jun)
{
month = 06
}
else
{
if (%Month% = Jul)
{
month = 07
}
else
{
if (%Month% = Aug)
{
month = 08
}
else
{
if (%Month% = Sep)
{
month = 09
}
else
{
if (%Month% = Oct)
{
month = 10
}
else
{
if (%Month% = Nov)
{
month = 11
}
else
{
if (%Month% = Dec)
{
month = 12
}
else
{
MsgBox, Invalid Month
}
}
}
}
}
}
}
}
}
}
}
}
MsgBox, %month%
ExitApp
运行上面的脚本时,我只得到 %month% = 01,而我希望将 %month% 变量更改为相应的每月 MM 值。
表达式中的变量名称不包含在百分号中。
因此,文字字符串必须括在 双引号以将它们与变量区分开。
#NoEnv
Gui, Add, Text,, Abbrivated Month (Case Sensitive Ex: Jul):
Gui, Add, Edit, vMonth
Gui, Add, Button, default, Submit ; The label ButtonOK (if it exists) will be run when the button is pressed.
Gui, Show,, Date at the end of the target file
return
GuiClose:
ButtonSubmit:
Gui, Submit
if (Month = "Jan")
month = 01
else if (Month = "Feb")
month = 02
else if (Month = "Mar")
month = 03
else if (Month = "Apr")
month = 04
else if (Month = "May")
month = 05
else if (Month = "Jun")
month = 06
else if (Month = "Jul")
month = 07
else if (Month = "Aug")
month = 08
else if (Month = "Sep")
month = 09
else if (Month = "Oct")
month = 10
else if (Month = "Nov")
month = 11
else if (Month = "Dec")
month = 12
else
{
MsgBox, Invalid Month
ExitApp
}
MsgBox, % month
ExitApp