Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

JScript "Main" function

Posted on 1997-06-03
4
Medium Priority
?
741 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 100 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Suggested Courses

963 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