I think I posted this question before, but anyway.. When coding JScript for the CLS, does JScript have a "main()" function like in C# or C++? I haven't been able to find one or anything like it in the SDK documentation.
[System.STAThread()]
public static void main(String[] args)
{
Application.Run(new Form1());
}
All that you need to do is change that statement to the equive of JScript. There just has to be the System.STAThread() on top of a static method. I am not sure if it has to be called main but I don't think so.
I have tried this, but I can't seem to get it to work. JScript attaches attributes to functions with the attribute name and the keyword "Attribute". ie: STAThreadAttribute, not with the square braces [], and placing a function parameter argument block doesn't
seem to work. THe compiler generates: Bad function calling. Can you explaing this?
I can only post the main function part of it only, the rest is probably to big to fit on screen: (and yes, the main part is inside a class declaration) STAThreadAttribute(); public function main() : int { Console.WriteLine("Hello: test" + var_IsOn); ask();
wcalcd(); } This without the STAThreadAttribute does not generate any errors, but the main function is not called unless a statement is place at the very top of the source code outside any class or function declarations.
You need to make the main() function static, this is because the method is not accessable unless the object is created and since the main() method is suppose to create the object you sort of have a Catch22.
A good reference is http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsintro7/html/vxorilanguageequivalentskeywords.asp?frame=true and http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsintro7/html/vxgrfLanguageEquivalents.asp?frame=true
STAThreadAttribute();
public static function main() : int {
Console.WriteLine("Hello: test" + var_IsOn);
ask();
wcalcd();
}
Modifying the main function making it static doesn't seem to resolve all the issues, it resolves all but one, stating where I declared the STAThreadAttribute(); as a syntax error. JS1002: Syntax Error (line 230, 1) can you explain this too?
Try this. I don't think you need the attribute at the end of the attribute but that wouldn't cause the problem. I think it was hte semi colon you put on it.
STAThread()
public static function main() : int {
Console.WriteLine("Hello: test" + var_IsOn);
ask();
wcalcd();
}
Hope this works. Can I ask you one question? Why are you using JScript, when you could just as
easily use C#? You would have the use of a couple great IDE's #Develop (Free), VS.Net, or Borland. Also if you want you can take in an array of strings in the main method if you want arguments passed from the command line. Well good luck.
You raise many valid points Mr Nberardi about using C# as an alternative, as I have reviewed the language specifications for C# in documentation, and yes, I could just as easily use C#, but my first ever language I ever learnt was JScript, and when I found
out Microsoft ported JScript as a compiled executable form, I was quite estatic about creating my own applications in exe form without learning another language. But I have written alot of, somewhat rudimentary applications, in JScript.NET (because I didn't
know if JScript.NET had an application entry point), and although I probably could easily leverage the power of C#, I would prefer JScript.NET over the rest as thats the first language I was first acustomed to.
I haven't tried your solution yet Mr nberardi cause I'm not at home and these computers don't have the .NET Framework installed, but I do hope it does work.
decpersona
Member
310 Points
62 Posts
Does JScript.NET have a "main()" function for global arguments?
Jan 22, 2004 12:44 AM|LINK
nberardi
Star
11233 Points
2352 Posts
Re: Does JScript.NET have a "main()" function for global arguments?
Jan 22, 2004 04:09 PM|LINK
[System.STAThread()] public static void main(String[] args) { Application.Run(new Form1()); }All that you need to do is change that statement to the equive of JScript. There just has to be the System.STAThread() on top of a static method. I am not sure if it has to be called main but I don't think so.decpersona
Member
310 Points
62 Posts
What does this do?
Feb 03, 2004 11:58 PM|LINK
nberardi
Star
11233 Points
2352 Posts
Re: What does this do?
Feb 04, 2004 01:26 AM|LINK
decpersona
Member
310 Points
62 Posts
Re: What does this do?
Feb 05, 2004 02:06 AM|LINK
nberardi
Star
11233 Points
2352 Posts
Re: What does this do?
Feb 05, 2004 11:45 AM|LINK
nberardi
Star
11233 Points
2352 Posts
Re: What does this do?
Feb 05, 2004 01:31 PM|LINK
STAThreadAttribute(); public static function main() : int { Console.WriteLine("Hello: test" + var_IsOn); ask(); wcalcd(); }decpersona
Member
310 Points
62 Posts
Re: What does this do?
Feb 09, 2004 12:27 AM|LINK
nberardi
Star
11233 Points
2352 Posts
Re: What does this do?
Feb 09, 2004 11:39 AM|LINK
STAThread() public static function main() : int { Console.WriteLine("Hello: test" + var_IsOn); ask(); wcalcd(); }Hope this works. Can I ask you one question? Why are you using JScript, when you could just as easily use C#? You would have the use of a couple great IDE's #Develop (Free), VS.Net, or Borland. Also if you want you can take in an array of strings in the main method if you want arguments passed from the command line. Well good luck.decpersona
Member
310 Points
62 Posts
In answer to your question
Feb 11, 2004 12:24 AM|LINK
I haven't tried your solution yet Mr nberardi cause I'm not at home and these computers don't have the .NET Framework installed, but I do hope it does work.