Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Otwieranie plików .js
Forum PHP.pl > Forum > Po stronie przeglądarki > JavaScript
nker
Nie mogę otworzyć pliku .js Ponieważ wyskakuje mi że "Serwer automatyzacji nie może utworzyć obiektu"
(Kod: 800A01AD Źródło: Microsoft JScript - błąd czasu wykonywania), przypuszcza że ma to jakiś związek z zabezpieczeniami bo wcześniej działało, niestety nie wiem co zmieniłem. Pozdrawiam
revyag
tzn. jak otwierasz ? edytorem ? dołączasz do strony ?
nker
Nie, normalnie mam plik na twardym. Chcę go wykonać, on pobiera i aktualizuje notowania giełdowe.
kossa
Cytat
błąd czasu wykonywania


napisałeś że skrypt pobiera notowania giełdowe, być może serwer z którego pobierał dane nie odpowiada, lub przesyła nieprawidłowe dane bo tam zmienił się np. układ strony itd.

Łukasz
nker
Niestety nie, w ogóle nie łączy się z tą stroną.
Pisze, że błąd jest w wierszu 22, znak 1. Zamieszczam treść tego pliku:
Kod
/*
** AmiBroker/Win32 scripting Example
**
** File:     WSE.js
** Created:     Tomasz Janeczko, January 12th, 2000
** Purpose:     Download and import quotes from bossa.pl
** Language:      JavaScript (Windows Scripting Host)
**
** Modified:     Marek Chlopek <mchlopek@post.pl>
** Modified v2.0:  Wojciech Filipek <Wojtek_f@mm.pl>
*/

/**************************************************************/
/* GB: Constants                                              */
/* PL: Stałe                                                  */
/**************************************************************/

/* GB: The path to database */
/* PL: Ścieżka do bazy danych */

Forreading = 1;
fs = new ActiveXObject("Scripting.FileSystemObject");
a = fs.OpenTextFile("path.txt", Forreading,true,0);
path=a.ReadLine();
DataDir=path;
a.Close();

/* GB: The ticker to check */
/* PL: Symbol odniesienia */
ChkTicker = "FW20";

/* GB: The folder where the files will be downloaded */
/* PL: Ścieżka do katalogu składowania plików z notowaniami */
DestDir = path+"\\Scripts\\Bossa.pl\\Files\\fut\\";

/* GB: The name and the path to downloader program */
/* PL: Nazwa i ścieżka dostępu do programu pobierającego pliki */
DownloaderPrg  = path+"\\Scripts\\URLGet.exe";

/* GB: Force download - if true causes downloading data file */
/*     even if it exists on the local drive */  
/* PL: Wymuszenie pobierania danych - jeśli 'true' wymusza ściąganie plików */
/*     z danymi nawet jeśli ten plik już istnieje w lokalnym systemie */
ForceDownloadFlag = true;

/* GB: URL from where data are downloaded */
/* PL: URL skąd są pobierane pliki z notowaniami */
URLPrefix = "http://bossa.pl/pub/futures/omega/fut/";

/* GB: extension of file name, YYYYMMDD will be prepended */
/* PL: rozszerzenie nazwy pliku z notowaniami, RRRRMMDD poprzedza rozszerzenie */
FileExt = ".txt";

/* GB: ASCII Importer format file name */
/* PL: nazwa pliku formatu dla ASCII Importer-a */
ASCIIFormatFile = "Bossa.pl.format";

/* GB: max number of days to download when history is empty */
/* PL: maksymalna liczba dni do pobrania */
nMaxHistoryLen = 365;

/**************************************************************/
/* Main part                                                  */
/**************************************************************/

/* Create AmiBroker app object */
AmiBroker = new ActiveXObject( "Broker.Application" );
/* ... and file system object */
FileSys = new ActiveXObject( "Scripting.FileSystemObject" );
WshShell = new ActiveXObject( "WScript.Shell" );

var MiliSecInDay = 24 * 60 * 60 * 1000;

function Download( URL, filename )
{
    if( ! ForceDownloadFlag && FileSys.FileExists( filename ) ) return true;

    if( WshShell.Run( "\"" +DownloaderPrg + "\"" + " " + URL + " " + filename, 0, true ) == 0 ) return true;

    WScript.echo("Download of " + URL + " failed." );

    return false;
}

function Import( filename )
{
    try
    {
        AmiBroker.Import( 0, filename, ASCIIFormatFile );
    }
    catch( e )
    {
        return false;
    }

    /* refresh ticker list and windows */
    AmiBroker.RefreshAll();
    return true;
}

function CheckFolder()
{
    if( ! FileSys.FolderExists( DestDir ) )
    {
        FileSys.CreateFolder( DestDir );
    }
}

function GetNumberOfDaysToLoad()
{
    var Today = new Date();
    var LastDate = new Date();

    LastDate.setDate( LastDate.getDate() - nMaxHistoryLen ); // one year

    if( AmiBroker.Stocks.Count > 0 )
    {
        nQty = AmiBroker.Stocks( ChkTicker ).Quotations.Count;
        if( nQty > 0 )
        {
            LastDate = new Date( AmiBroker.Stocks( ChkTicker ).Quotations( nQty - 1 ).Date );
        }
    }


    // the difference is in milliseconds    
    return ( Math.floor( (Today - LastDate)/MiliSecInDay ) + 1 );

}

function IsValidDatabase()
{
    AmiBroker.SaveDatabase( );
    AmiBroker.LoadDatabase( DataDir );

    if( AmiBroker.Stocks.Count > 0 )
    {
        try
        {
            return AmiBroker.Stocks( ChkTicker ).Ticker == ChkTicker;
        }
        catch( e )
        {
            WScript.echo("The database currently loaded into AmiBroker does not have " + ChkTicker + "\nSo I guess this is not correct database.\nUpdate failed.");
        }
    }

    return false;
}

function Main()
{
    bOK = true;

    if( ! IsValidDatabase() ) return;
    
    var CurDate = new Date();
    var NumDays = GetNumberOfDaysToLoad();

    WScript.echo("Your database is " + NumDays + " day(s) old.\n" + (NumDays > 0 ? "Downloading missing quotes" : "No update is needed" ) );

    CheckFolder();

    for( i = 0; i < NumDays; i++ )
    {
        if( CurDate.getDay() > 0 && CurDate.getDay() < 6 )
        {
            // bussiness day
            y = CurDate.getFullYear();
            m = CurDate.getMonth() + 1;
            d = CurDate.getDate();

            bOK = true;

            filename = y + ( m < 10 ? "0" : "" ) + m + ( d < 10 ? "0" : "" ) + d + FileExt;

            URL = URLPrefix + filename;

            if( y == 2001 && URLPrefix2001 != "" )
            {
                URL = URLPrefix2001 + filename;
            }

            if( Download( URL, DestDir + filename ) )
            {
                if( ! Import( DestDir + filename ) ) bOK = false;
            }
            else
            {
                bOK = false;
            }

            if( ! bOK && WshShell.popup( "The download and/or import of the " + filename + " has failed.\nThis can be because the data are not available or network connection problem.\nDo you want to abort?" , 0, "Abort updating", 4 + 256 ) == 6 )
            {
                break;
            }

        }

        CurDate.setDate( CurDate.getDate() - 1 );
    }

    if( bOK )  WScript.echo("Update script finished. Your database is now up-to-date" );
    else       WScript.echo("Update script finished. There were, however, some errors during download/import");
}

Main();
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.