Board logo

標題: [原創] 無聊作的小時鐘... [打印本頁]

作者: mark15jill    時間: 2011-6-10 09:17     標題: 無聊作的小時鐘...

如題
因不知道怎將label轉換成圓形的
所以   只好加減用吧..

以下是程式碼
  1. Private Sub Command1_Click(Index As Integer)
  2.     Timer1.Interval = 1000
  3. End Sub

  4. Private Sub Command2_Click()
  5.    Timer1.Interval = 0
  6. End Sub

  7. Private Sub Form_Load()
  8.     Timer1.Interval = 0
  9.     Label1.Caption = ""
  10. End Sub

  11. Private Sub Timer1_Timer()
  12. For i = 1 To 1  '此地方用迴圈是讓他自動隨著電腦時間讀取 如果沒有此行 會造成按一下 跳一次
  13.     Label1.Caption = Date & Time
  14. Next i
  15. End Sub
複製代碼
[attach]6564[/attach]
作者: kevenpeter    時間: 2011-6-19 09:28

用VB.NET,仿版主的程式。另外請教一下,如果我每秒隨機產生一個1~100之間的亂數,但我想知道例如9:00:00~9:01:00這段期間內所產生的亂數最大值與最小值,該怎麼寫?

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

用VB.NET,仿版主的程式。另外請教一下,如果我每秒隨機產生一個1~100之間的亂數,但我想知道例如9:00:00~9 ...
kevenpeter 發表於 2011-6-19 09:28



    好奇 時鐘為什麼要用亂數....
作者: kevenpeter    時間: 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




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)