Attribute VB_Name = "QuoteEngine"
' dwQuote QuoteEngine
' Copyright (c) 1997-1998 by Desaware Inc.  All Rights Reserved

Option Explicit

' This is a collection of quotes that need to be filled
' Each one if filled in turn
' All objects work with this list
Private QuotesPending As New Collection

' Set to True when a quote is in progress
Private QuotationInProgress As Boolean

' Enumerat that indicates which service to use
Public Enum QuoteSourceType
   sqschwab = 0   ' Charles Schwab & Co.
   sqyahoo = 1    ' Yahoo
End Enum

Public QuoteSource As QuoteSourceType  ' Service in use

' Called by StockQuote object to start a quotation
' if one is not yet in progress
Public Sub StartQuote(Optional obj As StockQuote)
   Dim sq As StockQuote

   ' Add it to the list
   If Not obj Is Nothing Then
      QuotesPending.Add obj
   End If
   If (Not QuotationInProgress) And QuotesPending.Count > 0 Then
      QuotationInProgress = True
      Set sq = QuotesPending.item(1)
      frmHolder.StartQuote sq.symbol ' Start a quotation now
   End If
End Sub

' Called when quotation is done
' htmlstring is String containing the downloaded html
' html is "" if EndQuote is due to an error
Public Sub EndQuote(htmlstring As String)
   Dim htmlcol As New dwHTMLcollection
   Dim sq As StockQuote
   
   ' Quotation is done
   QuotationInProgress = False
   
   ' Remove the first item in the collection
   ' (it's the one that's been in progress
   Set sq = QuotesPending(1)
   QuotesPending.Remove 1
   
   ' Don't keep objects hanging around unneeded
   If QuotesPending.Count = 0 Then
      Set QuotesPending = Nothing
      Unload frmHolder
   End If
   
   If Len(htmlstring) = 0 Then
      sq.ReportQuote Nothing, sqError
   Else
      htmlcol.LoadFromString htmlstring
      sq.ReportQuote htmlcol, sqIdle
   End If
   ' Start the next quotation
   StartQuote
End Sub

' Initialization routine
Sub Main()
   
   ' For now, hardcode the quote source
   ' QuoteSource = sqyahoo
    QuoteSource = sqschwab
   
   ' On standalone operation, bring up quotation form
   If App.StartMode = vbSModeStandalone Then
      frmQuote.Show
   Else
      ' Don't show the task in the task bar
      App.TaskVisible = False
   End If
End Sub
