Scripts discussion (1)

Discuss and announce AkelPad plugins
Locked
  • Author
  • Message
Offline
Site Admin
Posts: 6403
Joined: Thu Jul 06, 2006 7:20 am

Post by Instructor »

VladSh
Должен вызывать плагин программы NSIS.
http://nsis.sourceforge.net/Category:Plugins

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

New version SelectRangeText.js script now supports the index (line, column) and offset.
Last edited by KDJ on Sat Nov 13, 2010 8:06 pm, edited 1 time in total.

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

I wanted to read the file creation date and convert it to a string.
The following code generates a runtime error (in the last line).

Code: Select all

var FileName = AkelPad.GetEditFile(0);
var oFSO     = new ActiveXObject("Scripting.FileSystemObject");
var oFile    = oFSO.GetFile(FileName);
var FileDate = oFile.DateCreated;
var DateStr  = FileDate.toString();
Where is the error?

Offline
Posts: 2248
Joined: Tue Aug 07, 2007 2:03 pm
Location: Vinnitsa, Ukraine

Post by FeyFre »

KDJ, because:
From scrrun.dll embedded TypeLib

Code: Select all

interface IFile : IDispatch {
//...
HRESULT DateCreated([out, retval] DATE* pdate);
//...
}
And as defined in Windows SDK WTypes.idl

Code: Select all

typedef double DATE;
So technically this property is not instance of JScript object Date, but of type DATE - floating number of double precision(DATE - specially separated type in COM to mark number as a container of Date/Time value).
You should use it in following way:

Code: Select all

var DateStr  = Date(FileDate)
Or

Code: Select all

FileDate+1 // next day

Offline
Posts: 1873
Joined: Mon Aug 06, 2007 1:07 pm
Contact:

Post by Infocatcher »

KDJ wrote:Where is the error?
MS JScript has some strange things. :?

Code: Select all

var FileName = AkelPad.GetEditFile(0);
var oFSO     = new ActiveXObject("Scripting.FileSystemObject");
var oFile    = oFSO.GetFile(FileName);
var FileDate = new Date(oFile.DateCreated);
WScript.Echo(FileDate.toString());
WScript.Echo(FileDate.toLocaleString());

Offline
Posts: 2248
Joined: Tue Aug 07, 2007 2:03 pm
Location: Vinnitsa, Ukraine

Post by FeyFre »

Most of developers will brake brain while dealing with VARIANT/SAFEARRAY parts of COM. :wink:

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

FeyFre and Infocatcher, thanks for the explanation.
By the way, I noticed that these codes work the same:
var FileDate = new Date(oFile.DateCreated);
var FileDate = Date(oFile.DateCreated);
Does this mean that "new" can be omitted?

Offline
Posts: 2248
Joined: Tue Aug 07, 2007 2:03 pm
Location: Vinnitsa, Ukraine

Post by FeyFre »

KDJ, ask something easier.

Offline
Posts: 1873
Joined: Mon Aug 06, 2007 1:07 pm
Contact:

Post by Infocatcher »

Code: Select all

var n = 128e10;
var d0 = Date(n);
var d1 = new Date(n);
WScript.Echo(
	typeof d0 + "\n" + // string
	typeof d1          // object
);
And you can use some useful methods (msdn) of Date object in second case.

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

But in the case of the array is the same:

Code: Select all

var n = 10;
var d0 = Array(n);
var d1 = new Array(n);
WScript.Echo(
   typeof d0 + "\n" + // object
   typeof d1          // object
);

Offline
Posts: 1873
Joined: Mon Aug 06, 2007 1:07 pm
Contact:

Post by Infocatcher »

KDJ wrote:But in the case of the array is the same
https://developer.mozilla.org/en/JavaSc ... w_Operator

Code: Select all

var ret = new someFunction();
should always return new object, but result of direct call

Code: Select all

var ret = someFunction();
depends on someFunction implementation:

Code: Select all

function someFunction(x) {
    return String(x);
}
var n = 128e10;
var d0 = someFunction(n);
var d1 = new someFunction(n);
WScript.Echo(
   typeof d0 + ": " + // string
   d0 + "\n" +        // "1280000000000"
   typeof d1 + ": " + // object
   d1                 // "[object Object]"
);

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

Here I collected the differences, depending on the initialization of variables.

Code: Select all

//Array
var x = [];             //typeof: object
var y = Array(x);       //typeof: object
var z = new Array(x);   //typeof: object
//RegExp
var x = /a/;            //typeof: object
var y = RegExp(x);      //typeof: object
var z = new RegExp(x);  //typeof: object
//String
var x = "10";           //typeof: string
var y = String(x);      //typeof: string
var z = new String(x);  //typeof: object
//Number
var x = 10;             //typeof: number
var y = Number(x);      //typeof: number
var z = new Number(x);  //typeof: object
//Boolean
var x = true;           //typeof: boolean
var y = Boolean(x);     //typeof: boolean
var z = new Boolean(x); //typeof: object
//Date
var oFSO     = new ActiveXObject("Scripting.FileSystemObject");
var FileDate = oFSO.GetFile(AkelPad.GetEditFile(0)).DateCreated;
var x = FileDate;       //typeof: date
var y = Date(x);        //typeof: string
var z = new Date(x);    //typeof: object
In the case of Array and RegExp is always the type of object.
In the case of String, the, the type can be string or object.
And in the case of Date, the type is date, string or object.

Offline
Posts: 58
Joined: Sat Apr 12, 2008 11:43 am

Post by koros »

У меня следующая проблема - запускаю скрипт CreateSubParagraph.js с помощью Toolbar плагина:
-"Создание новой строки с отступом и существующим типом пункта" Call("Scripts::Main", 1, "CreateSubParagraph.js", "", 0)Icon("%a\AkelFiles\Plugs\Paragraph.ico")
и получаю следующую ошибку:

D:\MyAkelPad\AkelFiles\Plugs\Scripts\CreateSubParagraph.js
Строка: 6
Символ: 1
Oшибкa: 'oCh' - oпpeдeлeниe oтcyтcтвyeт
Кoд: 800A1391
Иcтoчник: Oшибкa выпoлнeния Microsoft JScript

В чем может быть затык?

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

koros
You must also have selCompleteLine.js script:
D:\MyAkelPad\AkelFiles\Plugs\Scripts\selCompleteLine.js.
Here it is written: viewtopic.php?p=4890#p4890

Offline
Posts: 58
Joined: Sat Apr 12, 2008 11:43 am

Post by koros »

Спасибо. Помогло.
Locked