|
- Start Windows Explorer and locate the folder where your jsc
application is
installed. Here is an example:
- Click Start -> Control Panel
- Double-click System
- In the System Properties dialog box, click the Advanced tab and click Environment Variables
- In the System Variables section, click Path and click Edit
- Press End or get to the end of the string
- Type ; followed by the complete path to the compiler. Mine appears
as:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322 - Click OK on each dialog box
Application Creation
|
To create a JScript .NET application, you start with a text
file and write your code in it. One of the types of applications you can create
is called a console application. A console application is one that displays its
result(s) in a DOS window, which is a window with a black background.
In our lessons, we will mostly use the free jsc compiler
provided by Microsoft. To write our code, we will use Notepad. To compile our
applications, we will use the command prompt.
There are two main operations you will regularly perform as
a programmer vis-à-vis your application. The primary operation consists of
displaying something on the screen. This task is taken care of by using print().
Based on this, to display a word or sentence on the DOS window, include it in
the parentheses of print. If it is a word or a group of words, include it
between double-quotes.
After creating a file that holds the code of a JScript .NET
application, you can prepare it for distribution. A regular script is a simple
text-base file that can be interpreted by a browser. If you create such a
script, you can save it to display and make it available to other people who
would simply open it in their browser.
If you have created a JScript .NET application and want to
distribute but you are not concerned whether your clients have a browser or not,
you must create an executable. To do this, you must compile your application.
The only way you can create an executable from a JScript .NET application is
through the command prompt. The steps used to open the command prompt depend on
your operating system. In Windows XP and Windows Server 2003, to open a command
prompt, on the Taskbar, you can click Start -> All Programs -> Accessories
-> Command Prompt.
To compile a program on the Command Prompt, first change to
the directory that contains your script file. To proceed, invoke the name of
your compiler, in this case jsc, followed by the name of the script file wit its
extension, and press Enter. If there are errors, the compiler will let you know.
You can then return to the file, fix the problem, and compile again, until all
problems have been corrected.
After compiling the program, an executable application, that
has the same name as the script that was compiled, would be created.
After creating an executable application, you can distribute
it to other people. An executable of a JScript .NET application is a fairly
small application. You can save it to disc and then, either place if where
people can first download it or send it in a disk or other portable medium
(never email an executable).
Executing your application is equivalent to using it. To
execute an application that you have just created, at the Command Prompt where
you compiled it, you can type the name of the executable (your clients can
double click the executable to open the application.
As mentioned above, if you compile your application by
simply invoking the name of the script file that contains the code, an
executable with the same name as the file would be created. Fortunately, when
compiling the file, you can specify the name you want for the executable. The
formula to follow is:
jsc /out:ApplicationName File.js
In this formula, you must first call the compiler as done
previously. It must be followed by /out: which indicates that you are
going to specify the name of the executable. After the /out: factor, type
the desired name that will hold the name of the new application instead of the
name of the file. Lastly, type the name of the file that contains the script and
make sure you append its extension.
A library is a program that contains additional information
that other programs can use. The information in the library can be almost
anything. Experience will guide you as to what you can put in it.
A library is created with the same
approach as the programs we have used so far. This means that you start from a
script file that has the .js extension and that contains the code you decided to
put in it. To actually create the library, you compile it using the following
formula:
jsc /target:library file.js
In this case, the only thing different in the formula is the
file.js, which is the name of the file that contains the necessary code. After
compiling the code, a new application (yes, it is an application) is created but
it has the .dll extension instead of .exe as do the regular applications we have
created so far.
A comment is a line or paragraph of text that the
compiler would not consider when examining the code of a program. There
are two types of comments recognized by C#.
To display a comment on a line of text, start the line
with two forward slashes //. Anything on the right side of // would be
ignored. Here is an example:
// This line will be ignored. I can write in it anything I want
The above type of comment is used on only one line.
You can also start a comment with /*. This type of comment ends with */.
Anything between this combination of /* and */ would not be read by the compiler.
Therefore, you can use this technique to span a comment on more than one
line.
An escape sequence is a special character that
displays non-visibly. For example, you can use this type of character to
indicate the end of line, that is, to ask the program to continue on the
next line. An escape sequence is represented by a backslash character, \,
followed by another character or symbol. For example, the escape sequence
that moves to the next line is \n.
An escape can be included in single-quotes as in '\n'.
It can also be provided in double-quotes as "\n".
JScript.NET recognizes other escape sequences.
|
Escape Sequence | Name | Description |
\b | Backspace | Takes the cursor back by one space |
\t | Horizontal Tab | Takes the cursor to the next tab stop |
\n | New line | Takes the cursor to the beginning of the next line |
\v | Vertical Tab | Performs a vertical tab |
\f | Form feed | |
\r | Carriage return | Causes a carriage return |
\s | Any Character | Matches any white space character |
\S | Any Character | Matches any non-white space character |
\' | Single Quote | Displays a single quote |
\" | Double Quote | Displays a double quote |
\\ | Backslash | Displays a backslash (\) |
\h | Character | Displays an ASCII character from an octal number |
\xhh | 2-Digit Hex | Displays a hexadecimal number with two digits |
\xhhhh | 4-Digit Hex | Displays a hexadecimal number with four digits |
No comments:
Post a Comment