Solved

JScript "Main" function

Posted on 1997-06-03
4
722 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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

632 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