Solved

JScript "Main" function

Posted on 1997-06-03
4
675 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

896 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