That's pretty tricky... It took me almost 30 minutes to get it working right.
The trick is that, to remove 1 character, you ned to write a backspace + space + backspace.... Then when your value decrease from let's say 100 to 99, you need an adjustment so that it "erase" the correct amount of character on the screen... Anyway, here is the working code:
Code:Module Module1 Private WithEvents CountDownTimer As System.Timers.Timer Private countDownValue As Integer = 1200 Sub Main() CountDownTimer = New System.Timers.Timer() With CountDownTimer .AutoReset = True .Interval = 100 End With Console.Write("Start counting down... " & countDownValue) CountDownTimer.Start() 'Prevent the application to close Console.ReadLine() End Sub Private Sub CountDownTimer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles CountDownTimer.Elapsed Static lastDigitCount As Integer = countDownValue.ToString.Length countDownValue -= 1 Dim currentDigitCount As Integer = countDownValue.ToString.Length 'Adjustment to character erasing... If lastDigitCount > currentDigitCount Then Console.Write(ChrW(8) & ChrW(32) & ChrW(8)) lastDigitCount = currentDigitCount End If 'Erase the old value and write the new value If countDownValue > 0 Then For i As Integer = 0 To currentDigitCount - 1 Console.Write(ChrW(8) & ChrW(32) & ChrW(8)) Next Console.Write(countDownValue) Else CountDownTimer.Stop() Console.Write(ChrW(8) & ChrW(32) & ChrW(8) & countDownValue & Environment.NewLine) Console.Write("Press Enter key to exit...") End If End Sub End Module




Reply With Quote