Using VB.NET with API example

Discussion in 'Automated Trading' started by psytek, Aug 24, 2005.

  1. You can control (term is Automation) Excel from VB or VB.net code... so in your VB(.net) code set Excel in the mode you want it in... grab what you need and then reset Excel whatever mode...

    Question: What are you doing from VB.net that you cannot not do from Excel... just curious...

    cj...

    :)

    __________________
    HAVE STOP - WILL TRADE

    If You Have The Vision We Have The Code
     
    #31     Oct 30, 2005
  2. Hi. I am trying to implement an error handling routine to enable me to exit gracefully in case the file I am trying to open is not currently available. I looked at the help files and came across the Try/Catch method. I tried it and am still having errors in the dev environment instead of getting it thru the error handler. Can anyone suggest a solution?. Thanks in advance. Here is the code that is not working.

    Try
    oRead = oFile.OpenText("c:\Main3.txt")
    line = oRead.ReadLine
    oRead.Close()

    Catch e As Exception

    MsgBox(e.Message)
    End Try


    Here is the mesage I am getting which is not coming from the error handler.


    A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll

    Additional information: Could not find file "c:\Main3.txt".
     
    #32     Nov 2, 2005
  3. Hi.
    I need help on an issue and would appreciate any suggestions. I used to have an Excel object in the if/then else statement below.

    xlbook = GetObject("c:\XLworkbooks\GenesisATS.xls")

    While xlbook.application.cells(rw,1)<> "" 'Check for Opening Order Criteria

    If xlbook.application.cells(rw,4) > 1 And xlbook.application.cells(rw,6) < 0.8 ) Then
    OpenShorts(rw)

    elseIf xlbook.applcation.cells(rw,4) > 1 And xlbook.application.cells(rw,6) < 0.8 ) then
    OpenLongs(rw)
    endif

    The problem was that my CPU was running 60-70% since it uses the Excel object. I changed my program to just save the Excel sheet into a text file and then I use

    oRead = oFile.OpenText("c:\InvestRT\Admin\Main2.txt")

    to load text file into an array which makes the above if statement run faster (only 14% CPU)

    The problem is that sometimes the opentext is being done at the same time the text file is being saved so it aborts. The error was something like file is being used by another process. Is there a way to prevent this? I tried error handling using Try/Catch but it still gives me an error message. Is there a way to optimize Excel instead so that it runs faster? maybe use MS Jet to access excel instead? Thanks
     
    #33     Nov 2, 2005
  4. Lookup file system watcher.

    http://www.freevbcode.com/ShowCode.asp?ID=4841
     
    #34     Nov 6, 2005


  5. rep:

    Hi...the text below...
    Might want to change the If Statments into twoby adding another if..see(XXX)

    ie............................................................XXXX..........
    If xlbook.application.cells(rw,4) > 1 And if xlbook.application.cells(rw,6) < 0.8 ) Then


    ..........................................

    GL
    Kal


    If xlbook.application.cells(rw,4) > 1 And xlbook.application.cells(rw,6) < 0.8 ) Then
    OpenShorts(rw)

    elseIf xlbook.applcation.cells(rw,4) > 1 And xlbook.application.cells(rw,6) < 0.8 ) then
    OpenLongs(rw)
    endif
     
    #35     Nov 8, 2005
  6. Pondracer

    Pondracer Guest

    If you are trying to compile the TWSAPI_VBSample.NET example it will fail around line 1213 in the VB_Sample_API.vb file. There's a bogus error trap that you can rem out to get this to work.

    'If eventArgs.errorCode = MKT_DEPTH_DATA_RESET Then
    ' m_dlgMktDepth.clear()
    'End If

    It looks like they used the MS .NET conversion tool to upgrade this app to .NET and that may have caused this to hose. After making the correction I have the application compiled and running on my PC.
     
    #37     Nov 11, 2005