Created November 2006. Posted August 2016.

Call the native version of a VBScript object

Let's say you've redefined a VBScript item, for example a function like Left. How would you call the original version of that function if you needed to?

To be honest, I wrote this so long ago I can't remember why I wrote it. But here it is.

Option Explicit

' This redefines the "left" function 
Function Left(mystring,mynumber) 
        Left = Right(mystring,mynumber) 
End Function

Dim sc, cmd 
' This code is the way to get to the "real" old version 
set sc = CreateObject("MSScriptControl.ScriptControl")
' set the language 
sc.Language = "VBScript" 
' what command do you want to call? 
cmd = "Left(""hello"",1)"

Response.Write "<hr>" 
Response.Write Eval(cmd) 
Response.Write "<hr>" 
Response.Write Left("hello", 1) 
Response.Write "<hr>" 
' here we call the one that produces the right result 
Response.Write sc.Eval(cmd)
Response.Write "<hr>"

blog comments powered by Disqus