Announcement

Collapse
No announcement yet.

runtime error - please help me!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • runtime error - please help me!

    hi,
    i am using VB6 to program an application with eSignal 7.7 in Windows XP.
    i want it to collect some symbols (about 400 symbols) volumes everyday. I have made a VB application to collect one symbol's volume data and then execute a .vbs file to run this VB application for about 400 times, eveytime to collect 1 symbol's volume data for the day before, and everytime it will sleep 30 seconds.
    But always, there will be a runtime error '91', "object variable or with block variable not set".
    I am almost going to be mad with this error. Can anybody help me? Thank you a lot!

    the code is as the following:

    ==============================================
    Dim WithEvents esignal As IESignal.Hooks
    Dim lHistoryHandle As Long
    Dim lLastHistoryCount As Long
    Dim sSymbol As String
    Dim aSymbolID As Integer
    --------------------------------------------------------------------------
    Private Sub ReleaseHistory()
    If lHistoryHandle <> 0 Then
    esignal.ReleaseHistory lHistoryHandle
    lHistoryHandle = 0
    lLastHistoryCount = 0
    End If
    End Sub
    ----------------------------------------------------------------------------
    Private Sub RequestHistory()

    Dim sInterval As String

    sInterval = "D"

    sSymbol = Trim(sSymbol)
    sInterval = Trim(sInterval)

    ReleaseHistory

    Dim bt As IESignal.barType
    Dim nNumBars As Long

    bt = btDAYS

    nNumBars = 2

    lHistoryHandle = esignal.RequestHistory(sSymbol, sInterval, bt, nNumBars, -1, -1)

    If esignal.IsHistoryReady(lHistoryHandle) = True Then
    FillHistory
    End If


    End Sub
    -------------------------------------------------------------------------------
    Private Sub esignal_OnBarsChanged(ByVal lHandle As Long)
    FillHistory
    End Sub
    ------------------------------------------------------------------------------------
    Private Sub esignal_OnBarsReceived(ByVal lHandle As Long)
    FillHistory
    End Sub
    -------------------------------------------------------------------------------
    Private Function FormatBarData(lIndex As Long, item As BarData)
    Dim sRet As String

    sRet = Str$(item.dtTime)
    sRet = sRet + ": " + Str$(item.dOpen)
    sRet = sRet + ", " + Str$(item.dHigh)
    sRet = sRet + ", " + Str$(item.dLow)
    sRet = sRet + ", " + Str$(item.dClose)
    sRet = sRet + ", " & item.dVolume

    FormatBarData = sRet
    End Function
    -------------------------------------------------------------------------------
    Private Sub FillHistory()
    Dim lNumBars As Long
    Dim baritem As IESignal.BarData
    Dim lBar As Long
    Dim sBar As String

    lNumBars = esignal.GetNumBars(lHistoryHandle)
    If lNumBars = 0 Then
    Exit Sub
    End If

    If lstHistory.ListCount > 0 And lNumBars = lLastHistoryCount Then
    ' update the top bar
    baritem = esignal.GetBar(lHistoryHandle, 0)
    sBar = FormatBarData(0, baritem)

    lstHistory.List(0) = sBar
    ElseIf lstHistory.ListCount > 0 And lNumBars = lLastHistoryCount + 1 Then
    ' add a new bar
    baritem = esignal.GetBar(lHistoryHandle, 0)
    sBar = FormatBarData(0, baritem)
    lstHistory.AddItem sBar, 0
    ElseIf lstHistory.ListCount = 0 Or lNumBars <> lLastHistoryCount + 1 Then
    ' refresh entire list box.
    For lBar = -(lNumBars - 1) To 0
    'baritem = esignal.GetBar(lHistoryHandle, lBar)
    'sBar = FormatBarData(lBar, baritem)
    'lstHistory.AddItem sBar, 0

    baritem = esignal.GetBar(lHistoryHandle, lBar)

    Dim time As String
    time = Str$(baritem.dtTime)

    Dim closeprice As String
    closeprice = Str$(baritem.dClose)

    Dim openprice As String
    openprice = Str$(baritem.dOpen)

    Dim highprice As String
    highprice = Str$(baritem.dHigh)

    Dim lowprice As String
    lowprice = Str$(baritem.dLow)

    Dim aVolume As String
    aVolume = CStr(baritem.dVolume)



    If DateDiff("D", time, Date) = 1 Then

    Set aConn = CreateObject("ADODB.Connection")
    aConn.Open "filedsn=***", "**", "**"

    Set aRS = CreateObject("ADODB.RecordSet")
    aRS.Open "**", aConn, 1, 3, 2
    aRS.AddNew
    aRS("symbol") = aSymbolID
    aRS("date") = Trim(time)
    aRS("volume") = aVolume
    aRS.Update

    If Not aRS Is Nothing Then
    aRS.Close
    End If

    If Not aConn Is Nothing Then
    aConn.Close
    End If

    Set aRS = Nothing
    Set aConn = Nothing

    End If

    Next lBar

    End If

    lLastHistoryCount = lNumBars

    ReleaseHistory
    Set esignal = Nothing
    End

    End Sub


    Private Sub Form_Load()

    Form1.Hide
    Set esignal = New IESignal.Hooks
    lHistoryHandle = 0
    lLastHistoryCount = 0

    esignal.SetApplication ("mstennicke1")

    optHistoryBars.Value = True

    Set FileObject = CreateObject("scripting.FileSystemObject")
    Set out = FileObject.OpenTextFile("C:\VolumeCollector.txt", 1, True)
    sSymbol = out.ReadLine
    aSymbolID = out.ReadLine


    If Not out Is Nothing Then
    out.Close
    End If
    Set out = Nothing

    Set FileObject = Nothing

    lstHistory.Clear

    RequestHistory


    End Sub
    ---------------------------------------------------------------------------------


    Private Sub Form_Unload(Cancel As Integer)
    ReleaseHistory

    Set esignal = Nothing
    End Sub
    ---------------------------------------------------------------------------------
    Private Sub Timer1_Timer()
    ReleaseHistory
    Set esignal = Nothing

    End

    End Sub

  • #2
    On which line of code is the error occuring when you run the debugger?

    Comment


    • #3
      sorry, i dont know which line. i am using a .vbs file to execute the application, only a dialog box saying "runtime error...". so really very hard to debug.

      Comment


      • #4
        Without a decent development environment, you are back in the programming stone age -- you can pick up a student/starter version of Visual Basic for a few bucks -- it will save you many hours and much frustration.
        By the way, a little known secret is that Excel ships with a pretty good VB development environment which I sometimes use for proto-typing. In Excel, just display the Visual Basic tool bar and you are off and running.
        Best of luck.

        Comment


        • #5
          I am even sure how you are attempting to do what you want to do. This part is confusing:

          "I have made a VB application to collect one symbol's volume data and then execute a .vbs file to run this VB application for about 400 times, eveytime to collect 1 symbol's volume data for the day before, and everytime it will sleep 30 seconds."

          Your application should just request volume data for 400 symbols. The logic in the "Multiple History Request" sample is what you should look at.

          Comment


          • #6
            thank you.
            i have modified my code. please see the new post.

            Comment

            Working...
            X