Progress Bar Trouble (Beginner)

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

My.Computer.FileSystem.CopyDirectory("\\server\proj\stds", "C:\dwgs\stds", True)

End Sub

Private Sub CopyWithProgress(ByVal ParamArray filenames As String())

ProgressBar1.Visible = True

ProgressBar1.Minimum = 1

ProgressBar1.Maximum = filenames.Length

ProgressBar1.Value = 1

ProgressBar1.Step = 1

Dim x As Integer

For x = 1 To filenames.Length - 1

If CopyDirectory(filenames(x - 1)) = True Then

ProgressBar1.PerformStep()

End If

Next x

End Sub

End Class

How do I get this to work How do I reference the progress bar to the CopyDirectory



Answer this question

Progress Bar Trouble (Beginner)

  • anand singh

    Its still responeding "name 'CopyDirectory' is not declared"
  • Tareq1176

    When the files are being copied

    Using line; My.Computer.FileSystem.CopyDirectory("\\server\proj\stds", "C:\dwgs\stds", True)

    I would like the progress bar to follow along. Something appears to be wrong with CopyDirectory line, not sure what I can do differently though. Does that help


  • Andreas Andersson

    This should work, if CopyDirectory returns true when it copies a directory successfully. Why not get rid of the conditional and just call step every time If you don't, the progress bar is not guarenteed to run to the end, anyhow.



  • Igor Grozman

    I don't follow, remember I'm still pretty new at this. What do you mean by get rid of the conditional Mike
  • jjamjatra

    Oh. See, you never said this was the problem.

    My.Computer.FileSystem.CopyDirectory("\\server\proj\stds", "C:\dwgs\stds", True)

    is how you did it before. I just assumed that CopyDirectory was a local function you were calling. You need to use the above code in order to scope the method.



  • Nat81

    Well, when you type CopyDirectory, there is no local method called that. When you typed My.Computer.FileSystem.CopyDirectory before, you showed the compiler where the method was that you wanted to call. You need to do this again.



  • Jackzlin

     

    I'm not sure that I understand your question and I think it's needs clarification as far as what you'd like to do.

    I do have one comment on your code though....

    Dim x As Integer

    For x = 1 To filenames.Length - 1

    If CopyDirectory(filenames(x - 1)) = True Then

    ProgressBar1.PerformStep()

    End If

    Next x

    can be written thusly:

    For x  as integer = 0 To filenames.Length - 1

    If CopyDirectory(filenames(x)) = True Then ProgressBar1.PerformStep()

    Next

     

     



  • Gioman40

    Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    My.Computer.FileSystem.CopyDirectory("\\server\proj\stds", "C:\dwgs\stds", True)

    End Sub

    Private Sub CopyWithProgress(ByVal ParamArray filenames As String())

    ProgressBar1.Visible = True

    ProgressBar1.Minimum = 1

    ProgressBar1.Maximum = filenames.Length

    ProgressBar1.Value = 1

    ProgressBar1.Step = 1

    Dim x As Integer

    For x = 1 To filenames.Length - 1

    My.Computer.FileSystem.CopyDirectory("C:\dwgs\stds", (filenames(x - 1)))

    ProgressBar1.PerformStep()

    End

    Next x

    End Sub

    End Class

    I guess I'm still doing it wrong, I'll try hitting the books again. Mike


  • FlávioOliveira

    I was thinking about that too...

    But why the index of X-1 when he began the loop with 1

    Why not begin it at zero and just use X



  • Ron31416

    Maybe you could make a sample, that I could better understand
  • M Thomas

    I mean just call step every time, don't make it conditional on anything

    replace

    If CopyDirectory(filenames(x - 1)) = True Then

    ProgressBar1.PerformStep()

    End If

    with

    CopyDirectory(filenames(x - 1))

    ProgressBar1.PerformStep()



  • gliffton

    This is where I'm confused. How should I go about doing this, scopeing the method
  • GuZ

    I concur, I guess he missed that suggestion.



  • Seethar

    The other thing you may need to do is call Application.DoEvents() between each copy step, so that your UI updates itself while the copy operations are taking place.



  • Progress Bar Trouble (Beginner)