Solved

JScript "Main" function

Posted on 1997-06-03
4
664 Views
Last Modified: 2012-06-27
When writing a standalone VBScript script, the first function called is Sub Main, just as in VB. What is the equivalent of Sub Main when writing standalone JScript scripts?
0
Comment
Question by:krmc
4 Comments
 
LVL 1

Expert Comment

by:jftao
ID: 1266215
<script>

function name()
{ ...
 your code
  ...
}
</script>

 
0
 

Author Comment

by:krmc
ID: 1266216
As I stated in the question, I am not referring to HTML-embedded scripts; I am asking about standalone scripts. Also, I did not ask what a function looks like in JScript, but what the *main* function looks like.
0
 
LVL 1

Accepted Solution

by:
lonejedi earned 50 total points
ID: 1266217
When developing your ActiveX Script Host you must specify which function you want to use as "main" as in the snipet below:

...
//get the dispatch interface to the engine and
// call the procedure named "main"
hr = pIas->GetScriptDispatch (0, &pIDisp);
LPOLESTR szMain = OLESTR ("main");
DISPID dispid;
hr = pIDisp->GetIDsOfNames (IID_NULL, &szMain, 1, 9, &dispid);
DISPPARAMS params = {0, 0, 0, 0};
hr = pIDisp->Invoke (dispid, IID_NULL, 9, DISPATCH_METHOD, &params, 0, 0, 0);
...

Technically you can specify anything you want, but "main" is a good default as it conforms to VBScript standards, whereas JScript doesn't have a standard (that I know of, at any rate). This would mean that the JScript:

function main()
{
...
}

would be equivalent to VBScript:

public sub main()
...
end sub

You would want to be certain to document this for your end-users.
0
 

Expert Comment

by:WoMbAt
ID: 1266218
JScript has no main function, although if a

<script language="VBScript">

was used, you could define a main function. For
JavaScript, use the onLoad attribute in the <body>
tag and define a function to call (this will work
for JScript and JavaScript BTW).
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now