Maybe now is the time to ask again
![Smile :)](./images/smilies/icon_e_smile.gif)
Please, give us this day our switch, and deliver us from ElseIfs
![Razz :P](./images/smilies/icon_razz.gif)
That would mean you could create a switch/case statement in AutoHotkey like this:The CASE statement evaluates a single expression and compares it against several potential values, or evaluates multiple Boolean expressions and chooses the first one that is TRUE
Code: Select all
if ( x = 1 )
...
else if ( x = 2 )
...
else if ( x = 3 )
...
else if ( x = 4 )
...
Code: Select all
switch := [ func( "xequals1" ), func( "xequals2" ), func( "xequals3" ), func( "xequals4" ) ]
switch[ x ].Call()
xequals4()
{
...
}
xequals3()
{
...
}
xequals2()
{
...
}
xequals1()
{
...
}
Code: Select all
q::
Loop, 5
{
a := A_Index
b := (a = 1) ? 10
: (a = 2) ? 20
: (a = 3) ? 30
: (a = 4) ? 40
: 0
MsgBox, % b
}
Loop, 5
{
a := A_Index
b := c := d := e := ""
(a = 1) ? (b := "B")
: (a = 2) ? (c := "C")
: (a = 3) ? (d := "D")
: (a = 4) ? (e := "E")
: 0
MsgBox, % b " " c " " d " " e
}
return
Code: Select all
F1::
WinGetTitle, text, MT9750
llarg := RegExReplace(text ,"(^.*\[)|(\].*$)") ; Retorna el text que hi ha entre []
curt := RegExReplace(llarg,"\d$") ; Es menja l'último digit
switch curt
{
case "NATTES":
case "NATEXP":
Msgbox 0x40000, % curt, % "NAT_NATEXPc()"
case "NATFAB":
case "NATFTE":
Msgbox 0x40000, % curt, % "NAT_NATFABc()"
case "PREDICT":
Msgbox 0x40000, % curt, % "BS2_PREDICT_1()"
default:
Msgbox % "NO SÉ QUÈ CONY VOLS OBRIR!!!" curt
}
Return
Code: Select all
default:
Msgbox % "NO SÉ QUÈ CONY VOLS OBRIR!!!" curt
Users browsing this forum: No registered users and 27 guests