IB Excel DDE VBA question

Discussion in 'Automated Trading' started by travis, Oct 17, 2006.

  1. travis

    travis

    I am using IB TWS in connection with Excel DDE, with vba code. Once I connect to the TWS and the data starts coming, I get a bunch of Error13 ("Type mismatch"). On a given vba procedure, the more I refer to data from TWS (that I get with the DDE link) the more Error 13 I get. This doesn't stop the system from working, because I use "resume next", but I would like to know, and I have no idea right now.
     
  2. swandro

    swandro

    Type mismatch usually occurs when you are trying to load a value in one format into a field with a different, non-compatible format. For example, if you have a field which is specified as an integer, you would get a type mismatch if you tried to load a text value into it. I suggest you check all your variable definitions - make sure that they are suitable for what you are trying to load into them. It is best to be generous - for instance, most price related fields can be specified as double.

    The other possiblility is that you are receiving some incorrect data. But check your field definitions first.
     
  3. Kap

    Kap

    I'm guessing u have recorded some sort of macro right ?... show the code and all will become apparent
     
  4. travis

    travis

    Thanks to both of you.

    Yes, I am using vba, and no, I have not recorded a macro, but I have written myself all that code.

    To the previous post, yes, I did try using "dim x as double" instead of "dim x as integer", and it didn't get rid of any of the 36 "error 13" I get. The other hypothesis, no, I am not getting any corrupt data for sure.
     
  5. swandro

    swandro

    My money is still on a "bad" value - here is a routine that will create Error 13. If you build the error handling in that I have used, you can display the data that is causing the error to occur. This may help you to move forward.

    Sub Test()

    Dim x As Double

    On Error GoTo errlab

    x = "x"
    End

    errlab:
    If Err.Number = 13 Then
    MsgBox "error value = " & x
    End If
    Resume Next

    End Sub

    Hope this helps
     
  6. fader

    fader

    travis, post the code snippet which triggers the error, perhaps it will make it easier to figure out what is wrong.
    all the best.
     
  7. travis

    travis

    Regretfully, I don't know exactly where in the sub procedure these 36 "type mismatch" errors are coming from. And this is the most important procedure in my system, so I am not too happy about posting it here, or sending it out. However, thanks to everyone for their willingness to help me.
     
  8. could be it is too valuable a procedure for use with tws. IB probably realizes its the holy grail and is blocking it.
     
  9. Kap

    Kap

    - u have a date as a value or a text as a value, error 13 is as it says a variable mismatch, trying to act on a 'value' from a cell when its a dde text/date perhaps..use the immediate window to watch the variable values in the VBE as u f8 debug it... using Resume next / on error goto 0 .. just tells me its botch job.
     
  10. m4a1

    m4a1

    maybe the data is coming to you as string type and you need to put it in a string variable first, then convert the string variable into a double
     
    #10     Oct 18, 2006