Active window on the application is a chart but when i run the javascript using cscript Amibroker.js
, i see error:Microsoft JScript runtime error: 'chart' is null or not an object on line chart.GotoDateTime(dateTime);
// Define the year, month, and date
var year = 2023;
var month = 11;
var date = 11;
// Create a Date object
var dateObj = new Date(year, month - 1, date); // Subtract 1 from month
// Create the main OLE automation object for AmiBroker
var AB = new ActiveXObject("Broker.Application");
// Get the active chart
var chart = AB.ActiveDocument.ActiveWindow.Chart;
// Format the date in the required format
var dateTime = dateObj.getFullYear() + "-" + ("0" + (dateObj.getMonth() + 1)).slice(-2) + "-" + ("0" + dateObj.getDate()).slice(-2) + " 00:00:00";
// Go to the specific date
chart.GotoDateTime(dateTime);
WScript.Echo(dateTime);
The error message you're encountering, "Microsoft JScript runtime error:
chart
is null or not an object," indicates that thechart
object is not being retrieved correctly from theAmiBroker
application. This could be due to a few reasons, such as no active chart being open or theAmiBroker
application not being properly initialized.Try using a delay: There might be a timing issue where the script is trying to access the
chart
object before it's fully available. You can try adding a delay before attempting to access thechart
object, using theWScript.Sleep
method.For example: