How to Pass Arguments to a class Ex: Dim t as new TL ("string", "string", "string")

1

I have a problem that is turning my head upside down! I am building a connection DLL with FTP server but soon I face the following problem:

I need to declare the class in a form to open the connection to the FTP Server, but in this class declaration the variable must contain the FTPServ , User and Password . But there's the problem. I can not create string for a class, I have programming time but in javascript for games!

Example:

Imports Servidor.FTP

Dim FTPServ As New FTP("Servidor", "Usuário" , "Senha")

But Visual Studio speaks the following

Too many arguments to "Public Sub New"

I declare the Hostname, User and Password Property and I used the Sub New but nothing is right.

DLL Home Code

Imports System.IO
Imports System.Net
Imports System.Net.NetworkCredential
Public Class FTPServ
    Dim URIFTP As String = ""
    Dim SWServidor As WebRequest = FtpWebRequest.Create(URIFTP)

    Public _Host As String
    Public _Password As String
    Public _User As String



    Public Property HostnameP As String

        Get
            Return _Host
        End Get
        Set(ByVal V As String)

        End Set
    End Property



    Public Property UsuárioP As String

        Get
            Return _Host
        End Get
        Set(ByVal V As String)

        End Set
    End Property




    Public Property SenhaP As String

        Get
            Return _Password
        End Get
        Set(ByVal V As String)

        End Set
    End Property



    Public Sub New(ByVal usuário As String, ByVal Senha As String, ByVal Domain As String)
        Me._Host = Domain
        Me._Password = Senha
        Me._User = usuário
    End Sub


    Public Function UploadFile(ByVal URLArquivo As String, Destino As String)
        ' SWServidor.Credentials = New NetworkCredential(Hostname, Usuário, Senha)
        SWServidor.Method = WebRequestMethods.Ftp.UploadFile
        Try

            Dim ByteFile() As Byte = System.IO.File.ReadAllBytes(Destino)
            Dim MyStream As System.IO.Stream = SWServidor.GetRequestStream()
            MyStream.Write(ByteFile, 0, ByteFile.Length)
            MyStream.Close()
            MyStream.Dispose()

        Catch ex As Exception

            MsgBox("Erro")

        End Try
    End Function
End Class
    
asked by anonymous 11.03.2015 / 03:07

3 answers

1

The error Too many arguments to "Public Sub New" means that you passed more arguments in the constructor method. Looking at the code it looks like the amount of arguments is ok:

Public Sub New(ByVal usuário As String, ByVal Senha As String, ByVal Domain As String)
    Me._Host = Domain
    Me._Password = Senha
    Me._User = usuário
End Sub

But then I noticed that your class is called FTPServ and not FTP as stated in the other answers, but even you changing the error continued, so I noticed that you are importing Imports Servidor.FTP , but in other programming languages the file name must be equivalent to the class name.

Then the correct thing would be to use this:

Imports Servidor.FTPServ

and this:

Dim ftp As New FTPServ("Servidor", "Usuário" , "Senha")

It is likely that you have created more than one file and are editing and importing the wrong one and that is why the arguments error continues because you have edited the correct file but imported the error (I think, I'm not sure) p>     

21.06.2015 / 21:24
0

Your class is not called FTP , but FTPServ, I made some modifications:

Public Class FTPServ
    Dim URIFTP As String = ""
    Dim SWServidor As WebRequest = FtpWebRequest.Create(URIFTP)

    Private _Host As String
    Private _Password As String
    Private _User As String

    Public Property HostnameP As String

        Get
            Return _Host
        End Get
        Set(ByVal V As String)

        End Set
    End Property

    Public Property UsuárioP As String

        Get
            Return _Host
        End Get
        Set(ByVal V As String)

        End Set
    End Property

    Public Property SenhaP As String

        Get
            Return _Password
        End Get
        Set(ByVal V As String)

        End Set
    End Property

    Public Sub New(ByVal usuario As String, ByVal senha As String, ByVal domain As String)
        Me._Host = domain
        Me._Password = senha
        Me._User = usuario
    End Sub


    Public Sub UploadFile(ByVal URLArquivo As String, Destino As String)
        ' SWServidor.Credentials = New NetworkCredential(Hostname, Usuário, Senha)
        SWServidor.Method = WebRequestMethods.Ftp.UploadFile
        Try

            Dim ByteFile() As Byte = System.IO.File.ReadAllBytes(Destino)
            Dim MyStream As System.IO.Stream = SWServidor.GetRequestStream()
            MyStream.Write(ByteFile, 0, ByteFile.Length)
            MyStream.Close()
            MyStream.Dispose()

        Catch ex As Exception

            MsgBox("Erro")

        End Try
    End Sub
End Class

    Public Sub New(ByVal usuario As String, ByVal senha As String, ByVal domain As String)
        Me._Host = domain
        Me._Password = senha
        Me._User = usuario
    End Sub


    Public Sub UploadFile(ByVal URLArquivo As String, Destino As String)
        ' SWServidor.Credentials = New NetworkCredential(Hostname, Usuário, Senha)
        SWServidor.Method = WebRequestMethods.Ftp.UploadFile
        Try

            Dim ByteFile() As Byte = System.IO.File.ReadAllBytes(Destino)
            Dim MyStream As System.IO.Stream = SWServidor.GetRequestStream()
            MyStream.Write(ByteFile, 0, ByteFile.Length)
            MyStream.Close()
            MyStream.Dispose()

        Catch ex As Exception

            MsgBox("Erro")

        End Try
    End Sub
End Class

You state like this:

Dim ftp As New FTPServ("Servidor", "Usuário" , "Senha")
    
11.03.2015 / 03:34
0
  

Dim FTPServ As New FTP ("Server", "User", "Password")

If you are really making this call the error is in "New FTP"

    
11.03.2015 / 03:47