Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Select Case structure


  • Please log in to reply
21 replies to this topic
AnttiV
  • Members
  • 237 posts
  • Last active: Feb 13 2014 02:31 PM
  • Joined: 14 Aug 2009
I tried looking through docs and I didn't come up with anything, but if I missed it, sorry.

What I would like, is a Select -structure from Basic-family languages (at least VB and RealBasic have this. or VB used to anyway).

Example:
;Var1 contains the hour of the day. The script is supposed to do different things at different hours. We can do it with multiple "if Var1"s, but I think Select is a more appropriate approach for this.

Select Case Var1
Case 1
 ; Code here that executes if Var1 = 1
Case 2
 ; Code here that executes if Var1 = 2
Case 3
 ; etc.
Case 4
Case 5 To 7 ; Can define ranges also.
Case 8..9 ; Another suggestion to range syntax, I think Delphi did this.
Case 10, 12 ; Multiple-choice case
Case 11
Case %Var2% ; you can use a variable too. Just "Var2" would matched if Var1 == "Var2"
Case Else
 ; If Var1 wasn't anything yet specified, execute this code
End Select

This is almost how RealBasic does it and I've noticed I use it a lot (I hate multiple if clauses...).

Again, if AHK can already do this, please point me to the syntax, otherwise discuss if this would be a worthwhile addition.[/code]

jaco0646
  • Moderators
  • 3165 posts
  • Last active: Apr 01 2014 01:46 AM
  • Joined: 07 Oct 2006
This has been at the top of the Planned Features list for the past 5 years. :roll:

Several previous threads about it.
1. Case/Switch
2. Switch case and For
3. Switch
4. Case Select
5. Switch Case statement