spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column116


JScript .NET, Part X: Displaying Information

Sr Instructional Designer D2L-Moodle,Clearance
WSI Nationwide, Inc.
US-NJ-Fort Monmouth

Justtechjobs.com Post A Job | Post A Resume
Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs


Using System.Console

The class System.Console is slightly more powerful than the print statement. Its methods feature display options that are not supported by the print statement. The WriteLine() method mimics the print statement. The Write() method displays a string without appending a newline character. The ReadLine() method reads from the command line, starting from the end of the previous output string, and ending at the end of the line. Having both read and write functionalities enables you to create a dialog with the user.

To use classes from the .NET framework, such as the System.Console above, you need to import the namespace to which the class belongs. Then, when you call a method, you don't need to specify the fully qualified name of the method. Notice again, that the System.Console class is supported only when you compile your JScript .NET code with the jsc compiler and run it from the command line. Using the System.Console class in an ASP.NET page or in Code Behind JScript .NET code will yield a compilation error.

The following JScript .NET script is similar to the one on Page 2; we just replaced the print statements with calls to System.Console.WriteLine() (col116ex1.js):

import System;
class HelloWorld{
  //constructor
  function HelloWorld() {
    Console.WriteLine("Object Constructed");
  }
  
  function TypeHello() {
    Console.WriteLine("Hello World.");
  }
  
}

var myHelloWorldObj = new HelloWorld();
myHelloWorldObj.TypeHello();

The following example shows a dialog with the user. It asks for his or her name, and echoes it back:

import System;
System.Console.Write("What is your name: ");
var name : String = Console.ReadLine();
Console.Write("Hello ");
Console.Write(name);
Console.WriteLine("!");

Notice the usage of both Write() and WriteLine(). Whenever we want to go to the next line, we use the WriteLine() instead of Write(). The following command-line window shows the code listing of the above dialog, col116ex3.js, its compilation, and its execution.


Next: How to use System.Windows.Forms.MessageBox

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: August 12, 2002
Revised: August 12, 2002

URL: http://www.webreference.com/js/column116/3.html