Find more
Windows programming tools at
 
   
  EzTools Software Logo Quality Windows Programming Tools
Because Presentation is Everything
EditListView Editable ListView
Customizable XP style ListView
Set colors, fonts, and much more
more info
 
Home  Downloads  Buy Support Services FAQ About Us

The Incredible ScriptObject

 

Product Quicklist  
  Database Products
SQLitePlus & SQLite++  
SQLite.NET DLL  
SqlWeb COM DLL  
  HSP System
Overview  
HTML Scripting Pages  
EzWeb Compiler  
EzReg Copy Protection  
  ActiveX Components
EditListView Enhanced ListView  
WOW WebBrowser  
BrowserList HTML Listbox  
HotButton ActiveX  
HotLink HTML HyperLink  
HotList HTML Listbox  
SuperCombo HTML Droplist  
TabStrip ActiveX  
  Other Products
RegDb COM DLL  
Zip COM DLL  
Source Code  
EzComm Messaging DLL  
EzScript XML Generator  
The ScriptObject  
EzScript & EzWeb Compiler  
Test Container  
Access DB Stored Procedures  
Licensing  
FAQ  

 

At the heart of EzScript is the ScriptObject.  This is what you use to execute script code.  Mainly, it has inputs, outputs and RunScript methods.  It has a primary Input (Variant), an Input parameter collection.  Use these if your script needs inputs.  You call one of the RunScript methods to execute a script.  Then any outputs generated by your script is available in the output properties.  Below is a simplified diagram of the ScriptObject, showing its primary methods, input and output properties.

Uses for EzScript

Lets take a practical example.  Suppose you needed to create an XML document from a database. How would you go about it?  Think for minute. Is it getting messy?  Now let's see how easy it would be with the EzScript ScriptObject.  Here is the script you would write if using the SQLitePlus COM DLL with its sample Northwind database.

<?xml version='1.0' encoding='Windows-1252' ?>
<%
Dim db, ds, col

Set db = Host.CreateObject("sqliteplus.sqlitedb28")

db.Init "sqlt28_8859_1m.dll"
db.Open Host.MapPath("\test_scripts\northwind.db"), eReadWrite
Set ds = db.Exec("select * from suppliers")
If Not ds.EOD Then %>

    <Suppliers>
    <% While Not ds.EOD%>
        <Name><%=ds("CompanyName")%></Name>
    <% ds.MoveNext
    Wend %>

    </Suppliers>
<% End If
db.Close
%>

To execute this script, you only need to instantiate a ScriptObject in your code.  If the above script is saved to a file named "gen_suppliers_doc.vbs" in your application's folder, here is how you would execute it:

Dim scriptObj as new EzScript.ScriptObject

scriptObj.RunScript App.Path & "\gen_suppliers_doc.vbs"

'the output is now available in scriptObj.OutStream

As you can see, using EzScript is really easy.  This is why Microsoft ASP has been so successful - its easy to create complex pages by intermixing script code with text.

Here are some uses for EzScript:

  • Generating HTML pages or XML documents.
  • Workflow. EzScript is especially well-suited to Workflow.
  • Mail Merges
  • Any kind of program where the user needs to create and/or execute a script.

EzScript Objects

There are two intrinsic EzScript objects - Host and System.  Intrinsic means that these objects are always there - you don't create them.  For example, to write text to the output stream, you would do this:

<%
Host.Write "some text"
%>

The Host Object

The Host object represents the containing ScriptObject.  You can access its InParams, OutParams, Input, Output and most other properties for use in your script.  For example, suppose there is a named Input Parameter, "hiredate".  You would access it like this:

<%
Host.Write Host.InParam("hiredate")
%>

The System Object

The System object is a "service" object, meant to provide easy access to commonly used Windows services, like the Registry and File system.

<%
Host.Write System.GetCurrentPath()
%>

Helper Objects

There are also helper objects, some of which you cannot create directly - you must obtain them through the System object.  For example, the File object is obtained by calling System.OpenFile.  Using this object, you can easily read and write to files.  Here is an example:

<%
Dim f, val
const eAccessReadWrite=3
const eFileShareRead=1
const eOpenAlways=4
const eNormal=128
const eSeekBegin = 0
const eDataTypeString = 1

set f = System.OpenFile( Host.MapPath("myfile.txt"), eAccessReadWrite, eFileShareRead, eOpenAlways, eNormal )
s = "This is some data"
f.Write s, len(s)
f.Seek 0, eSeekBegin
f.Read val, f.size, eDataTypeString
host.write val
set f = nothing
%>

There is also the FindFileInfo object.  You get this by calling System.FindFirstFile and System.FindNextFile.

Two helper objects can be created directly: StringBuilder and VariantDictionary.  The StringBuilder object is used to efficiently build strings, and the VariantDictionary can be used to manage collections of data and objects.  Here is an example of using a StringBuilder.

<%
dim sb

set sb = Host.CreateObject("EzScript.StringBuilder")
sb.Write "This "
sb.Write "is "
sb.Write "a "
sb.Write "string!"

host.write sb
%>

Unicode and Multibyte

EzScript will run either Unicode or Multibyte script files.  EzScript recognizes the Unicode lead character 0xFFFE.  (This character will be pre-pended to the data in a file created by Notepad).  If this character is not present, EzScript will attempt to determine if the text is Unicode or Multibyte.  If your Unicode file does not have the Unicode lead character, or if you wish to be certain your script file is interpreted properly, you can explicitly specify type text type in the RunScriptFile method (recommended).

EzScript and EzStor

EzScript can run script files from either the local file system or from EzStor files.  Using EzStor allows you to bundle all of your script files into a single file to ship with your application (sort of like WinZip). You wouldn't want end-users to freely access and modify your script files.  For this reason, EzScript works with EzStor files to access your scripts.  EzStor allows you to put any number of scripts into a single file.  Furthermore, you can include other files from within the EzStor file with #include statements in your script.


 

Copyright © EzTools Software2001-2007 All rights reserved. Trademarks and Disclaimer:
All trademarks belong to their respective companies.