Page 35 of 97

Posted: Wed Nov 03, 2010 3:11 am
by Instructor
VladSh
Должен вызывать плагин программы NSIS.
http://nsis.sourceforge.net/Category:Plugins

Posted: Wed Nov 03, 2010 5:17 am
by KDJ
New version SelectRangeText.js script now supports the index (line, column) and offset.

Posted: Fri Nov 05, 2010 7:12 pm
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?

Posted: Fri Nov 05, 2010 8:32 pm
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

Posted: Fri Nov 05, 2010 8:42 pm
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());

Posted: Fri Nov 05, 2010 8:50 pm
by FeyFre
Most of developers will brake brain while dealing with VARIANT/SAFEARRAY parts of COM. :wink:

Posted: Fri Nov 05, 2010 10:09 pm
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?

Posted: Fri Nov 05, 2010 10:16 pm
by FeyFre
KDJ, ask something easier.

Posted: Fri Nov 05, 2010 10:23 pm
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.

Posted: Fri Nov 05, 2010 10:54 pm
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
);

Posted: Sat Nov 06, 2010 1:05 am
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]"
);

Posted: Sat Nov 06, 2010 2:38 pm
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.

Posted: Mon Nov 08, 2010 8:12 pm
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

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

Posted: Mon Nov 08, 2010 9:02 pm
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

Posted: Mon Nov 08, 2010 9:30 pm
by koros
Спасибо. Помогло.