<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>VbScript</title>
        <link>http://blogs.ugidotnet.org/fgiossi/category/VbScript.aspx</link>
        <description>Microsoft Visual Basic Script</description>
        <language>it-IT</language>
        <copyright>Francesco Giossi</copyright>
        <generator>Subtext Version 2.6.0.0</generator>
        <item>
            <title>Running custom VbScript code from asp</title>
            <link>http://blogs.ugidotnet.org/fgiossi/archive/2007/08/27/running-custom-vbscript-code-from-asp.aspx</link>
            <description>Running custom VbScript code from asp
I was in the need to run some custom VbScript code from an asp page, so I went through the problem and found a very simple solution.
A common solution is to use the Microsoft ScriptControl.
Here is a very simple example running a piece of code stored in a text file.
default.asp
&amp;lt;%@language=VBSCRIPT%&amp;gt;
&amp;lt;%

dim sFile : sFile = ""

sFile = LoadFile("MyCustomScript.txt")

if len(sFile) &amp;gt; 0 then
    Response.Write "The result is: " &amp;amp; ExecScript(sFile)
end if

Function ExecScript(sScript)

        dim sc
        'Create the Script Control object
        set sc = server.CreateObject("scriptcontrol")
        
        sc.Language = "VBSCRIPT"
        sc.UseSafeSubset = false
        sc.Reset
        
        'add the custom script to the ScripContro object
        sc.AddCode sScript
        'run the code and evaluate the result of the "CustomScript" function
        ExecScript = sc.Eval("CustomScript")
        
        set sc = nothing

End Function

Function LoadFile(sFileName)
    Dim objFSO
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

    Dim objTextStream
    dim strFileName
    dim lsTemp

    strFileName = server.MapPath(sFileName)
    const fsoForReading = 1

    If objFSO.FileExists(strFileName) then
        'The file exists, so open it and output its contents
        Set objTextStream = objFSO.OpenTextFile(strFileName, fsoForReading)
        lsTemp=  vbNullString &amp;amp; objTextStream.ReadAll &amp;amp; vbNullString
        objTextStream.Close
        Set objTextStream = Nothing
    Else
        'The file did not exist
        Response.Write strFileName &amp;amp; " was not found."
    End If

    'Clean up
    Set objFSO = Nothing
    LoadFile = lsTemp
end function

%&amp;gt;
MyCustomScript.txt
function CustomScript()
    'Let's calculate the area of a rectangle
    dim dHeight : dHeight = 10
    dim dWidth : dWidth = 20
    CustomScript = cstr(dHeight * dWidth)
end function
This is a very easy example of how to use the Microsoft ScriptControl in an asp page.
A more realistic task would be, for example, store the script in a database, get the scripts from there and run 'em like exposed above.&lt;img src="http://blogs.ugidotnet.org/fgiossi/aggbug/87986.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Francesco Giossi</dc:creator>
            <guid>http://blogs.ugidotnet.org/fgiossi/archive/2007/08/27/running-custom-vbscript-code-from-asp.aspx</guid>
            <pubDate>Mon, 27 Aug 2007 21:25:59 GMT</pubDate>
            <comments>http://blogs.ugidotnet.org/fgiossi/archive/2007/08/27/running-custom-vbscript-code-from-asp.aspx#feedback</comments>
            <slash:comments>3</slash:comments>
            <wfw:commentRss>http://blogs.ugidotnet.org/fgiossi/comments/commentRss/87986.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.ugidotnet.org/fgiossi/services/trackbacks/87986.aspx</trackback:ping>
        </item>
    </channel>
</rss>