vb中如何設計類似60秒倒計時的程式

2021-06-17 18:02:24 字數 3370 閱讀 3303

1樓:

建立一個timer控制元件:timer1

設定timer1的interval屬性為1000建立一個顯示倒計時的lable:lbltime**:dim i as long

private sub form_load()i=60

endsub

private sub timer1_timer()i=i-1

lbltime.caption="倒計時" & iif i<=0 then

msgbox "倒計時結束,退出"

endendif

end sub

2樓:otz進進

新增timer控制元件,新增label控制元件,label的caption屬性為60,將interval屬性設為1000(每一秒執行一次)然後在timer的time中新增

dim i as integer '定義迴圈變數

private sub timer1_timer()

i=60 '定義變數值迴圈,60次

i = i - 1 '每次迴圈i的值減去一

label.caption="還有"& i & "秒" '輸出i的值,即實現倒計時顯示

if i <= 0 then '判斷i的值是否為零,即迴圈是否到達60次

**塊 '是的話執行**塊中的內容,就是你想要實現的功能,如:"msgbox “遊戲結束”"

timer1.enabled = false '最後關閉timer,不再迴圈

end if '退出if語句

end sub

3樓:匿名使用者

dim flag as boolean '定義布林型變數,用於判斷倒計時間是否已到.若倒計時到,則停止遊戲

private sub form_load()label1.caption = 60

timer1.interval = 1000end sub

private sub timer1_timer()label1.caption = label1.caption - 1

if label1.caption = 0 thenlabel1.caption = "遊戲結束"

flag = true '此時倒計時時間到,設定flag為true(flag系統預設初值為false),用以作為結束程式標誌

timer1.enabled = falseend if

end sub

上面就是倒計時的程式

你可以執行遊戲的**處進行如下判斷

....

if flag =true then

exit sub

else

....你的遊戲**

4樓:蘇州老三石

在窗體中加個timer,然後用如下**

dim i as integer

private sub form_load()i = 60

timer1.interval = 1000end sub

private sub timer1_timer()i = i - 1

form1.cls

print i

if i = 0 then

timer1.enabled = falsemsgbox ("time over!")end if

end sub

5樓:

用timer控制元件。很容易實現。

vb中怎樣製作一個計時器? 能夠設定倒計時的時間,並進行倒計時

6樓:

1、開啟vb6.0,新建一個工程,在窗體中新增三個命令按鈕,caption分別改為“設定倒計時”、“啟動倒計時”、“繼續”,將窗體form1的caption屬性改為“倒計時”,新增一個計時器控制元件,新增一個文字框。

2、將文字框的text屬性清空,將字型font屬性調整為小四,便於觀察,將背景色屬性backcolor調為淺黃色。

3、雙擊“設定倒計時”命令按鈕,進入**編輯視窗。

4、雙擊“啟動倒計時”命令按鈕,進入**編輯視窗。

5、雙擊“計時器”控制元件,進入**編輯視窗。

6、在**編輯視窗的通用段進行變數定義:dim h as integer, m as integer, s as integer '分別儲存時分秒dim a as integer。

8、關閉**視窗,按下f5執行程式,單擊“設定倒計時”命令按鈕,彈出輸入對話方塊,此時輸入分鐘數為1,確定。

9、單擊“啟動倒計時”命令按鈕,文字框顯示倒計時時間,並時刻變動,至此實現了倒計時功能。

7樓:天天過節

用到三個控制元件:文字框(text1)、按鈕(command1)、計時器(timer1)

private sub command1_click()timer1.interval = 1000end sub

private sub timer1_timer()text1.text = val(text1.text) - 1if text1.

text < 1 thenmsgbox "時間到"

unload me

end if

end sub

8樓:弒神者是我

事先要在秒錶**調 enable屬性為false,interval屬性為1000

private sub command1_click()timer1.enabled = trueend sub

private sub timer1_timer()text1.text = val(text1.text) - 1if text1.

text < 1 thenmsgbox "時間到"

unload me

end if

end sub

9樓:匿名使用者

設定倒計時 開始時間t

for ,step -1

顯示 t-1s

next

vb6.0:怎麼實現每過60秒,分鐘的倒計時?即秒數按1秒倒計時,分鐘數按1分鐘(60秒)倒計時。

10樓:聽不清啊

mindec 和 secdec 設為全域性

變數private sub timer1_timer()secdec = secdec - 1

form2.label2.caption = secdecform2.label1.caption = secdec \ 60end sub

11樓:水柏稅宇文

密碼:111-1111111

vb6 0中MessageBox怎麼用

很簡單比如 private sub command1 click if text1.text 20100344 thenmsgbox 登陸成功 shell c documents and settings administrator 桌面 登入系統元件 bin bg1.exe endelse msg...

在VB中什麼叫立即視窗,vb6 0中的立即視窗的特點是什麼?這個用來幹什麼的?

立即視窗是一個能立即執行vb命令的除錯視窗,又稱debug window。常用來除錯程式。vb窗體是visual basic編譯環境提供的用於開發桌面程式的通用窗體類,其中包含和設計好的屬性和方法,開發人員可以直接使用,或基於窗體類 class form 定製自己的程式介面,無需從底層去編寫每一個細...

在vb程式設計中如何把小寫變成大寫,VB中如何把原來字母中的小寫改為大寫,大寫改為小寫

vb6.0可使用ucase 函式可將小寫字母變成大寫。ucase 函式,返回 variant string 其中包含轉成大寫的字串。ucase 函式示例 本示例使用 ucase 函式來將某字串轉成全部大寫。說明,只有小寫的字母會轉成大寫 原本大寫或非字母之字元保持不變。dim lowercase,u...