0

我是 Visual Basic 的新手(我正在学习它来为客户构建项目的一部分)。下面是使用 Sterling ActiveX API 库的示例代码。基本上,该程序与名为 Sterling Trader 的股票交易软件一起运行,当按下按钮时,文本框会更新为指定股票的当前股票报价(在本例中为 IBM):

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

Sterling Activex API 指南链接:http: //www.sterlingtrader.com/documents/Sterling_ActiveX_API_Guide.pdf

我想做这个代码的两件事:

  1. 我想做的是使文本框不断更新自己的新当前股票报价,而无需按下按钮。我猜你可以用计时器来做到这一点,但我不完全确定要修改代码的哪一部分,也不熟悉在 Visual Basic 中执行此操作的方法。

  2. 我想创建另一个文本框/按钮,让您通过输入并单击按钮来更改您要提取报价的股票。目前,代码使用的是 IBM 股票;这是由这行代码的“IBM”部分决定的: stiQuote.RegisterQuote("IBM", "*")

我该怎么做这两件事?

4

1 回答 1

0

这是一个计时器和程序化按钮单击的简单示例。

Imports System.Windows.Forms ' one of several namespaces that include timers

Public Class MyForm

    Private MyTimer As Timer

    Private Sub MyForm_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        MyTimer = New Timer
        MyTimer.Interval = 1000 ' 1 second
        MyTimer.Enabled = True
        AddHandler MyTimer.Tick, AddressOf HandleTimer
    End Sub

    Private Sub HandleTimer()
        Button1.PerformClick()
    End Sub

    Private Sub Button1_Click(sender As Object, e As System.EventArgs) Handles     Button1.Click
        TextBox1.Text = DateTime.Now.ToString("MM:ss")  
    End Sub

    Private Sub MyForm_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        MyTimer.Dispose()
        MyTimer = Nothing
    End Sub

End Class
于 2012-10-21T18:43:42.093 回答