基本上什麼,我試圖做的應用程序運行時,我開始一個更新的股票報價,並開始每隔10秒的定時器(這是10000毫秒)它會將10添加到一個整數變量的時間間隔爲60秒,我希望標籤在達到分鐘後每隔10秒顯示一個「下一次更新」標籤我希望更新股票行情並重置計時器它會重新開始,只要程序打開,它就會一直運行。使用定時器做一兩件事,每10秒,但做別的事情在分鐘的間隔
這是到目前爲止我的代碼,它跳過if語句,因爲它不是在10秒,當它到達該語句並退出。我應該使用一個while while循環嗎?
Imports System.Net
Imports System.IO
Imports Newtonsoft.Json
公共類Form1中
Private Symbols As List(Of String) = Nothing
Private Prices() As List(Of String) = Nothing
Private secondCount As Integer
Private intervalCount As Integer = 60
' force Update
Private Sub forceUpdateBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles forceUpdateBtn.Click
QuoteUpdater()
End Sub
Public Function GetStockPrices(symbol As String) As List(Of String)
' Dim pricesArray() As String
Dim prices As New List(Of String)()
Dim items() As GoogleFinanceItem
If UCase(symbol) = "INDU" Then
Dim url As String = "http://finance.google.com/finance/info?client=ig&q=INDEXDJX%3A.DJI"
Dim result As String = GetWebResponse(url).Replace("//", "")
' Dim newResult = result.Remove(0, 3)
items = JsonConvert.DeserializeObject(Of GoogleFinanceItem())(result)
' pricesArray = Split(result, ":")
Else
Dim url As String = "http://finance.google.com/finance/info?client=ig&q=" & UCase(symbol)
Dim result As String = GetWebResponse(url).Replace("//", "")
' Dim newResult = result.Remove(0, 3)
items = JsonConvert.DeserializeObject(Of GoogleFinanceItem())(result)
' pricesArray = Split(result, ":")
End If
' pricesArray = Split(pricesArray(4), """")
' prices.Add(CSng(Format(pricesArray(1), "0.00")))
'prices.Add(CSng(Format(pricesArray(1))))
prices.Add(items(0).price)
Return prices
End Function
' Get a web response.
Private Function GetWebResponse(ByVal url As String) As String
' Make a WebClient.
Dim web_client As New WebClient()
' Get the indicated URL.
Dim response As Stream = web_client.OpenRead(url)
' Read the result.
Using stream_reader As New StreamReader(response)
' Get the results.
Dim result As String = stream_reader.ReadToEnd()
' Close the stream reader and its underlying stream.
stream_reader.Close()
' Return the result.
Return result
End Using
End Function
Private Sub FillData()
Dim symbolSubSet() As Control = {Label1, Label2, Label3}
Dim priceSubSet() As Control = {Label4, Label5, Label6}
For i = 0 To 2
symbolSubSet(i).Text = Symbols(i)
priceSubSet(i).Text = Prices(i)(0) 'collection inside a collection. so in the first spot the array is in
Next
statusLbl.Text = "Last Updated: " + Now.ToString
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load, updateTimer.Tick
QuoteUpdater()
updateTimer.Start()
If updateTimer.Interval = 10000 Then
secondCount = secondCount + 10
nextUpdateLbl.Text = "in " + CStr(intervalCount - secondCount) + " secs"
End If
End Sub
Private Sub exitBtn_Click(sender As Object, e As EventArgs) Handles exitBtn.Click
Application.Exit()
End Sub
Private Sub QuoteUpdater()
Me.Cursor = Cursors.WaitCursor
' Get the ticker symbols.
'Dim symbols_text() As String = txtSymbols.Text.Split(","c)
Dim symbols_text() As String = {"PKG", "TEN", "INDU"}
Symbols = New List(Of String)()
For i As Integer = 0 To symbols_text.Length - 1
Symbols.Add(symbols_text(i).Trim())
Next i
' Get the data.
ReDim Prices(0 To Symbols.Count - 1)
For i As Integer = 0 To Symbols.Count - 1
Prices(i) = GetStockPrices(Symbols(i))
Next i
' Graph it.
'DrawGraph()
FillData()
Me.Cursor = Cursors.Default
End Sub
End Class
如果我想使這個間隔15分鐘,並已將其更新的每一個標籤分鐘,我改變了間隔90萬和專櫃15.然後我更改updateTimer方法6的,讓他們和15後(15〜櫃檯)* 10)我脫掉了* 10。我沒有看到它做任何事情。計時器滴答法如何被調用來試圖理解正在發生的事情。 – Edgar