暱稱: 頭像是我感興趣的女生 頭銜: 程式設計幼幼生
小學生
- 帖子
- 8
- 主題
- 2
- 精華
- 0
- 積分
- 15
- 點名
- 0
- 作業系統
- window 7
- 軟體版本
- office 2007
- 閱讀權限
- 10
- 性別
- 男
- 來自
- new taipei city
- 註冊時間
- 2010-12-25
- 最後登錄
- 2012-4-16

|
4#
發表於 2011-6-19 17:43
| 只看該作者
喔~用亂數是模擬報價伺服器(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 |
|