|
#1
|
|||
|
|||
I am a programmer without a compiler, and a sh-tty one at that.
I like programming. I've used VB, java, perl, QBASIC (woot!), and that's about it.
However, my linux box is down, and I like the flexibility of programming using javascript, considering that windows seems to run it just fine with minimal effort on my part. ---------- So I'd like to know a few things about javascript programming. 1) Can they output to text files. * 2) Can they output to HTML files. * 3) How do I make arrays? 4) How do I gather user input and make a WHILE loop? * easily, hopefully. ---------------------------------------------- link The following shows some code with the alert and prompt statements, which is part of what I need. It also shows a function (though no function variables are used), and a for loop. It shows arrays being used. So basically, I need to know the while loop and how to export to text. This shows a while loop --- Alright... so basically everything's been answered except the "how to output to text and html" thing... If I could get that, I'd be pretty happy. [img]/images/graemlins/smile.gif[/img] --- Edit: function with an argument |
#2
|
|||
|
|||
Re: I am a programmer without a compiler, and a sh-tty one at that.
The javascript can produce text output as in:
document.write('hello world'); to make text into HTML just use HTML commands: document.write('<h1>Hello World<h1>'); Not sure how you run your javascripts, but if you run them in your browser the output can be saved with a view-source save command. Or from a command line you can use the > operator after a command and give it a file to write the output to like: runme > output.txt |
#3
|
|||
|
|||
Re: I am a programmer without a compiler, and a sh-tty one at that.
[ QUOTE ]
The javascript can produce text output as in: document.write('hello world'); to make text into HTML just use HTML commands: document.write('<h1>Hello World<h1>'); Not sure how you run your javascripts, but if you run them in your browser the output can be saved with a view-source save command. Or from a command line you can use the > operator after a command and give it a file to write the output to like: runme > output.txt [/ QUOTE ] document.write(string) seems cool... ooc, how do I specify what text file it's printing to? Would I have to use weird java-esque file names: c://foldertowriteto/file.txt or would a standard DOS filepath be okay? I'd prefer to execute the file by double-clicking on it on my desktop or somesuch, so . [img]/images/graemlins/smile.gif[/img] FWIW, the stuff that I've found on the java document object model is very complex stuff. It's way more powerful than what I need to use it for (though it does appear to do what I need to use it for)... Any idea where I could find a dummy's guide to this? --Dave. |
#4
|
|||
|
|||
Re: I am a programmer without a compiler, and a sh-tty one at that.
[ QUOTE ]
[ QUOTE ] The javascript can produce text output as in: document.write('hello world'); to make text into HTML just use HTML commands: document.write('<h1>Hello World<h1>'); Not sure how you run your javascripts, but if you run them in your browser the output can be saved with a view-source save command. Or from a command line you can use the > operator after a command and give it a file to write the output to like: runme > output.txt [/ QUOTE ] document.write(string) seems cool... ooc, how do I specify what text file it's printing to? Would I have to use weird java-esque file names: <a href="c://foldertowriteto/file.txt" target="_blank">c://foldertowriteto/file.txt</a> or would a standard DOS filepath be okay? I'd prefer to execute the file by double-clicking on it on my desktop or somesuch, so . [img]/images/graemlins/smile.gif[/img] FWIW, the stuff that I've found on the java document object model is very complex stuff. It's way more powerful than what I need to use it for (though it does appear to do what I need to use it for)... Any idea where I could find a dummy's guide to this? --Dave. [/ QUOTE ] The security around web browsers will prevent Javascript from writing directly to the hard drive. This is intended to prevent malicious code from affecting computers. The best way to deal with a text file save is to write it to an html text field and then copy and paste the text into a new text file. As for good JS resources, try javascript.internet.com. There are hundreds of scripts here that might point you in the right direction. |
#5
|
|||
|
|||
Re: I am a programmer without a compiler, and a sh-tty one at that.
[ QUOTE ]
[ QUOTE ] [ QUOTE ] The javascript can produce text output as in: document.write('hello world'); to make text into HTML just use HTML commands: document.write('<h1>Hello World<h1>'); Not sure how you run your javascripts, but if you run them in your browser the output can be saved with a view-source save command. Or from a command line you can use the > operator after a command and give it a file to write the output to like: runme > output.txt [/ QUOTE ] document.write(string) seems cool... ooc, how do I specify what text file it's printing to? Would I have to use weird java-esque file names: <a href="c://foldertowriteto/file.txt" target="_blank">c://foldertowriteto/file.txt</a> or would a standard DOS filepath be okay? I'd prefer to execute the file by double-clicking on it on my desktop or somesuch, so . [img]/images/graemlins/smile.gif[/img] FWIW, the stuff that I've found on the java document object model is very complex stuff. It's way more powerful than what I need to use it for (though it does appear to do what I need to use it for)... Any idea where I could find a dummy's guide to this? --Dave. [/ QUOTE ] The security around web browsers will prevent Javascript from writing directly to the hard drive. This is intended to prevent malicious code from affecting computers. The best way to deal with a text file save is to write it to an html text field and then copy and paste the text into a new text file. As for good JS resources, try javascript.internet.com. There are hundreds of scripts here that might point you in the right direction. [/ QUOTE ] ------------ I'd heard about this, and to be honest, while I'm unhappy that I can't do what I want, this is probably still A Good Thing. However, does this still take effect even if I'm running off of a file in my c:\? ---- From the way this is going, I'm probably going to be stubbornly writing javascript until I have to make serious output: what I'm working on right now is just a step-through process that will choose bet sizes for me. I'm sure I'll hit the wall eventually and need perl. When I do, it's ActiveState for me. [img]/images/graemlins/smile.gif[/img] Thanks guys. Piping output though sounds great, as does outputting to html. It should be fun to try that out. I'll be at javascript.internet.com for a while. --Dave. |
#6
|
|||
|
|||
Re: I am a programmer without a compiler, and a sh-tty one at that.
Hi DavidC,
you can indeed write (and read) text files from JavaScript, so long as you are not using a web browser to execute the scripts. Use the *.js method, as used for the PT scripts, and there is no security imposed on the code. It looks like you've got arrays & functions, so here's a quick example: This gets the names of all players in the chosen PTDB that are autorated as a fish, stores their screen names in an array, then writes the contents of the array to a text file, in the same folder as the script is run from. Make sure there is not already an important file names "fish_list.txt" in your Poker Tracker directory, it will be overwritten. Writing an Array to a Text File Example: fish_list.js <font class="small">Code:</font><hr /><pre> ///// change settings here ///// var ptdb = 'ptrack11'; var fish_icon = 2; var output_filename = "list_of_fish.txt"; //////////////////////////////// ///// Globals ///////// var db = new ActiveXObject("ADODB.Recordset"); var cstring = "Driver={Microsoft Access Driver (*.mdb)};DBQ="+ptdb+".mdb"; var totalhands = 0; var sql = ''; var output_array = new Array(); /////////////////////////// //// functions /////// function outFile(arr, output_file) { var c = arr.length; var scriptfile = WScript.ScriptFullName; var fso = new ActiveXObject("Scripting.FileSystemObject"); var f = fso.GetFile(scriptfile); var scriptpath = f.ParentFolder; var outpath = scriptpath + "\\" + output_filename; var a = fso.CreateTextFile(outpath, true); for(var k=0; k<c; k++) { a.WriteLine(arr[k]); } a.Close(); } ////////////////////// /// Retrieve the players from PokerTracker DB /// Whom have been atorated with a "Fish" icon sql = "SELECT screen_name FROM players" +" WHERE treeview_icon="+fish_icon+";"; db.Open(sql, cstring, 1, 3); // cycle through the recordset using MoveNext, // add each name to the next slot of the array for (var i=0; i < db.RecordCount; i++) { output_array[output_array.length] = db(0) +""; db.MoveNext(); } db.Close(); outFile(output_array, output_filename); WScript.Echo(output_filename +" Written"); </pre><hr /> Enjoy! dave. |
#7
|
|||
|
|||
Re: I am a programmer without a compiler, and a sh-tty one at that.
[ QUOTE ]
I'd heard about this, and to be honest, while I'm unhappy that I can't do what I want, this is probably still A Good Thing. However, does this still take effect even if I'm running off of a file in my c:\? [/ QUOTE ] Yeah - I am afraid so. The browser doesnt care where the file resides (and all web pages exist on your hard drive in a cache anyway...) Have you considered learning Java? Its not a ton more difficult than Javascript at the more basic levels and its free. Check out Sun's website. They have soem great beginners tutorials. |
#8
|
|||
|
|||
Re: I am a programmer without a compiler, and a sh-tty one at that.
It can't write to a file. It can output to your browser which you can then save to a file. Or if you are somehow running it from the command line then you can "pipe" the output to a file using your operating system functions to redirect output to a file. But the language itself does not support any Input/Output commands.
I'm with the others, you will run into your boundaries soon with JavaScript. Perl or PHP isn't that huge of a leap to screw around with, but your upside capabilities to progress into more involved applications are significant. |
#9
|
|||
|
|||
Re: I am a programmer without a compiler, and a sh-tty one at that.
Out of curiosity, what did you find difficult about using Perl on Windows?
It would seem that for what you're looking for (quick text processing) Perl would be the thing. |
#10
|
|||
|
|||
Re: I am a programmer without a compiler, and a sh-tty one at that.
[ QUOTE ]
Out of curiosity, what did you find difficult about using Perl on Windows? It would seem that for what you're looking for (quick text processing) Perl would be the thing. [/ QUOTE ] This would be for iterative bet-size calculations. Java should do okay for this purpose. But yes, perl totally pwns for... well... everything actually. [img]/images/graemlins/cool.gif[/img] I tried setting up perl on windows once and it was a huge hassle. On linux it was very easy (might have even been part of the core that I used). |
|
|