views:

69

answers:

3

VBScript on ASP Classic contains an "int" function. (It rounds numbers towards -∞.) Suppose that some excessively "clever" coder has created a global variable named "int". Is there any way to get at the original function? I've tried all manner of workarounds with scoping and dodgy execs, but no dice. I suspect that it is impossible, but I'm hoping that someone will know more about it than I do.

EDIT: Thanks for the responses. Since y'all asked, the global variable, called "Int" (though unfortunately, vbscript is not case-sensitive), is a factory for a class similar to Java's Integer. The default property is essentially a one-arg constructor; i.e. "Int(42)" yields a new IntClass object holding 42. The default property of IntClass in turn simply returns the raw number.

The creator was trying to work around the lack of proper namespaces and static methods, and the solution's actually pretty seamless. Pass in an IntClass where an int is expected and it will automatically trigger the default property. I'm trying to patch the last remaining seam: that external code calling "int" will not round properly (because the constructor uses CLng).

+3  A: 

Not that I know of, getref only works on custom functions not on build-ins. I would suggest renaming the custom'int' function and update all references to this custom ones. You can use the search function visual studio (express) or any other tool of your liking for this. Shouldn't be to much work.

Joost Moesker
Thats a stupid variable name if there ever was one, I'm supprised VB even lets you over write a keyword like that? Renaming is the sensible solution. A quick hack might be to knock up a JScript version of Int include that and call that one instead, nasty though...
Pete Duncanson
Yeah I didn't believe it either until I tried it out myself. Amazing that vbscript lets you shoot yourself in the foot like this. I agree that trying to working around this issue will only serve to make the code that much more inscrutable.
NobodyMan
A: 
Eduardo Molteni
No dice -- CInt will round to nearest whole number, Int always rounds *down*: cint(5.6) is 6 whereas int(5.6) is 5.
NobodyMan
fix() is closer but slightly different than int(): fix rounds towards *zero*, so fix(-3.1) would be -3, int(-3.1) is -4.
NobodyMan
You are right, I have forgotten about what ´Int´ does
Eduardo Molteni
A: 

I didn't think reserved words would be allowed for function names or variables.

Duncanson's right. Do the pain and rename int. Chances are there are worse things going on than just this.

(why would someone make a global variable named int... that's going to take some thinking)

inked