What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Read Text from a file

Read Text from a file
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: Read Text from a file
You guys are still using the bugged version of ReadLineFromFile(). On the last line, "FileContents" is misspelled, which I already mentioned in my previous post.

Another possible issue could be that the file you're trying to read is saved as Unicode. By default, OpenTextFile reads the file as ASCII so you need to pass in an extra parameter to override this behavior. Therefore, I added an extra parameter to the function which takes care of this. You could try to detect whether a file is saved as ASCII or Unicode, but that requires some Win32 trickery.
Javascript code:
function ReadLineFromFile(sFile, nLine, bUnicode) {
    var f = new ActiveXObject("Scripting.FileSystemObject").OpenTextFile(sFile, 1 /* ForReading */, false, (bUnicode ? -1 : 0));
    var s = f.ReadAll();
    f.Close();
    var FileContents = s.split(/\r?\n/);
    if(nLine > FileContents.length) return false; // implement some error handling here?
    return FileContents[nLine-1];
}
 
function OnEvent_ChatWndSendMessage(oChatWnd, sMessage) {
    var m;
    if (m = /^\/([^ \n\r\v\xA0\/][^ \n\r\v\xA0]*)[\s\xA0]?([\s\S]*)/.exec(sMessage)) {
        var command = m[1].toLowerCase();
        var parameter = m[2];
        if (command == 'acserv') {
            var line = ReadLineFromFile("C:\\Program Files\\AssaultCube_v1.1.0.3\\config\\saved.cfg", 255, false); // change false to true if Unicode
            // line now contains the 255th line from saved.cfg
            line = line.replace('alias "serverinfo [', '');
            line = line.replace(']', '');
            return line;
        }
    }
    return sMessage;
}

Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
11-07-2010 07:42 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Read Text from a file - by TehGoatLord on 11-07-2010 at 02:51 AM
RE: Read Text from a file - by matty on 11-07-2010 at 03:40 AM
RE: Read Text from a file - by TehGoatLord on 11-07-2010 at 04:47 AM
RE: Read Text from a file - by Matti on 11-07-2010 at 10:11 AM
RE: Read Text from a file - by TehGoatLord on 11-07-2010 at 02:02 PM
RE: Read Text from a file - by TehGoatLord on 11-07-2010 at 02:04 PM
RE: Read Text from a file - by matty on 11-07-2010 at 02:10 PM
RE: Read Text from a file - by TehGoatLord on 11-07-2010 at 04:47 PM
RE: Read Text from a file - by whiz on 11-07-2010 at 05:24 PM
RE: Read Text from a file - by TehGoatLord on 11-07-2010 at 06:09 PM
RE: Read Text from a file - by matty on 11-07-2010 at 06:30 PM
RE: Read Text from a file - by TehGoatLord on 11-07-2010 at 06:48 PM
RE: Read Text from a file - by Matti on 11-07-2010 at 07:42 PM
RE: Read Text from a file - by TehGoatLord on 11-07-2010 at 08:01 PM
RE: Read Text from a file - by matty on 11-07-2010 at 08:07 PM
RE: Read Text from a file - by TehGoatLord on 11-07-2010 at 08:14 PM
RE: Read Text from a file - by Matti on 11-07-2010 at 08:22 PM
RE: Read Text from a file - by TehGoatLord on 11-07-2010 at 08:30 PM
RE: Read Text from a file - by Matti on 11-07-2010 at 08:42 PM
RE: Read Text from a file - by TehGoatLord on 11-07-2010 at 08:51 PM
RE: Read Text from a file - by Matti on 11-07-2010 at 10:36 PM
RE: Read Text from a file - by TehGoatLord on 11-07-2010 at 10:45 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On