Jump to content

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

AutoHotkey v1.1.13


  • Please log in to reply
24 replies to this topic
Menixator
  • Members
  • 744 posts
  • Last active: Sep 01 2015 02:54 PM
  • Joined: 10 Jul 2013

I wonder, if there's ever gonna be a 'Switch()' case statement... it would be really useful!

I'm wondering the same thing too. happy.png
Right now, In
 some cases, the Ternary operator can be used but in other cases it ends up as a string of if-else statements.



nnnik
  • Members
  • 1625 posts
  • Last active: Apr 11 2017 02:13 PM
  • Joined: 28 Jul 2012

I personally often use associative arrays for this kind of thing.

Most of the times its as good as an switch statement:

Color:={R:"Red",B:"Blue",G:"Green"}[shortname]

If you want to execute code define functions and use Func objekt inside the associative array.


Visit the new forum ahkscript.org.

http://ahkscript.org


iDrug
  • Members
  • 389 posts
  • Last active: Oct 11 2015 09:24 PM
  • Joined: 13 Oct 2009

I personally often use associative arrays for this kind of thing.
Most of the times its as good as an switch statement:

Color:={R:"Red",B:"Blue",G:"Green"}[shortname]

http://l.autohotkey.net/v2-changes.htm
If you want to execute code define functions and use Func objekt inside the associative array.

 

 

Example, please?



nnnik
  • Members
  • 1625 posts
  • Last active: Apr 11 2017 02:13 PM
  • Joined: 28 Jul 2012

This is from the Help file:

array := [Func("FirstFunc"), Func("SecondFunc")]

; Call each function, passing "foo" as a parameter:
Loop 2
    array[A_Index].("foo")

; Call each function, implicitly passing the array itself as a parameter:
Loop 2
    array[A_Index]()

FirstFunc(param) {
    MsgBox % A_ThisFunc ": " (IsObject(param) ? "object" : param)
}
SecondFunc(param) {
    MsgBox % A_ThisFunc ": " (IsObject(param) ? "object" : param)
}

Or:

array := {2:Func("FirstFunc"),1: Func("SecondFunc")}

; Call each function, passing "foo" as a parameter:
Loop 2
    array[A_Index].("foo")

; Call each function, implicitly passing the array itself as a parameter:
Loop 2
    array[A_Index]()

FirstFunc(param) {
    MsgBox % A_ThisFunc ": " (IsObject(param) ? "object" : param)
}
SecondFunc(param) {
    MsgBox % A_ThisFunc ": " (IsObject(param) ? "object" : param)
}

Visit the new forum ahkscript.org.

http://ahkscript.org


fump2000
  • Members
  • 591 posts
  • Last active: Nov 11 2015 07:52 AM
  • Joined: 01 Nov 2012

What's new on V 1.1.14?



nnnik
  • Members
  • 1625 posts
  • Last active: Apr 11 2017 02:13 PM
  • Joined: 28 Jul 2012
http://ahkscript.org...php?f=24&t=1443

Visit the new forum ahkscript.org.

http://ahkscript.org


joedf
  • Administrators
  • 986 posts
  • AutoHotkey Foundation
  • Last active: Jul 18 2017 06:01 PM
  • Joined: 20 May 2012
New forum ;)
Why ahkscript.org? - autohotkey.com is outdated

nnnik
  • Members
  • 1625 posts
  • Last active: Apr 11 2017 02:13 PM
  • Joined: 28 Jul 2012
He knows I think :D

Visit the new forum ahkscript.org.

http://ahkscript.org


fump2000
  • Members
  • 591 posts
  • Last active: Nov 11 2015 07:52 AM
  • Joined: 01 Nov 2012

ohhhhh yes :) sorry!



joedf
  • Administrators
  • 986 posts
  • AutoHotkey Foundation
  • Last active: Jul 18 2017 06:01 PM
  • Joined: 20 May 2012
:D great!
Why ahkscript.org? - autohotkey.com is outdated