hmm...
the overheat...
and the errors...
and the const symbol...

k, first, I think ! is better for const

@macro
$var
!const

personal opinion...

anyways, the errors and the overheat are due to same problem.
instead of passing the value to the const, we pass the code with which it can be evaluated.
so, basically, the udf would need to be more like:

Function Const($Constant,$Value)
Exit Execute('Function ' + $Constant + ' $' + $Constant + '=' + iif(vartype($Value)=8,'"'+$Value+'"',$Value) + ' EndFunction')
EndFunction

I admit, this goes little more complex supporting many vartypes, but this way the enum is done only once and if long query is passed as value, this way the runtime reduces a lot.
_________________________
!

download KiXnet