1 / 20

計算機程式實習期末作業

指導老師 : 謝慶存 學生 : 自控四乙 陳俊宇. 計算機程式實習期末作業. 先聲明,這次的作業並不是只有我自己完成的,而是在網路上搜尋了很多的相關資料,還有高手指導才有的成果。 所以這次的作業對我而言並不是完成一件作品,而是過程中遇到問題所學會的解決方法,雖然還不是非常了解這個程式碼的意義,但對我而言已經在程式語言跨出一大步了. 前言. 作品 : 倒數計時器. 是多組倒數計時器組合而成的一個程式,顧名思義可以用在 同一時段進行但起始時間不統一 的需計時事物上。 EXP: 雞排店的雞排入鍋時間倒數,實驗室的實驗計時,. 作品意義.

yepa
Download Presentation

計算機程式實習期末作業

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 指導老師:謝慶存 學生:自控四乙 陳俊宇 計算機程式實習期末作業

  2. 先聲明,這次的作業並不是只有我自己完成的,而是在網路上搜尋了很多的相關資料,還有高手指導才有的成果。 所以這次的作業對我而言並不是完成一件作品,而是過程中遇到問題所學會的解決方法,雖然還不是非常了解這個程式碼的意義,但對我而言已經在程式語言跨出一大步了 前言

  3. 作品:倒數計時器

  4. 是多組倒數計時器組合而成的一個程式,顧名思義可以用在同一時段進行但起始時間不統一的需計時事物上。是多組倒數計時器組合而成的一個程式,顧名思義可以用在同一時段進行但起始時間不統一的需計時事物上。 EXP:雞排店的雞排入鍋時間倒數,實驗室的實驗計時, 作品意義

  5. 程式碼特色是並不用設定介面,完全是用程式碼設計的一個程式程式碼特色是並不用設定介面,完全是用程式碼設計的一個程式 可以自行設定想要的音效 計時途中可以隨時暫停,計時終了案結束便可以重新計時 可插入想要音效 時間到,視窗會出現閃爍提醒 註記頁可以寫重要內容 程式介面/運作介紹

  6. Public Class frmTMR Private Declare Function FlashWindow Lib "user32" (ByVal hWnd As Int32, ByVal bInvert As Int32) As Int32 Private Declare Function GetTickCount Lib "kernel32" () As Int32 Private Structure 計時器屬性 ' 倒數時間已記錄在 lblTmr 元件中, 不用另存 Dim Pause As Boolean ' 按鈕狀態 Dim Useing As Boolean ' 倒數狀態 Dim TimeStart As Int32 ' 開始時間 Dim sec As Int32 ' 總秒數 Dim Flash As Boolean ' 完成狀態 End Structure Private Structure 閃爍屬性 Dim Count As Integer ' 閃爍計時 Dim Useing As Boolean End Structure 程式碼(簡單介紹)

  7. Dim 數量 As Integer ' 可使用之計時器數量, 以迴圈最大值為準, 以零起算 Dim TmrCtrl(4) As 計時器屬性 Dim TmrFlash As 閃爍屬性 Dim gBox(4) As GroupBox Dim lblSec(4), lblShow(4) As Label Dim cmbTmr(14) As ComboBox Dim butReSet(4), butBut(4) As Button Dim tmr As New Timer Dim tabMain As New TabControl Dim tpTimer, tpText, tpCalculate As New TabPage Dim chkBeep As New CheckBox Dim txtDoc As New TextBox Private Sub frmTMR_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim i, j As Int32 Me.Size = New Size(580, 490) Me.Text = "專業倒數秒“ 數量 = 4 For i = 0 To 4 With TmrCtrl(i)

  8. .Useing = False .Pause = False .sec = 0 End With Next With tabMain ' 設定 TabControl .Parent = Me .Size = New Size(540, 426) .Location = New Point(12, 12) .Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right .Font = New System.Drawing.Font("新細明體", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte)) .Alignment = TabAlignment.Top .Appearance = TabAppearance.Normal .Padding = New Point(6, 4) .SizeMode = TabSizeMode.FillToRight .Visible = True .Enabled = True End With

  9. With tpTimer ' 設定 TabPages .Parent = tabMain .Text = "計時" .UseVisualStyleBackColor = True End With With tpText ' 設定 TabPages .Parent = tabMain .Text = "註記" .UseVisualStyleBackColor = True End With With txtDoc ' 設定 TextBox .Parent = tpText .Font = New System.Drawing.Font("新細明體", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte)) .Location = New Point(4, 4) .Size = New Size(524, 382) .Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right .ScrollBars = ScrollBars.Both .Multiline = True .WordWrap = True AddHandler .KeyPress, AddressOf txtDoc_KeyPress End With ' 2011/05/29 For i = 0 To 4 gBox(i) = New GroupBox With gBox(i)

  10. .Parent = tpTimer .Size = New Size(446, 70) .Location = New Point(6, 6 + 75 * i) .Text = "第" & Mid("一二三四五", i + 1, 1) & "組" .Visible = True .Enabled = True End With Next For i = 0 To 4 lblSec(i) = New Label With lblSec(i) .Parent = gBox(i) .AutoSize = False .Font = New System.Drawing.Font("新細明體", 18.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte)) .Size = New Size(90, 28) .Location = New Point(6, 26) .BorderStyle = BorderStyle.Fixed3D .BackColor = Color.FromArgb(192, 192, 192) .TextAlign = ContentAlignment.MiddleRight .Enabled = True .Visible = True .Text = "0:00:00" End With lblShow(i) = New Label With lblShow(i) .Parent = gBox(i) .AutoSize = False

  11. .Font = New System.Drawing.Font("新細明體", 18.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte)) .Size = New Size(90, 28) .Location = New Point(98, 26) .BorderStyle = BorderStyle.Fixed3D .BackColor = Color.FromArgb(192, 192, 192) .TextAlign = ContentAlignment.MiddleRight .Enabled = True .Visible = True .Text = "0" End With butBut(i) = New Button With butBut(i) .Name = i.ToString .Parent = gBox(i) '.Font = but_Download.Font .Size = New Size(48, 34) .Location = New Point(342, 23) .BackColor = Color.FromArgb(224, 224, 224) .Enabled = True .Visible = True .Text = "啟動" AddHandler .Click, AddressOf butbut_Click End With

  12. butReSet(i) = New Button With butReSet(i) .Name = i.ToString .Parent = gBox(i) .Size = New Size(48, 34) .Location = New Point(392, 23) .BackColor = Color.FromArgb(224, 224, 224) .Enabled = True .Visible = True .Text = "停用" AddHandler .Click, AddressOf butReSet_Click End With Next For i = 0 To 14 cmbTmr(i) = New ComboBox With cmbTmr(i) .Parent = gBox(i \ 3) .Font = New System.Drawing.Font("新細明體", 18.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte)) .Size = New Size(46, 34) .Location = New Point((i Mod 3) * 48 + 192, 24) .IntegralHeight = False .MaxDropDownItems = 15 .Enabled = True .Visible = True

  13. If i Mod 3 = 2 Then For j = 0 To 55 Step 5 .Items.Add(Format(j, "00")) Next Else For j = 0 To 59 .Items.Add(Format(j, "00")) Next End If .SelectedIndex = 0 End With Next cmbTmr(2).SelectedIndex = 6 cmbTmr(4).SelectedIndex = 3 cmbTmr(7).SelectedIndex = 10 cmbTmr(10).SelectedIndex = 30 cmbTmr(12).SelectedIndex = 1 With chkBeep ' 設定 CheckBox .Parent = tpTimer .Appearance = System.Windows.Forms.Appearance.Button .Checked = True .CheckState = System.Windows.Forms.CheckState.Checked .Location = New Point(460, 16) .Size = New Size(70, 36) .Text = "音效" .TextAlign = System.Drawing.ContentAlignment.MiddleCenter .UseVisualStyleBackColor = True End With

  14. With tmr ' 設定 Timer .Interval = 1000 .Enabled = True AddHandler .Tick, AddressOf tmr_Tick End With End Sub Private Sub butbut_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim Index As Int32 = CInt(CType(sender, Button).Name) With TmrCtrl(Index) If .Useing Then ' 使用中, 做暫停處理 If .Pause Then butBut(Index).Text = "暫停" .TimeStart = GetTickCount Else butBut(Index).Text = "繼續" .sec -= (GetTickCount - .TimeStart) End If .Pause = Not .Pause Else ' 未使用中, 做啟動處理 .sec = CInt(cmbTmr(Index * 3).SelectedIndex) * 3600 + CInt(cmbTmr(Index * 3 + 1).SelectedIndex) * 60 + CInt(cmbTmr(Index * 3 + 2).SelectedIndex * 5) .sec = .sec * 1000

  15. .TimeStart = GetTickCount butBut(Index).Text = "暫停" .Useing = True 'Me.Icon = ImgLis.Draw(Me.Icon.Handle, 0, 0, 1) 'Me.Icon = New Imgl End If End With End Sub Private Sub butReSet_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim i As Int32 Dim Index As Int32 = CInt(CType(sender, Button).Name) TmrCtrl(Index).Useing = False TmrCtrl(Index).Flash = False TmrCtrl(Index).Pause = False lblSec(Index).Text = "0:00:00" butReSet(Index).BackColor = Color.Transparent butBut(Index).Text = "啟動" For i = 0 To 4 If TmrCtrl(i).Flash Then Exit For Next End Sub Private Sub tmr_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim i, Secs As Int32

  16. TmrFlash.Useing = False For i = 0 To 4 With TmrCtrl(i) If .Useing And (Not .Pause) Then ' 2011/06/03 Secs = GetTickCount - .TimeStart If Secs > .sec Then butReSet(i).BackColor = Color.Yellow TmrFlash.Useing = True .Flash = True .Useing = False End If lblShow(i).Text = CStr((.sec - Secs) \ 1000) lblSec(i).Text = FormatTime(.sec - Secs) End If End With Next For i = 0 To 4 If TmrCtrl(i).Flash Then FlashWindow(Me.Handle, 0) ' 強制顯示 My.Application.DoEvents() FlashWindow(Me.Handle, 1) If chkBeep.Checked Then Beep() Exit For End If

  17. Next End Sub Private Function FormatTime(ByRef ft_Time As Int32) As String Dim i As Int32 i = ft_Time \ 1000 ' 處理秒以上的單位 'j = ft_Time \ 100 ' 處理毫秒單位 ' 如果不需要精準到 0.1 秒, 則改用下面註解的程式碼; 如需計算到 0.01 秒, 請自行調整並修改 Timer.Interval 值 'FormatTime = Format(i \ 3600, "00:") & Format((i Mod 3600) \ 60, "00:") & Format(i Mod 60, "00.") & Format(j Mod 10, "0") FormatTime = Format(i \ 3600, "0:") & Format((i Mod 3600) \ 60, "00:") & Format(i Mod 60, "00") End Function Private Sub txtDoc_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) If (Asc(e.KeyChar)) = 1 Then e.Handled = True txtDoc.SelectAll() End If End Sub Private Sub frmTMR_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize If Me.WindowState = FormWindowState.Normal Then If sender.Size.Height < 580 Or sender.Size.Width < 490 Then Me.Size = New Size(580, 490) End If End If End Sub End Class

  18. 了解到設計界面可以用最原始的方法,就是程式碼一開始的那幾段,先把需要的物件定義出來,然後再給予座標點就行了。了解到設計界面可以用最原始的方法,就是程式碼一開始的那幾段,先把需要的物件定義出來,然後再給予座標點就行了。 其實沒有所有程式都是由小單位組合而成的聚集,所以觀念清楚,不要亂掉,把所有小程式碼統合起來就成為這個作品了 學習成果

  19. 以前老師教的很多指令我都不明白如何使用,現在經過這個有夠麻煩的程式,許多的指令都得到驗證了,而且也驚訝到visual basic也可以單純寫出程式碼而不用設定介面,算是學習到很多東西。 雖然這個作業遲交了一個禮拜,但是也是我嘔心瀝血做出來的成果,希望老師能接受 心得感想

  20. 感謝VB6/VB2005/Dev-C++ 程式技術倉庫的技術指導 以及莊元佳的輔助設計 引用資料

More Related