Calling undefined function in JScript causes exception, was: AmiQuote

Hello,
I running the below code and get "exception object expected" every time. If I click OK, the Amiquote will exit immediately; If I remove RunEvery(60), it amiquote will as soon as it is started.

I wanna run amiquote silently without interrupting my working.

Is there anything wrong with my code?
Thanks!

AQ = new ActiveXObject("AmiQuote.Document");

try
{
	while ( AQ.DownloadInProgress) WScript.Sleep( 500 ); // check IsBusy every 0.5 second
	while ( AQ.ImportInProgress) WScript.Sleep( 500 ); // check IsBusy every 0.5 second
  
        AQ.Open( "C:\\Users\\Administrator\\OneDrive\\Watchlist\\Watchlist\\symbols.tls" ); 
	AQ.Download(); 
        AQ.AutoImport; 
	RunEvery(60);
}

catch ( err )
{
     WScript.echo( "Exception: " + err.message ); // display error that may occur
}

Your RunEvery function is NOT defined anywhere. In your current code, you are calling function that you did not define.

If you wanted to access RunEvery property of AmiQuote object you should specify OBJECT and use . (member access) operator:

AQ.RunEvery = 60; // RunEvery is a **property** of AQ object, not a stand-alone function

Thank you Tomasz.

Should I change AQ.AutoImport = 1 too? I changed the code as following, but everytime, it open amiquote and close it immediately. The symbol list is 120 symbols so it should take longer time.

AQ = new ActiveXObject("AmiQuote.Document");

try
{
	while ( AQ.DownloadInProgress) WScript.Sleep( 500 ); // check IsBusy every 0.5 second
	while ( AQ.ImportInProgress) WScript.Sleep( 500 ); // check IsBusy every 0.5 second
  
        AQ.Open( "C:\\Users\\Administrator\\OneDrive\\Watchlist\\Watchlist\\symbols.tls" ); 
	AQ.Download(); 
        AQ.AutoImport = 1; 
	AQ.RunEvery() = 60;
}

catch ( err )
{
     //WScript.echo( "Exception: " + err.message ); // display error that may occur
}


The order of function calls in your script is incorrect. You should first call AQ.Download and LATER wait for completion, not the other way round as you are doing now.

It works great now! Thank you so much!

Just post the correct code that might be helpful to others.

AQ = new ActiveXObject("AmiQuote.Document");

try
{
        AQ.Open( "C:\\Users\\Administrator\\OneDrive\\Watchlist\\Watchlist\\symbols.tls" ); 
	AQ.Download(); 
	while ( AQ.DownloadInProgress) WScript.Sleep( 500 ); // check IsBusy every 0.5 second
        AQ.AutoImport = 1; 
	while ( AQ.ImportInProgress) WScript.Sleep( 500 ); // check IsBusy every 0.5 second
	AQ.RunEvery() = 60;
}

catch ( err )
{
     //WScript.echo( "Exception: " + err.message ); // display error that may occur
}


Actually this code isn't correct because you have set all settings PRIOR to actions. And you are still NOT reading my posts carefully and make the same error over again.

AQ = new ActiveXObject("AmiQuote.Document");

try
{
    AQ.Open( "C:\\Users\\Administrator\\OneDrive\\Watchlist\\Watchlist\\symbols.tls" ); 
    // settings FIRST!
    AQ.AutoImport = 1; 
    AQ.RunEvery = 60;
    // after everything is set do the ACTION
    AQ.Download(); 
	while ( AQ.DownloadInProgress || AQ.ImportInProgress) WScript.Sleep( 500 ); // check IsBusy every 0.5 second
}

catch ( err )
{
     //WScript.echo( "Exception: " + err.message ); // display error that may occur
}

i got the below error after i run the code and it failed to update any data.

image

Looks like you are wrong this time :wink: After moving the AQ.AutoImport = 1 and AQ.RunEvery() = 60 at the end, it can update data but still show the above exception.

AQ = new ActiveXObject("AmiQuote.Document");

try
{
    AQ.Open( "C:\\Users\\Administrator\\OneDrive\\Watchlist\\Watchlist\\symbols.tls" ); 

    // after everything is set do the ACTION
    AQ.Download(); 
	while ( AQ.DownloadInProgress || AQ.ImportInProgress) WScript.Sleep( 500 ); // check IsBusy every 0.5 second

    // settings FIRST!
    AQ.AutoImport = 1; 
    AQ.RunEvery() = 60;
}

catch ( err )
{
     WScript.echo( "Exception: " + err.message ); // display error that may occur
}

I gave you the answer A COUPLE OF POSTS ago. But you did not read that answer carefully and did not copy-paste it properly.

As I earlier pointed out, your code is wrong. You are using RunEvery as function while it is PROPERTY. REMOVE all that try-catch because it is misleading you into thinking that the code is good. But is not. Your modified code has SYNTAX ERROR. You are modifying the code without knowing what you are doing. Property is not a function. RunEvery must be used as property, i.e. WITHOUT braces. If you can't program with JScript, don't use it.

Again and again, you ignored previous advice:

AQ.RunEvery() = 60; // THIS IS WRONG RunEvery is NOT A FUNCTION!  

while it should be:

AQ.RunEvery = 60; // it is PROPERTY, NO BRACES!!!

as I wrote A COUPLE OF POSTS ago.

Use BATCH WINDOW instead for automating your daily tasks

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.