This article describes a Module class code used to create a countdown program using VB. It is a console-based countdown program and can be used as a reference for VB beginners or VB enthusiasts. Of course, readers can also copy the code into a VB project directly. To use it, you need to create the relevant code yourself. For beginners, it is also a piece of code that is easy to understand.
The specific function codes are as follows:
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("This program is a countdown program, please enter the required information in parts Countdown hours, minutes, seconds") Console.WriteLine("Please enter the number of hours (an integer greater than or equal to 0):") h = Console.ReadLine() Console.WriteLine("Please enter the total number of minutes for timing (an integer greater than or equal to 0 and less than 60):") m = Console.ReadLine() Console.WriteLine("Please enter the number of seconds for timing (greater than or equal to 0 and less than an integer of 60): ") s = Console.ReadLine() Console.WriteLine("The current system time is: {0}", h) a = Now() Console.WriteLine("The current system time is: {0}", a) Console.WriteLine(" ") Console.WriteLine(" **************The countdown begins***** ************ ") Console.WriteLine(" **************Countdown begins*************** ** ") Console.WriteLine(" **************Countdown begins************************ ") Console.WriteLine(" * *************Countdown begins****************** ") 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(" Remaining: {0} hours {1} minutes {2} seconds", h, m, s) If (h <= 0) And (m <= 0) And (s <= 0) Then Console.WriteLine("Countdown Completed, enter random characters to exit the program: ") Exit For End If End If If s = 0 Then If m > 0 Then m = m - 1 s = 59 Console.WriteLine(" Remaining: {0} hours {1} minutes {2} seconds", h, m, s) End If If m = 0 And h > 0 And s = 0 Then h = h - 1 m = 59 s = 59 Console. WriteLine("Remaining: {0} hours {1} minutes {2} seconds", h, m, s) If (h <= 0) And (m <= 0) And (s <= 0) Then Console.WriteLine("The countdown is complete, enter any characters to exit the program:") Exit For End If End If End If Next Console.Read() End Sub End Module