0

Let's say I have a code, or, please, can be any code. can I put a progress bar in which to show me how long does it have until the code is finished?

 Private Sub BttTxtIntDrawo()
        TxtOutput1.Clear()
        'TxtIntDraw' - numere repetate de la o extragere la alta.
        'Aplicăm condițiile și returnăm valorile distincte în Textbox.
        Try
            'Throw everything into a list of String initially.
            Dim AllNumbers1 As New List(Of String)
            'Loop through each TextBox, splitting them by commas
            For i As Integer = 0 To TxtIntDrawX.Text
                AllNumbers1.AddRange(CType(Me.Controls("txtBoxIntDraw"), TextBox).Lines(i).Split(CChar(",")))
                'Remove non-integer entries.
            Next
            AllNumbers1.RemoveAll(Function(x) Integer.TryParse(x, New Integer) = False)
            'Join the distinct list to an array, then back to comma separated format into wherever you want it output.
            TxtOutput1.Text = String.Join(",", AllNumbers1.Distinct().ToArray())
        Catch ex As Exception
        End Try
    End Sub
  • The progress tool bar has a min and max...you set that before your loop. Then you would use progressbar.PerformStep(). – Chris Catignani Apr 20 '19 at 18:55
  • 2
    For the code in the question, if you set [`Option Strict On`](https://stackoverflow.com/a/29985039/1115360) and make the corrections it hints at, it should run quickly enough to not need a progress bar. Otherwise, the [documentation for the BackgroundWorker Class](https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.backgroundworker?view=netframework-4.7.2) has a useful example for a single long-running task. – Andrew Morton Apr 20 '19 at 21:17

0 Answers0