dimanche 10 mai 2015

Calling a variable in a VB.net modlue

i am trying to make a simple FTP uploader as an excersice. i am just running into a little problem. when selceting a file to upload i want to display the path of the file in a textbox. This is what i have so far:

Public Class Form1

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

        Dim request As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create(IPBox.Text.ToString), System.Net.FtpWebRequest)
        request.Credentials = New System.Net.NetworkCredential(UserBox.Text.ToString, PassBox.Text.ToString)
        request.Method = System.Net.WebRequestMethods.Ftp.UploadFile

        Dim file() As Byte = System.IO.File.ReadAllBytes(subs.FileName)

        Dim strz As System.IO.Stream = request.GetRequestStream()
        strz.Write(file, 0, file.Length)
        strz.Close()
        strz.Dispose()

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        subs.OpenDialog()
    End Sub
End Class

in Dim file() As Byte = System.IO.File.ReadAllBytes(subs.FileName) FileName is a variable declared in a Module called subs:

 Module subs

    Public Sub OpenDialog()

        Dim FD As OpenFileDialog = New OpenFileDialog()
        Dim FileName As String

        FD.Title = "Selecteer een bestand"
        FD.InitialDirectory = "C:\"
        FD.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
        FD.FilterIndex = 2
        FD.RestoreDirectory = True

        If FD.ShowDialog() = DialogResult.OK Then
            FileName = System.IO.Path.GetFileName(FD.FileName)
        End If
    End Sub
End Module

I cant seem to reference to this specific Variable, i want to show the path in a textbox in vorm1.vb, OpenDialog() works just fine, but i have no idea why FileName won't work. is my idea even close to the solution? are there any alternatives?

Thank you in advance

Aucun commentaire:

Enregistrer un commentaire