1樓:
窗體中放置三個command、三個label、一個timer控制元件,在form_load過程中已經說明了控制元件用途,其中label1是顯示分鐘數,label2是顯示秒數,**如下:
dim js as integer '這裡宣告瞭一個全域性變數,儲存計時數
private sub command1_click()
timer1.enabled = false '停止計時
end sub
private sub command2_click()
timer1.enabled = true '繼續計時
end sub
private sub command3_click()
unload me '重新計時
form1.show
end sub
private sub form_load()
command1.caption = "暫停" '"暫停"按鈕
command2.caption = "繼續" '"繼續"按鈕
command3.caption = "重新計時" '"重新計時"按鈕
label3.caption = ":" '顯示":" 分隔符
timer1.enabled = true '使計時開始
timer1.interval = 1000 '計時間隔為1分鐘(1000毫秒)
js = 180 '計時數初始化,180秒即3分鐘
end sub
private sub timer1_timer()
dim f as integer, m as integer
if js > 0 then
js = js - 1
if js <= 30 then '在小於30秒後,標籤底色為紅色
label1.backcolor = &hff
label2.backcolor = &hff
label3.backcolor = &hff
end if
f = int(js / 60) '計算分鐘數
m = js - f * 60 '計算秒數
label1.caption = f '在label1標籤顯示分鐘數
label2.caption = m '在label2標籤顯示秒數
else
timer1.enabled = false '如果計時數小於或等於0,不再計時
end if
end sub
2樓:網海1書生
窗體中放入一個timer1,一個label1,三個按鈕command1、command2、command3
dim tt as integer
private sub command1_click() '開始按鈕
tt = 180
command1.enabled = false
command3.enabled = false
label1.forecolor = vbblue
label1.caption = ""
timer1.interval = 1000
timer1.enabled = true
end sub
private sub command2_click() '暫停按鈕
command2.enabled = false
command3.enabled = true
timer1.enabled = false
end sub
private sub command3_click() '繼續按鈕
command2.enabled = true
command3.enabled = false
timer1.enabled = true
end sub
private sub timer1_timer()
if tt <= 30 then
label1.forecolor = vbred
if tt <= 0 then
command1.enabled = true
command2.enabled = false
command3.enabled = false
timer1.enabled = false
end if
end if
label1.caption = (tt \ 60) & ":" & format(tt mod 60, "00")
tt = tt - 1
end sub
3樓:匿名使用者
設定一個長型變數,在窗體的載入事件中為它賦初值。
建立一個timer控制元件,設定interval屬性為響應週期,在timer1_timer中讓該變數自減。然後用一個分支,若等於0則作出某種動作。
參考例子:
dim ltime as long
sub form_ load()
ltime = 100 ’ 100秒倒計時timer1.interval=1000 ' 每秒發生一次timer事件
end sub
sub timer1_timer()
ltime = ltime - 1
me.caption = "還有" + str(ltime) + "秒"!
if ltime = 0 then
msgbox "時間已到!"
end if
end sub
4樓:
來個簡單的:
dim t as date, itime as date'開始private sub command1_click()label1.forecolor = vbbluelabel1 = "3:00"
itime = "00:03:00"
timer1.interval = 100timer1.enabled = truet = time
end sub
'暫停private sub command2_click()timer1.enabled = falseend sub
'繼續private sub command3_click()timer1.enabled = truet = time
end sub
'倒計時
private sub timer1_timer()if time - t > 1 / 24 / 3600 thenitime = itime - cdate("00:00:01")label1 = right(cstr(itime), 4)if label1 = "0:
30" then label1.forecolor = vbred
if label1 = "0:00" then timer1.interval = 0
t = time
end if
end sub
怎麼用vb編寫倒計時的程式
5樓:匿名使用者
用vb6.0寫的,執行時單擊“設定”按鈕,彈出inputbox輸入框供使用者輸入倒計時的時間(以分鐘為單位)。單擊“開始”按鈕則在文字框內顯示剩餘的時間數(以時:
分:秒的格式),同時滾動條上的滾動塊同步隨時間自左向右移動。dim shi as long
dim fen as long
dim miao as long
private sub form_load()
fen=val(0)
miao=val(0)
shi=val(0)
end sub
private sub command2_click()
fen=inputbox("時間","輸入","")
if fen>=val(60) then shi=val(shi)+val(1)
end sub
private sub command1_click()
timer1.enabled=true
end sub
private sub timer1_timer()
if miao<>val(0) then
miao=miao-1
end if
if miao=val(0) and fen <>val(0) then
fen=fen-1
miao=60-1
end if
if miao=val(0) and fen =val(0) and shi <>val(0) then
shi=shi-1
fen=60-1
miao=60-1
end if
if miao=val(0) and fen =val(0) and shi =val(0) then
msgbox("時間用盡了!")
timer1.enabled=false
end if
text1.text="還剩" & shi & "時" & fen & "分" & miao & "秒"
end sub
6樓:夷炎金項明
可以不使用控制元件。
你直接獲取當前系統的年月日(分,鈔這些都一個道理,我就不說了。只說個大概),然後把年轉為月,月轉為日,然後進行比較,相差多少,直接顯示出來就行了。
哦,說錯了,寫到這裡的話,看來還是需要一個timer控制元件才行,不然時間不會走。
思路給你寫出來了,你自己看著辦吧。
VB製作倒計時器問題,VB中怎樣製作乙個計時器? 能夠設定倒計時的時間,並進行倒計時
option explicit dim h as integer,m as integer,s as integer private sub command1 click if not isnumeric text1.text thenmsgbox 請正確小時數!exit sub end if if...