[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Automation Object Model export.vbs



PureBytes Links

Trading Reference Links

Hi
I'm trying to write Tomasz Export.js script
in VBScript. I get an error message saying
something like no object returned.
I only get an object when I use oStocks.Item(0).
Please take a look at the attached script. Need help
Thanks
Olli

-------------------------------------------------------
  For each ticker in filenames
    WScript.Echo "Export of " & ticker & " start"
    set oStocks = oAB.Stocks
    set oStock = oStocks.Item(ticker)   ' Object value: nothing
<--------------------
    set oStock1 = oStocks(ticker)       ' Object value: nothing
<--------------------
    set oStock2 = oStocks.Item(0)       ' Object value: {...} Object
    Qty = oStock.Quotations.Count       ' <------------------------ error
message is here


------------------------ Yahoo! Groups Sponsor --------------------~--> 
Try Online Currency Trading with GFT. Free 50K Demo. Trade 
24 Hours. Commission-Free. 
http://us.click.yahoo.com/RvFikB/9M2KAA/U1CZAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.html

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 
' debug mit "CSCRIPT //X scriptname.vbs"
' VBScript Run-time Errors
' http://msdn.microsoft.com/scripting/vbscript/doc/vsmscRunTimeErrors.htm 
' VBScript Syntax Errors
' http://msdn.microsoft.com/scripting/vbscript/doc/vsmscSyntaxErrors.htm

Option Explicit

Const path2database = "C:\Programme\Amibroker\Yahoo_DEU"
Const ForReading = 1, ForWriting = 2, ForAppending = 8

Function FileExist(dateiname)
  Dim WshShell, fso
  Set WshShell = WScript.CreateObject("WScript.Shell")
  Set fso = CreateObject("Scripting.FileSystemObject")
  FileExist = fso.FileExists(dateiname)
  Set fso = nothing
  Set WshShell = nothing
End Function

Sub FileDelete(dateiname)
  Dim WshShell, fso, f
  Set WshShell = WScript.CreateObject("WScript.Shell")
  Set fso = CreateObject("Scripting.FileSystemObject")
  If fso.FileExists(dateiname) Then
     Set f = fso.GetFile(dateiname)
     f.delete
     Set f = nothing
  End If
  Set fso = nothing
  Set WshShell = nothing
End Sub

Function ReadFile2Arr(dateiname)
 Dim Fields()
 Dim objFSO, f, i
 Set objFSO = CreateObject("Scripting.FileSystemObject")
 Set f = objFSO.OpenTextFile (dateiname, ForReading)
 i = 0
 Do Until f.atEndOfStream
   Redim Preserve Fields(i)
   Fields(i) = f.ReadLine
   i = i + 1
 Loop
 f.Close
 Set objFSO = nothing
 ReadFile2Arr = Fields
End Function

Function ExportAB(filename)  
  Dim oAB, fso, f, oStocks, oStock, oStock1, oStock2
  Dim filenames, ticker, Qty
  Set oAB = CreateObject("Broker.Application")
  If Not oAB.LoadDatabase(path2database) Then
  	 WScript.Echo "No database found! "
  	 WScript.Quit
  End If 
 
  FileDelete(filename)
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set f = fso.OpenTextFile(filename, ForWriting, true)
  f.WriteLine("VERSION;1;2")
  f.WriteLine("KURSE")
  filenames = ReadFile2Arr("firmen.txt")
  For each ticker in filenames
    WScript.Echo "Export of " & ticker & " start"
    set oStocks = oAB.Stocks
    set oStock = oStocks.Item(ticker)   ' Object value: nothing     <--------------------
    set oStock1 = oStocks(ticker)       ' Object value: nothing     <--------------------
    set oStock2 = oStocks.Item(0)       ' Object value: {...} Object
    WScript.Echo oStocks.Count
    WScript.Echo ticker
    WScript.Echo oStock.Quotations.Count
    WScript.Echo oStock1.Quotations.Count
    WScript.Echo oStock2.Quotations.Count
    ' Qty = oStock.Quotations.Count
    ' WScript.Echo Qty
    ' Qty = 50
    ' for i= Qty - 10 to Qty
    '   set oQuote = oStock.Quotations(i)
    '     WScript.Echo oQuote.Volume & ";" & oQuote.Open & ";" & _ 
    '                  oQuote.High & ";" & oQuote.Low & ";" & oQuote.Close 
    '     f.WriteLine  oQuote.Volume & ";" & oQuote.Open & ";" & _ 
    '                  oQuote.High & ";" & oQuote.Low & ";" & oQuote.Close 
    ' next  
  Next
  f.WriteLine("ENDE")
  f.Close
End Function
 
ExportAB("wiso.txt")