All of my JavaScript thus far has been as part of a webpage, but have been encouraged to create "tools" where text is provided to a function as a parm from "StdIn" and returned to a StdOut. This is part of the code I've seen:My questions are 1) How to set a program code or error code if there is a major problem? 2) How to look at answers to prompts on startup? 3) A good resource for WScript programs.Code:function calculate(clip) { var seltab = new Array(), PosTab = new Array(); var i, j, k, OutText = "", begChord = "", endChord = ""; var cntNotes=0, begpnt, endpnt; var lines = new Array(); /* lines = document.nwcform.OutputField.value.split("\n"); there is no document object in CScript, so this need to be replaced with: */ lines = clip.split("\r\n"); //var WshShell = WScript.CreateObject("WScript.Shell"); // Example of opening a window //WshShell.Popup("Hello from a popup"); for (i=0; i < lines.length; i++) { if (/Note.*Grace.+\:[#bn].+\^/.test(lines[i])) { // Thanks to Declan1991 of webdeveloper.com for help here. begpnt = lines[i].search(/[#bn]-*\d+/); endpnt = lines[i].search(/\^/); seltab[cntNotes++] = lines[i].substr(begpnt, endpnt-begpnt); ........................ snip for brevity........................... /* Again, there is no document. This not needed: document.nwcform.OutputField.value = "" //To rebuild textarea for (i = 0 ; i < lines.length; i++) { document.nwcform.OutputField.value += lines[i]; if ((cntNotes - i) > 1) document.nwcform.OutputField.value += "\n"; } document.nwcform.OutputField.select(); //Pre selected for Cntl/C Instead,use: */ return lines; } //End of function /* Execution begins here: */ WScript.StdOut.Write(calculate(WScript.StdIn.ReadAll()).join("\r\n")); WScript.StdErr.Write("An error message would go here"); // and the calling program showed it to me.
TIA


Reply With Quote

Bookmarks