Whether the switch can judge the expression unset Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
cgx5871
Posts: 315
Joined: 26 Jul 2018, 14:02

Whether the switch can judge the expression unset

Post by cgx5871 » 05 Jun 2023, 11:00

Code: Select all

a()
a(b?){
	Switch b
	{
	Case unset(b):
		MsgBox "unset"

	Case 1:
		MsgBox 1
	}
}

User avatar
mikeyww
Posts: 26860
Joined: 09 Sep 2014, 18:38

Re: Whether the switch can judge the expression unset  Topic is solved

Post by mikeyww » 05 Jun 2023, 11:08

Code: Select all

#Requires AutoHotkey v2.0
c := 3
a()
a(c)

a(b?){
 Switch {
  Case IsSet(b):
   MsgBox "Set"
  Default:
   MsgBox "Unset"
 }
}
Explained: Unset parametersSwitch
If present, SwitchValue is evaluated once and compared to each case value until a match is found, and then that case is executed. Otherwise, the first case which evaluates to true (non-zero and non-empty) is executed. If there is no matching case and a Default is present, it is executed.

neogna2
Posts: 589
Joined: 15 Sep 2016, 15:44

Re: Whether the switch can judge the expression unset

Post by neogna2 » 06 Jun 2023, 03:05

or

Code: Select all

  Case !IsSet(b):
   MsgBox "Unset"

Post Reply

Return to “Ask for Help (v2)”