Modify ↓
Opened 12 years ago
Closed 12 years ago
#2553 closed Bug (No Bug)
Enum unwillingly&erroneously declares/treats variables as Const
| Reported by: | rarirurerory | Owned by: | |
|---|---|---|---|
| Milestone: | Component: | AutoIt | |
| Version: | 3.3.9.23 | Severity: | None |
| Keywords: | Cc: |
Description
;Should you want to make vars unchangable constants, you simply add Const before them.
;However you _obviously_ wouldn't expect&want vars declared without Const to be treated as if they were declared WITH Const!
;but one may totally need to adjust the once Enum'erated variables, e.g. after changing an array those vars are to be used with, and s/he just can't! why, maybe Const was used? ha, nope! still cannot alter 'em!..
;please disregard those few who think this BUG is a butterfly, and fix it for (not only)your Pleasure and Glory. Thank you.
;example code:
Global Const $a=3, $b=2, $c=1
Global Const Enum $e_animal, $e_reptile, $e_fruit
Const Enum $itemColorShmalor, $itemTextBext, $itemYadayada
;-- now sans the Const --;
;-- these expected to always be changable --:
Global $x=555, $y='nope', $z=777
Enum $hehe, $haha, $hoho ;why oh why do you make these sneering v{w}ars Constant?!
;noooo, stop it!..
$jk=1
$oops=1
Test()
Exit
Func test()
do
switch Random(1,6,1)
case 1
ConsoleWrite('***1***'&@LF)
$x=777 ;this will not cause a problem
;$a=777 ;while this expectedly will, because $a
;was declared as Const
case 2
ConsoleWrite('***2***'&@LF)
;Global $c=5 ;alright, since $c is Const, we cannot redeclare it.
Global $y=5 ;this's fine tho, not const
case 3
ConsoleWrite('***3*** - expect a right error'&@LF)
Enum $a, $b, $c ;this will Rightfully cause an error, as
;these three vars are created with Const.
case 4
ConsoleWrite('***4')
;$jk=2 ; -- here would be error if $jk were Const
ConsoleWrite('*** - THE big pesky error!'&@LF)
Enum $jk, $oops ;and yet, while neither vars here
;was made with Const, this happens:
;Cannot assign values to constants.:
;Enum $jk, $oops
;Enum ^ ERROR
case 5
ConsoleWrite('***5*** - here goes the error!'&@LF)
$hehe=';)' ;this Somehow happens to be a Const and
;it breaks the script! wait, did i maybe
;declared it like that? ...hmm, nope. hmm!
Enum $haha, $hoho ;( same here
case 6
ConsoleWrite('***6*** - error error error!!'&@LF)
;$z=1 ;$z and others may or may not be --
;$y=2 ; -- redeclared, next line --
Enum $z,$y,$x ;-- yup, will be faulty anyway.
EndSwitch
until 0
EndFunc
Attachments (0)
Change History (2)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
| Resolution: | → No Bug |
|---|---|
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.

The Help file makes it quite clear that Enum produces constants:
In most languages Enum declares constants and I see no reason why AutoIt should be different, particularly as this behaviour is well-documented and long established. If you want to alter the value of items in the script, they need to declared as variables and so Enum is not a suitable function to use.
M23