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

Asked

Viewed 262 times

1

I’m having a problem that’s turning my head backwards! I’m building a server connection DLL FTP but right away I’m faced with the following problem:

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

Example:

Imports Servidor.FTP

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

But the visual Studio says the following

Too Many Arguments to "Public Sub New"

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

Initial Code of the DLL

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
  • Syntax is wrong. What type of must be the variable FTPServ? Do you have any documentation of this class? It would be nice to see the builder of this type to see if it is matching what you are using. Without seeing how she is There’s no way to answer.

  • Parameters passed in class creation do not match with constructor.

  • Ftpserv is a reference to FTP class and this FTP class has to get these user and password server parameters

  • Put the FTP class constructor code there.

  • take a look there I’ve done several ways but at the time of declaring the variable in the form VS still says Too Many Arguments

  • Good afternoon, managed to solve the problem?

Show 1 more comment

3 answers

1


The mistake Too many arguments to "Public Sub New" means that you passed over arguments in the constructor method. Looking at the code it seems that 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 your class is called FTPServ and not FTP as said in the other reply, 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 has to be equivalent to the class name.

Then the right 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 therefore the error of the arguments continue, as you have edited the correct file but imported the error (I guess, not sure).

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 declare so:

Dim ftp As New FTPServ("Servidor", "Usuário" , "Senha")
  • I tried this once but VS keeps saying Piblic Sub New() and does not recognize the strings

0

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

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

  • è n understand a lot of Vb but from what I’ve seen VS would release me an object reference exception not defined for an object instance

  • See other colleague’s up-to-date response.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.