Question Using functions and dll's

Jose Cuervo

Member
Joined
Jul 14, 2010
Messages
14
Programming Experience
1-3
Hi,

I am not sure if i am using these in the correct manner. Basically i have an app that downloads a file from an ftp server (i am kinda cheating cos i am using chilkat).
Now if i put the code directly in the form i can get it to do a progressbar.value = ... in it['s own sub.

What i decided to do was stick my ftp download parts into a dll i created. Created a function within the dll and i have a return on that which returns the message 'file downloaded' or 'no file to download'. But can i return a value to update the progress bar as it goes when the code is contained in a dll?

Or am i totally missing the point and how to use dlls? lol
 
If you created a class in your dll, which dealt with the downloading of a file from the FTP server, then within the class you could an event called ProgressChanged.

You would then need to implement your code so that when you call the function to download it would start downloading then with each percentage of progress raise the ProgressChanged event supplying the percentage of progress as a parameter.
So your code for the downloader class would be something like;
VB.NET:
Public Class FTPDownloader
    Public Event ProgressChanged(ByVal progress As Integer)

    Public Function downloadFile(ByVal filename As String) As Boolean
        Dim currentProgress As Integer = 0
        'all you code
        'When you've downloaded an additional 1% of the FTP file then
        currentProgress += 1
        RaiseEvent ProgressChanged(currentProgress)
    End Function
End Class

And the code on your form would be something like;
VB.NET:
Public Class Form1
    Private WithEvents _downloader As FTPDownloader

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        _downloader = New FTPDownloader
        ProgressBar1.Minimum = 0
        ProgressBar1.Maximum = 100
    End Sub

    Private Sub _downloader_ProgressChanged(ByVal progress As Integer) Handles _downloader.ProgressChanged
        ProgressBar1.Value = progress
    End Sub
End Class

You may need to look into threading this in order for the form to actually do any refreshing to show the progress, but unfortunately I don't have any experience in threading so I can't help you there.

Anyway that is how I would go about achieving this, there may be a better way but I don't know one.

Hope this helps

Satal :D
 
You may need to look into threading this in order for the form to actually do any refreshing to show the progress, but unfortunately I don't have any experience in threading so I can't help you there.

Anyway that is how I would go about achieving this, there may be a better way but I don't know one.

Hope this helps

Satal :D

Yeah threading is the other thing i am looking into along with splitting into DLLs lol

That looks like the way i would do it with the code directly on the form, didn't realise i could do that with it in a dll too. Will give it a bash mate, cheers :D
 
Back
Top