Solved

JScript "Main" function

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
assigning javascript variable to php variable 8 69
Boolean 13 51
Call a VB.net function in Javascript 6 52
Why am I getting SyntaxError: missing ; before statement error 39 83
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

752 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