Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = False
Label1.Text = ""
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer1.Enabled = False
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Interval = 1
Label1.Text = Now
End Sub
End Class作者: mark15jill 時間: 2011-6-19 16:13
喔~用亂數是模擬報價伺服器(DDE Server),因為我的數據是每秒5~10個一直接收,所以我要每一分鐘(或每5分鐘)計算這一分鐘內的最大值及最小值。下列是我寫的未完成程式碼,參考看看。
Public Class Form1
Dim arr(200000) As String
Dim advisecount As Integer
Dim startindex As Integer
Dim stopindex As Integer
Dim mark_min As String
Dim max As Integer = 0
Dim min As Integer = 100
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label3.Text = Format(Now, "hh:mm:ss") '顯示現在時間
Label4.Text = Now.Second + Now.Millisecond / 1000 '顯示現在秒數+毫秒
advisecount += 1 '每tick一次就加1
Randomize() '亂數種子初始化
Dim rand As New Random '宣告亂數物件rand
Dim x As Integer '承接rand物件產生的亂數
x = rand.Next(1, 100)
If x > max Then
max = x
Label5.Text = max
ElseIf x < min Then
min = x
Label6.Text = min
End If
arr(advisecount) = x '放入arr陣列比較大小用
'記錄"序號","時間","亂數"
TextBox1.Text &= Format(Now, "hh:mm:ss") & " @ " & Format(advisecount, "000000") & " => " & arr(advisecount) & vbNewLine
TextBox1.SelectionStart = TextBox1.TextLength '設定插入點
TextBox1.ScrollToCaret() '將捲軸捲至最底
If TextBox1.TextLength > 10000 Then '適時清空以免程式負載過大
TextBox1.Text = ""
End If
If Now.Second Mod 60 = 0 Then '當秒數為"00"時即下一個分鐘的開始
mark_min = Now.Minute
startindex = advisecount
Label1.Text = startindex
Label7.Text = mark_min
End If
If Now.Minute > mark_min And Now.Second Mod 60 = 0 Then
stopindex = advisecount
Label2.Text = stopindex
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer1.Enabled = False
End Sub
End Class