title: Visual Basic: Changing a Button Click into a Constantly Updating Event
body: <p>I'm new to Visual Basic (I'm learning it to build part of a project for a client). Below is sample code that is using the Sterling ActiveX API library. Basically, this program runs alongside a stock-trading software called Sterling Trader and, when the button is pressed, the text box updates with the current stock quote of the specified stock (in this case it's IBM):</p>
  
  <pre><code>Option Strict Off
  Option Explicit On
  
  Public Class Form1
  Inherits System.Windows.Forms.Form
  
  Dim stiEvents As New SterlingLib.STIEvents
  Dim stiQuote As New SterlingLib.STIQuote
  
  Delegate Sub TextBoxUpdater(ByVal byre As TextBox, ByRef str As Object)
  
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      AddHandler stiQuote.OnSTIQuoteSnap, AddressOf OnSTIQuoteSnap
      AddHandler stiQuote.OnSTIQuoteUpdate, AddressOf OnSTIQuoteUpdate
  End Sub
  
  Private Sub OnSTIQuoteSnap(ByRef structQuoteSnap As SterlingLib.structSTIQuoteSnap)
  
      UpdateTextBoxLast(TextBox1, structQuoteSnap.fLastPrice)
  
  End Sub
  
  Private Sub OnSTIQuoteUpdate(ByRef structQuoteUpdate As SterlingLib.structSTIQuoteUpdate)
  
      If structQuoteUpdate.bLastPrice Then
          UpdateTextBoxLast(TextBox1, structQuoteUpdate.fLastPrice)
      End If
  
  End Sub
  
  Private Sub UpdateTextBoxLast(ByVal lb As TextBox, ByRef str As Object)
      If (lb.InvokeRequired) Then
          Me.BeginInvoke(New TextBoxUpdater(AddressOf UpdateTextBoxLast), lb, str)
      Else
          TextBox1.Text = str
  
      End If
  
  End Sub
  
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      stiQuote.RegisterQuote("IBM", "*")
  End Sub
  
  End Class
  </code></pre>
  
  <p>Link to the Sterling Activex API guide: <a href="http://www.sterlingtrader.com/documents/Sterling_ActiveX_API_Guide.pdf" rel="nofollow">http://www.sterlingtrader.com/documents/Sterling_ActiveX_API_Guide.pdf</a></p>
  
  <p>Two things I'd like to do this code:</p>
  
  <ol>
  <li><p>I want to do is make the text box constantly update itself with the new current stock quote without the button being pressed. I'm guessing you could do this with a timer, but I'm not entirely certain what section of the code to modify, nor am I familiar with the way to do this in Visual Basic.</p></li>
  <li><p>I'd like to create another text box/button that let's you change the stock whose quote you are pulling by typing it in and clicking the button. Right now, the code is using the IBM stock; this is determined by the "IBM" part of this line of code: stiQuote.RegisterQuote("IBM", "*")</p></li>
  </ol>
  
  <p>How can I do these two things?</p>