Scripts discussion (1)
- Author
- Message
-
Offline
- Posts: 1949
- Joined: Sat Mar 06, 2010 7:40 pm
- Location: Poland
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.
-
Offline
- Posts: 1949
- Joined: Sat Mar 06, 2010 7:40 pm
- Location: Poland
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).
Where is the error?
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();
-
Offline
- Posts: 2248
- Joined: Tue Aug 07, 2007 2:03 pm
- Location: Vinnitsa, Ukraine
KDJ, because:
From scrrun.dll embedded TypeLibAnd as defined in Windows SDK WTypes.idlSo 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:Or
From scrrun.dll embedded TypeLib
Code: Select all
interface IFile : IDispatch {
//...
HRESULT DateCreated([out, retval] DATE* pdate);
//...
}
Code: Select all
typedef double DATE;
You should use it in following way:
Code: Select all
var DateStr = Date(FileDate)
Code: Select all
FileDate+1 // next day
-
Offline
- Posts: 1873
- Joined: Mon Aug 06, 2007 1:07 pm
- Contact:
MS JScript has some strange things.KDJ wrote:Where is the error?

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: 1949
- Joined: Sat Mar 06, 2010 7:40 pm
- Location: Poland
-
Offline
- Posts: 1873
- Joined: Mon Aug 06, 2007 1:07 pm
- Contact:
Code: Select all
var n = 128e10;
var d0 = Date(n);
var d1 = new Date(n);
WScript.Echo(
typeof d0 + "\n" + // string
typeof d1 // object
);
-
Offline
- Posts: 1949
- Joined: Sat Mar 06, 2010 7:40 pm
- Location: Poland
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:
https://developer.mozilla.org/en/JavaSc ... w_OperatorKDJ wrote:But in the case of the array is the same
Code: Select all
var ret = new someFunction();
Code: Select all
var ret = someFunction();
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]"
);
-
Offline
- Posts: 1949
- Joined: Sat Mar 06, 2010 7:40 pm
- Location: Poland
Here I collected the differences, depending on the initialization of variables.
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.
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 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
У меня следующая проблема - запускаю скрипт 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
В чем может быть затык?
-"Создание новой строки с отступом и существующим типом пункта" 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
В чем может быть затык?
-
Offline
- Posts: 1949
- Joined: Sat Mar 06, 2010 7:40 pm
- Location: Poland
koros
You must also have selCompleteLine.js script:
D:\MyAkelPad\AkelFiles\Plugs\Scripts\selCompleteLine.js.
Here it is written: viewtopic.php?p=4890#p4890
You must also have selCompleteLine.js script:
D:\MyAkelPad\AkelFiles\Plugs\Scripts\selCompleteLine.js.
Here it is written: viewtopic.php?p=4890#p4890