#119339 - 2004-05-12 10:16 PM
Re: Define constants with kixtart
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Rad,
Did some tweaks with your code (XP).. Code:
break on
const(_OS ,split(@ProductType)[1]) const(_CSD ,val(right(@csd,1))) const(_ADMIN ,ingroup('@wksta\'+sidtoname('S-1-5-32-544'))-1+@INWIN) const(_HKLMSCCS ,"HKLM\SYSTEM\CurrentControlSet") const(_HKCUSMWCV ,"HKCU\Software\Microsoft\Windows\CurrentVersion") const(_HKLMSMWCV ,"HKLM\Software\Microsoft\Windows\CurrentVersion") const(_Desktop ,"readvalue(_HKCUSMWCV+'\Explorer\Shell Folders','Desktop')") const(_StartMenu ,"readvalue(_HKCUSMWCV+'\Explorer\Shell Folders','Start Menu')") const(_Favorites ,"readvalue(_HKCUSMWCV+'\Explorer\Shell Folders','Favorites')") const(_MyDocuments ,"readvalue(_HKCUSMWCV+'\Explorer\Shell Folders','Personal')") const(_alldesktop ,"expandenvironmentvars(readvalue(_HKLMSMWCV+'\Explorer\User Shell Folders','Common Desktop'))") const(_allstartmenu,"expandenvironmentvars(readvalue(_HKLMSMWCV+'\Explorer\User Shell Folders','Common Start Menu'))") const(_LDAP ,'"LDAP://"+@domain+"/"+GetObject("LDAP://rootDSE").Get("defaultNamingContext")')
? "OS: " _OS ? "SP: " _CSD ? "Admin: " _ADMIN ? "Current Control Set: " _HKLMSCCS ? "Current Version: " _HKCUSMWCV ? "Desktop: " _Desktop ? "Start Menu: " _StartMenu ? "Favorites: " _Favorites ? "My Documents: " _MyDocuments ? "All StartMenu: " _allstartmenu ? "All Desktop: " _alldesktop ? "LDAP: " _LDAP get $
Function Const($Constant,$Value) Exit Execute('Function ' + $Constant + ' $' + $Constant + '=' + $Value + ' EndFunction') EndFunction
Thanks,
Kent
|
|
Top
|
|
|
|
#119342 - 2004-05-13 12:01 AM
Re: Define constants with kixtart
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
I see it as a way to guarantee that a value is... well constant since everytime it is used it is re-evaluated.
realistically, we all do it the way you are doing it now.. we always have been. But this promises to ensure that we do not accidentally reuse a var somewhere a screw something up.
At least until Ruud provides real consts
I still think it uses too much overhead... creating all those functions for each const and then calling that funct each time a const is used.
|
|
Top
|
|
|
|
#119344 - 2004-05-13 01:37 AM
Re: Define constants with kixtart
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
I see something like this really coming into play where you want a dynamic constant ...... What I mean is....you are expect a given type of data to be returned, but that actual data value can change over time.
I agree that the global variable is much less overhead. but when dealing with simple values, I had to loop into the 100k mark to stat to really notice a difference in @msecs between the 2 methods.
Has anyone ever have any dealings with FORTH?
|
|
Top
|
|
|
|
#119345 - 2004-05-13 05:20 AM
Re: Define constants with kixtart
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
I had to do something like this to detect opening RAS connections... I had to spawn a new shell and pass a value back
|
|
Top
|
|
|
|
#119346 - 2004-05-13 10:12 AM
Re: Define constants with kixtart
|
Lonkero
KiX Master Guru
   
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
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
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 601 anonymous users online.
|
|
|