ການໃຊ້ Timer ໃນ Visual Basic 6 ເພື່ອສະແດງເຖິງການກຳນົດເວລາໃນໂປຣແກຣມ
ມີຕົວຢ່າງດັ່ງນີ້
ເພີ່ມ Timer Control ໃນຟອມ
ໂຄ້ດ:
Option Explicit ' Add a Timer control to your project. It will be Timer1 ' It looks like a stop watch in the IDE. Dim OldTime As Date Dim newTime As Date Dim diff As Date Private Sub Form_Load() OldTime = Time Timer1.Interval = 1000 Timer1.Enabled = True End Sub Private Sub Timer1_Timer() Static x As Long Static zz$, ss$ x = x + 1 newTime = Time diff = DateDiff("s", OldTime, newTime) Form1.Caption = (diff 3600) & ":" & Format((diff 60 Mod 60), "00") & ":" & _ Format((diff - ((diff 60) * 60)), "00") ' Debug.Print (diff 3600) & ":" & Format((diff 60 Mod 60), "00") & ":" & _ Format((diff - ((diff 60) * 60)), "00") If newTime = DateAdd("s", 360, OldTime) Then ' Add 360 seconds Timer1.Enabled = False ' You time is UP! Do something! Beep End If End Sub
Private Sub Form_Load() Timer1.Interval = 60000 Timer1.Enabled = True End Sub Private Sub Timer1_Timer() Static Minutes As Integer If Minutes = 44 Then '45 minutes since its counting from 0 i set 44 Minutes = 0 'ຈະຜ່ານນີ້ທຸກໆ 45 ນາທີ ໃສ່ໂຄ້ດທີ່ຕ້ອງການບ່ອນນີ້ '-------------------------------- End If End Sub
ໂປຣແກຣມນີ້ຈະແລ່ນທຸກໆ 45 ນາທີ ຕາມທີ່ທ່ານກຳນົດໂຄດໃນບ່ອນນັ້ນ