Using VB.NET with API example

Quote from GATrader:

Hi . I have an Excel sheet which fetched data using DDE from a charting program. I also have a vb.net program which takes these values and assigns them to an array in VB. The problem is in my timer. Occasionally, I get this message.

first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll

Additional information: Call was rejected by callee.


I think it is because an assigment statement such as

vxl(rw).index = xlbook.Application.Cells(rw, 2).value
vxl(rw).TrigrBuy = xlbook.Application.Cells(rw, 3).value
vxl(rw).TrigSell = xlbook.Application.Cells(rw, 4).value

which fetches the data from eXcel can't communicate to excel since Excel is in edit mode probably from a cell change thru the DDe. IS there a way to handle this error or a way to do the assignment statments ONLY when Excel is ready? Thanks

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
 
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".
 
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
 
Quote from GATrader:

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

Lookup file system watcher.

http://www.freevbcode.com/ShowCode.asp?ID=4841
 
Quote from GATrader:

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



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
 
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.
 
Back
Top