Archives

Archives / 2010 / March
  • Using custom .net classes in ASP Classic Compiler

    To use custom .net classes, I extended VBScript syntax with the Imports statement. The Imports statement introduce the top namespace to the VBScript, as in the example below. The following example demonstrates using ADO.NET in ASP Classic Compiler:

    <%
        imports system
        dim filePath = Server.MapPath("/Database/authors.mdb")
        dim oleConn = new system.data.oledb.oledbconnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & filePath)
        oleConn.Open()

        dim cmd = new system.data.oledb.OleDbCommand("SELECT * From authors", oleConn)
        dim dr = cmd.ExecuteReader()
        do while dr.Read()
            response.Write(dr.GetString(1) & "<br/>")
        loop
    %>

    In the example above, “imports system” instructs VBScript.net that system is a namespace rather than an object. When VBScript.net encounters system.data.oledb.oledbconnection, it follows the namespace hierarchy to find the oledbconnection class.

    However, VBScript.net does not automatically search all the loaded assemblies. Instead, it only searches the assemblies it was instructed search. VBScript.net will always search the system.dll assembly. However, to instruct VBScript.net to also search in the system.data.dll, we need to add the following code to global.asax.cs:

    using System.Reflection;
    using Dlrsoft.Asp;

    protected void Application_Start(object sender, EventArgs e)
    {
        Assembly a1 = Assembly.Load("System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
        AspHandlerConfiguration.Assemblies.Add(a1);
    }

    The above code tells AspHandler to search the System.Data.dll assembly for classes.

    Lastly, to saves the typing of the fully qualified class name, the “imports” statement also supports alias. The following code demonstrates using alias to save typing:

    <%
    imports t = system.text

    dim sb = new t.StringBuilder()
    sb.append("this")
    sb.append(" is ")
    sb.append(" stringbuilder!")
    response.write sb.toString()

    %>

  • Uploaded ASP Classic Compiler Build 0.6.1.34834

    It has been a long time without a new release. This release contains only a few small fixes, but it is a change in the strategy. I decided to branch the code: one branch to stabilize the VBScript 4.0 features and the other branch to implement the VBScript 5.0 features such as Eval/Execute and VBScript classes.

    The reason is that not all users need VBScript 5.0 features. Some users have only a small number of VBScript classes and can easily convert them to C# classes as VBScript.net can use .net classes. Although I still have a lot to do to reach a mature release, some users only use limited VBScript features so they can use ASP Classic Compiler first. I will issue a license under the “Early Access Program” for those users who want to go live with pre-release versions of ASP Classic Compiler.

    The “Early Access Program” is an enterprise/ISV class of program with source code access. It allows participating users to self-support under emergency situations with source code access. Although the compiler code may have a steep learning curve, many users can learn simple bug fixes fairly quickly by following bug fixes in the source control system. The remaining users can still get the binaries from the Codeplext site http://aspclassiccompiler.codeplex.com without warranty. If you are interested in the program, please contact me using the contact user form.