The Basics

To demonstrate how to script the DTCs, I created a simple Inventory database. This database contains the structure shown in Figure 8-1.

click to view at full size.

Figure 8-1. The Inventory database contains information for producing and maintaining inventory items and work orders.

I used Microsoft SQL Server for the database engine, but you can use Oracle, Microsoft Access, or any other database supported by Visual InterDev. The database access in this chapter will be simple. It will demonstrate how to script DTCs—not how to use the database features. You can learn more about scripting database features in Chapter 13 and Chapter 14.

A number of properties, methods, and events are shared across multiple DTCs. For example, almost every DTC will have show and hide methods that can be used to show or hide the DTC at run time. Some DTCs have a value property that you can use to extract data from the DTC or to place data in the DTC at run time.

Other DTCs have properties, methods, and events that are specific only to them. For instance, the Listbox and OptionGroup DTCs have an addItem method for adding items to the DTC at run time.

You can access the properties and methods of a DTC at run time by using the dot syntax. For example, to load a Listbox DTC that has an ID of ItemName, you might use the following code:

 ItemName.addItem "Widget A" ItemName.addItem "Widget B" ItemName.addItem "Widget C" ItemName.addItem "Widget D" 

These commands add the Widget item names to ItemName.

You must call the methods for a DTC from the scripting platform it uses. For example, if you define a DTC and specify that it uses the Client scripting platform, the DTC's properties, methods, and events are available only in script code on the client. Conversely, if you define a DTC and specify that it uses the Server scripting platform, the DTC's properties, methods, and events are available only in ASP code running on the server.

To demonstrate how to call a method in the correct scripting platform, let's look at the following sample code:

 <SCRIPT ID=serverEventHandlersVBS LANGUAGE=vbscript RUNAT=Server> Sub thisPage_onenter()     if thisPage.firstEntered then         Listbox1.addItem "Widget A"         Listbox1.addItem "Widget B"         Listbox1.addItem "Widget C"         Listbox1.addItem "Widget D"     end if End Sub </SCRIPT> 

This code runs whenever the page loads, whether the page is being accessed by a browser navigating to it or it is being entered by processing an HTML form. If the thisPage.firstEntered property is true, the user has navigated to the page and this code loads Listbox1 with data. The results are shown in Figure 8-2 below.

click to view at full size.

Figure 8-2. A server-side Listbox DTC.

You can also implement this code on the client, but you must change the event that contains the code to an event that will be fired in the browser. This code executes the same addItem statements, but this time they execute in the window_onload event in the browser.

<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript> <!-- Sub window_onload     ListBox1.addItem "Widget A"     ListBox1.addItem "Widget B"     ListBox1.addItem "Widget C"     ListBox1.addItem "Widget D" End Sub --> </SCRIPT> 

Another issue you must correctly deal with involves the syntax of the various commands. Visual InterDev 6.0 implements the DTCs using the Script Library, which is composed of JScript routines. Service Pack 1 for Microsoft Visual Studio 6 will offer the option of using a set of COM components on the server in place of the JScript Script Library.

At least until Service Pack 1 is released, you must get used to using the correct case in your programming. JScript is case-sensitive while Microsoft Visual Basic is not. Since the DTCs are implemented using the JScript Script Library, the run-time executes all your code in JScript. This is true even if you are developing in VBScript (Visual Basic, Scripting Edition). For example, the following line of code will work:

 if thisPage.firstEntered then 

This line of code will fail:

 if thispage.firstEntered then 

If you execute this last line of code, the following message will appear in the browser:

 Microsoft VBScript runtime error '800a01a8'  Object required: 'thispage'  /VI6BookExamples/InventoryList.asp, line 13 

This error is generated because the "p" in 'thispage' is not capitalized. Capitalize the P, and the script works fine.



Programming Microsoft Visual InterDev 6. 0
Programming Microsoft Visual InterDev 6.0
ISBN: 1572318147
EAN: 2147483647
Year: 2005
Pages: 143

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net