Что нового

Не понимаю работу Select

Ufo

Новичок
Сообщения
12
Репутация
0
Код:
for $i = 1 to 9
		HotKeySet ($i, '_sectors_selection')
		ConsoleWrite ('hotkey ' &$i& ' set' &@LF)
	next
	ConsoleWrite ('Waiting for selection' &@LF)
	
	
Func _sectors_selection()
	Select
	case @HotKeyPressed = 1 Or 2 OR 3 or 5 or 7
		ConsoleWrite ('group 1'&@LF)
	case @HotKeyPressed = 4 or 6 or 8
		ConsoleWrite ('group 2'&@LF)
	case @HotKeyPressed = 9
		ConsoleWrite ('group 3'&@LF)
	EndSelect
EndFunc

Do
Until GUIGetMsg() = -3


Всё время выбирает группу 1, какой бы хоткей не нажал. Что я не так делаю?
 

Medic84

Омега
Команда форума
Администратор
Сообщения
1,590
Репутация
341
Код:
Switch @HotKeyPressed
    case  1 Or 2 OR 3 or 5 or 7
        ConsoleWrite ('group 1'&@LF)
    case 4 or 6 or 8
        ConsoleWrite ('group 2'&@LF)
    case 9
        ConsoleWrite ('group 3'&@LF)
EndSwitch

Думаю для этого случая Switch будет разумнее =)
 

Medic84

Омега
Команда форума
Администратор
Сообщения
1,590
Репутация
341
А по большому счету должно быть так:
Код:
Select
    case @HotKeyPressed = 1 Or @HotKeyPressed = 2 OR @HotKeyPressed = 3 or @HotKeyPressed = 5 or @HotKeyPressed = 7
        ConsoleWrite ('group 1'&@LF)
    case @HotKeyPressed = 4 or @HotKeyPressed = 6 or @HotKeyPressed = 8
        ConsoleWrite ('group 2'&@LF)
    case @HotKeyPressed = 9
        ConsoleWrite ('group 3'&@LF)
    EndSelect
 

madmasles

Модератор
Глобальный модератор
Сообщения
7,790
Репутация
2,322
ИМХО, в данной ситуации лучше так (короче):
Код:
;...
Func _sectors_selection()
	Switch @HotKeyPressed
		Case 1, 2, 3, 5, 7
			ConsoleWrite('group 1' & @LF)
		Case 4, 6, 8
			ConsoleWrite('group 2' & @LF)
		Case 9
			ConsoleWrite('group 3' & @LF)
	EndSwitch
EndFunc   ;==>_sectors_selection
 
Верх