What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Tips

Tips
Author: Message:
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: RE: Tips
To show how things can be made shorter:


As an example I'll take the 'file existing' routine shown by Chris Boulton.
code:
// Checking if a file exists:

function file_exists(file)
{
    var fileSys = new ActiveXObject("Scripting.FileSystemObject");
    if(fileSys.FileExists(file))
    {
        return true;
    }
    else
    {
        return false;
    }
}
If you use an IF THEN ELSE structure to check on a function which only returns true or false on its own, you can do:
code:
return fileSys.FileExists(file)
Since filesys is an object which you have defined before and since this is only used once, you don't specifically need it to be defined as a variable but you can use it directly:
code:
return new ActiveXObject("Scripting.FileSystemObject").FileExists(file)
All this makes that the function is reduced to only 1 line:
code:
function file_exists(file)
{
    return new ActiveXObject("Scripting.FileSystemObject").FileExists(file);
}


-------------------------------

Various short functions derived from VB6:

see "CookieRevised's reply to [I help them] VB2JS"
.-= A 'frrrrrrrituurrr' for Wacky =-.
10-21-2006 01:44 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Tips - by surfichris on 03-13-2006 at 12:06 PM
RE: Tips - by -dt- on 03-13-2006 at 12:11 PM
RE: Tips - by segosa on 03-13-2006 at 12:39 PM
RE: Tips - by surfichris on 03-13-2006 at 01:13 PM
RE: Tips - by Volv on 04-19-2006 at 06:29 AM
RE: Tips - by -dt- on 04-19-2006 at 06:57 AM
RE: Tips - by davidt on 08-15-2006 at 09:21 AM
RE: RE: Tips - by CookieRevised on 10-21-2006 at 01:44 AM
RE: Tips - by Plan-1130 on 10-25-2006 at 08:15 PM
RE: Tips - by matty on 10-25-2006 at 08:21 PM
RE: Tips - by tryxter on 01-08-2007 at 06:46 PM
RE: Tips - by CookieRevised on 01-28-2007 at 01:15 AM
RE: Tips - by Matti on 06-02-2007 at 05:02 PM
RE: Tips - by Matti on 06-07-2007 at 05:38 PM
RE: Tips - by henry1817 on 12-30-2009 at 04:13 PM
RE: Tips - by matty on 12-30-2009 at 04:20 PM
RE: Tips - by whiz on 06-24-2010 at 10:53 AM


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