August 19, 2002 - Printing from JScript .NET
August 19, 2002 Printing from JScript .NET Tips: August 2002
Yehuda Shiran, Ph.D.
|
print
statement. The print statement takes one argument, a string, and displays it in the command-line window, followed by a new line character. The print
statement works only with the JScript command-line compiler, jsc
. Trying to use print in an ASP.NET page will yield a compiler error. So will an attempt to use it in a Code Behind JScript .NET. Here is a JScript .NET script that uses the print statement:
import System;
class HelloWorld{
//constructor
function HelloWorld() {
print("Object Constructed");
}
//method
function TypeHello() {
print("Hello World.");
}
}
var myHelloWorldObj = new HelloWorld();
myHelloWorldObj.TypeHello();
The program defines a class, HelloWorld
, with two methods: the constructor HelloWorld()
and TypeHello()
. Each method prints one string. The constructor prints the message "Object Constructed"
when an object of type HelloWorld
is constructed. The TypeHello()
method prints the message "Hello World"
. Compiling this program, col116ex2.js
, with the jsc
compiler yields the default executable col116ex2.exe
. When you run this executable (just type col116ex2
at the command line), you'll see the two print messages. The following command-line window shows the code listing, the compilation step, the execution step, and the output of the program:To learn more about JScript .NET and ASP.NET, go to Column 116, JScript .NET, Part X: Displaying Information.