none
VB loop delay RRS feed

Answers

  • Can you help me build a timer in VB console application step by step?

    like this?

    Imports System.Timers
    
    Module Module1
    
        Sub Main()
            Dim t As New Timer With {.Interval = 1000, .Enabled = True}
            AddHandler t.Elapsed, Sub()
    
                                      Console.WriteLine("aaa")
                                  End Sub
            Console.ReadLine()
        End Sub
    
    End Module
    

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Ojan8388 Wednesday, April 10, 2019 10:59 AM
    Wednesday, April 10, 2019 3:15 AM

All replies

  • Hello,

    Here is a very simple example which waits one second or each iteration of the loop. For useful information on Async see this page.

    Public Class Form1
        Private Async Sub Button1_Click(sender As Object, e As EventArgs) _
            Handles Button1.Click
    
            Dim indexer As Integer = 10
    
            While indexer <> 0
                Console.WriteLine(indexer)
                indexer -= 1
                Await Wait(1000)
            End While
    
        End Sub
        ''' <summary>
        ''' Millisecond delay
        ''' </summary>
        ''' <param name="ms">1000 = one second</param>
        ''' <returns></returns>
        Private Async Function Wait(ms As Integer) As Task
            Await Task.Delay(ms)
        End Function
    End Class
    


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, April 9, 2019 6:31 PM
    Moderator
  • How can I delay visual basic loops?

    What kind of loop?  Why delay it?

    Search Documentation

    SerialPort Info

    Multics - An OS ahead of its time.

     "Those who use Application.DoEvents have no idea what it does

        and those who know what it does never use it."    former MSDN User JohnWein

    Tuesday, April 9, 2019 6:32 PM
  • Can you help me build a timer in VB console application step by step?
    Tuesday, April 9, 2019 7:26 PM
  • Can you help me build a timer in VB console application step by step?

    What are you trying to do?

    Search Documentation

    SerialPort Info

    Multics - An OS ahead of its time.

     "Those who use Application.DoEvents have no idea what it does

        and those who know what it does never use it."    former MSDN User JohnWein

    Tuesday, April 9, 2019 7:35 PM
  • I'm trying to program timer .

    • Edited by Ojan8388 Tuesday, April 9, 2019 7:42 PM
    Tuesday, April 9, 2019 7:39 PM
  • Okay we are at the point where you need to describe without talking code what you are attempting to achieve out of this. The reason for not talking code is because there has to be a requirement and that a Timer and/or a loop may not be the proper path to take.

    What not to come back and say is something like "I'm new to coding" but instead reply back with your requirements to complete one or more task.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, April 9, 2019 9:47 PM
    Moderator
  • Can you help me build a timer in VB console application step by step?

    like this?

    Imports System.Timers
    
    Module Module1
    
        Sub Main()
            Dim t As New Timer With {.Interval = 1000, .Enabled = True}
            AddHandler t.Elapsed, Sub()
    
                                      Console.WriteLine("aaa")
                                  End Sub
            Console.ReadLine()
        End Sub
    
    End Module
    

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Ojan8388 Wednesday, April 10, 2019 10:59 AM
    Wednesday, April 10, 2019 3:15 AM