0

I'm trying to read a text file but it keeps outputting the following error:

"Object doesn't support this property or method"

Here is the code i'm using the only info the error gave me was that the problem was on line 80

var now = new Date().getTime();
var fso = new ActiveXObject("Scripting.FileSystemObject");
if (!fso.FileExists("1278468327648.txt")) {
    var deadline = now + 172800002
    var write_id;
    write_id = deadline;
    var s = fso.CreateTextFile("1278468327648.txt", true);
    s.WriteLine(deadline);
    s.Close();
}
var a = fso.OpenTextFile("1278468327648.txt", 1, true, 0);
//Line 80
var txtleft = a.ReadAll();
a.close;
var x = setInterval(function() { 
        var now = new Date().getTime();
        var t = txtleft - now;
        var days = Math.floor(t / (1000 * 60 * 60 * 24)); 
        var hours = Math.floor((t%(1000 * 60 * 60 * 24))/(1000 * 60 * 60) + (days * 24)); 
        var minutes = Math.floor((t % (1000 * 60 * 60)) / (1000 * 60)); 
        var seconds = Math.floor((t % (1000 * 60)) / 1000); 
        if (seconds < 10) {
            seconds = "0" + seconds
        }
        if (minutes < 10) {
            minutes = "0" + seconds
        }
        if (hours < 10) {
            hours = "0" + seconds
        }
        document.getElementById("demo").innerHTML = "Time Left: " + hours + ":" + minutes + ":" + seconds; 
        if (t < 0) { 
            clearInterval(x); 
            document.getElementById("demo").innerHTML = "EXPIRED"; 
        } 
    }, 1000);
}
Tyler
  • 37
  • 7
  • Ok I tried this and i gave me the same error – Tyler Feb 07 '20 at 19:26
  • wait I think I accidentally deleted your comment sorry – Tyler Feb 07 '20 at 19:28
  • `var a = fso.OpenTextFile("1278468327648.txt", 1, true);` Like this? – Tyler Feb 07 '20 at 19:39
  • It doesn't matter, the default value is `0`, if the argument is omitted. I can't see anything wrong in the code, it should work as it is. – Teemu Feb 07 '20 at 19:41
  • And it also works as it is, when I run on my machine. – Teemu Feb 07 '20 at 19:47
  • https://imgur.com/a/GT4oRhh – Tyler Feb 07 '20 at 19:48
  • IE sometimes shows entirely wrong line for the error. Is there some other code after `a.close`? You could create a copy of the file as .html, and run it with IE, you could at least get a console to debug with, though setting of the permission requests is annoying. – Teemu Feb 07 '20 at 19:50
  • I edited the question to include the rest of the code after a.close – Tyler Feb 07 '20 at 19:53
  • Bah, it's the file close line, you need parentheses. i.e. `a.Close();`. I ran my HTA in IE9 mode, and it tolerates also `a.close;`. – Teemu Feb 07 '20 at 20:00
  • I changed it to a.Close(); and it still outputs the error with the same exact message – Tyler Feb 07 '20 at 20:02
  • After commenting out the line `var txtleft = a.ReadAll;` it runs fine so this is the problem – Tyler Feb 07 '20 at 20:05
  • No this turns to odd. Please see [this post](https://stackoverflow.com/a/19570684/1169519), and upgrade the IE version your HTA uses. There sholud be parenthesis on that line too. – Teemu Feb 07 '20 at 20:05
  • It works not after changing ReadAll; to ReadAll(); – Tyler Feb 07 '20 at 20:09
  • It seems, there is an unmatched } at the end of your code. When I remove it (and encapsulate the code into an HTA) it works for me, as is. Though, just for completeness, I still would clean up that code (missing semicolons, case, correct function calls.) – amix Feb 16 '20 at 21:06

0 Answers0