Manipuler un objet active X
Bonjour , j’essaie sans succés de faire réagir un objet active X .
Le but du programme est d »envoyer le ticker d’une action située dans un fichier .txt. vers une base de donnée .
J’aie la solution en Javascript mais je rencontre des difficultés pour la retranscrire en VBscript .
Donc voici la solution en javascript .
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
/*
** The data is stored in lines with following format
** <ticker>,<full name>,<industry number>
**
*/
WScript.Echo( "Script Started" );
/* change this line according to your data file name */
ImportStocks("TEST1.txt");
WScript.Echo( "Finished" );
function ImportStocks( filename )
{
var fso, f, r;
var ForReading = 1;
var AmiBroker;
var fields;
var stock;
/* Create AmiBroker app object */
AmiBroker = new ActiveXObject( "Broker.Application" );
/* ... and file system object */
fso = new ActiveXObject( "Scripting.FileSystemObject" );
/* open ASCII file */
f = fso.OpenTextFile( filename, ForReading);
i = 1;
/* read the file line by line */
while ( !f.AtEndOfStream )
{
r = f.ReadLine();
/* split the lines using comma as a separator */
fields = r.split(",");
try
{
/* les symbols sont ajoutés si iln'existent pas */
stock = AmiBroker.Stocks.Add( fields[ 0 ] );
stock.FullName = fields[ 1 ];
stock.IndustryID = parseInt( fields[ 2 ] );
}
catch( e )
{
WScript.echo( "There is a problem in line no." + i + ".\nThe line looks as follows:\n'" + r + "'\nIt will be skipped and next lines will be processed as normal" );
}
i++;
}
AmiBroker.RefreshAll();
} |
Et voici ce que j’aie retranscris en VBscript
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
Option explicit
Dim fso, f, r
Dim fields
Const ForReading = 1
dim AmiBroker
dim collectiondestock
Set AmiBroker = CreateObject("Broker.Application")
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("C:\Documents and Settings\a\Mes documents\TEST1.txt", ForReading)
do While f.AtEndOfStream <> true
r = f.ReadLine()
'wscript.echo r
fields = Split(r,",") ' il fallait faire attention à l'écriture de split ; decoupes r en petits fields (champs)
wscript.echo "La variable " & fields(0) & " est de type " & typename(fields(0)) 'le ticker est de type string
'le fichier test1 peut être decouper en 3 colonnes 0 , 1 , 2 avec la virgule comme séparateur
collectiondestock = Amibroker.stocks.add (fields(0))
collectiondestock.FullName = fields( 1 )
collectiondestock.IndustryID = CInt( fields( 2 ) )
on error resume next
loop
Set AmiBroker = Nothing
Set fso = Nothing
Set f = Nothing
Set collectiondestock = Nothing
AmiBroker.RefreshAll() |
Et je me viande ici
Code:
collectiondestock = Amibroker.stocks.add (fields(0))
Avec le message : « cet objet ne gère pas cette propriété ou cette méthode »
Voici un lien vers les objets activeX de l’application concernée …
http://www.amibroker.com/guide/objects.html