quote:
Originally posted by stu
Cookie, I will give yours a try now, it looks like I will need to make a few adjustments to it to make it work with my script though
I don't see what you need to adjust...
The function GetRandomLyric() can be used without any modification, as long as your lyrics array is named 'arrLyrics'.
The build-in lyrics array you have in your script (named
Text[]) can simply be overwritten with the array read from the file (named
Lines[]). You don't need two different arrays for that. Name them both
arrLyrics[], stick in the routine I showed and you're done...
PS: and make your 'FileToArray' code as a seperate function and let it simply return an array so you can do:
if (which === 0) arrLyrics = FileToArray('C:\\quotes.txt'));
or, to preserve the contents of the existing array also:
if (which === 0) arrLyrics.concat(FileToArray('C:\\quotes.txt'))
code:
function FileToArray(sFileName) {
var arrTemp = new Array();
var oFSO = new ActiveXObject("Scripting.FileSystemObject")
if (oFSO.FileExists(sFileName)) {
var oFile = oFSO.OpenTextFile(sFileName, 1);
while(!oFile.AtEndOfStream) {
var sLine = oFile.ReadLine().replace(/^\s+|\s+$/g,'');
if (sLine !== '') arrTemp.push(sLine);
}
oFile.Close();
}
return arrTemp;
}
quote:
Originally posted by stu
Ok, so like CookieRevised said, the suggestions made did not work..
they work, but it can be done in a much shorter and faster way.