VB完成的倒計時類代碼詳解。本站提示廣大學習愛好者:(VB完成的倒計時類代碼詳解)文章只能為提供參考,不一定能成為您想要的結果。以下是VB完成的倒計時類代碼詳解正文
本文所述為用VB制造倒計時順序用到的一個Module類代碼,是基於控制台的倒計時順序,可供VB初學者或許VB喜好者參考學習,當然讀者也可以將其拷貝代碼到VB工程外面直接運用,不過需求自己創立相關的代碼,關於初學者來說,也是很容易看懂的一段代碼。
詳細功用代碼如下:
Module Module1 Sub Main() Dim a As Date Dim h, m, s As Integer Dim n, i As Long Dim x, z As Long Dim y As Long Console.WriteLine("本順序為倒計時順序,請分部輸出需求倒數的小時數、分鐘數、秒數") Console.WriteLine("請輸出計時的小時數(大於等於0的整數):") h = Console.ReadLine() Console.WriteLine("請輸出計時的總分鐘數(大於等於0並且小於60的整數):") m = Console.ReadLine() Console.WriteLine("請輸出計時的秒數(大於等於0的並且小於60的整數):") s = Console.ReadLine() Console.WriteLine("以後零碎時間為:{0}", h) a = Now() Console.WriteLine("以後零碎時間為:{0}", a) Console.WriteLine(" ") Console.WriteLine(" **************倒計時開端***************** ") Console.WriteLine(" **************倒計時開端***************** ") Console.WriteLine(" **************倒計時開端***************** ") Console.WriteLine(" **************倒計時開端***************** ") z = 0 x = 60 For i = 0 To h * 3600 + m * 60 + s For n = 0 To 6000000 For y = 0 To 25 z = z + 1 Next Next If (h <= 0) And (m <= 0) And (s <= 0) Then Exit For If s > 0 Then s = s - 1 Console.WriteLine(" 剩余:{0}小時{1}分{2}秒", h, m, s) If (h <= 0) And (m <= 0) And (s <= 0) Then Console.WriteLine("倒計時終了,隨意輸出字符將加入順序:") Exit For End If End If If s = 0 Then If m > 0 Then m = m - 1 s = 59 Console.WriteLine(" 剩余:{0}小時{1}分{2}秒 ", h, m, s) End If If m = 0 And h > 0 And s = 0 Then h = h - 1 m = 59 s = 59 Console.WriteLine(" 剩余:{0}小時{1}分{2}秒 ", h, m, s) If (h <= 0) And (m <= 0) And (s <= 0) Then Console.WriteLine("倒計時終了,隨意輸出字符將加入順序:") Exit For End If End If End If Next Console.Read() End Sub End Module