Pass parameters in a VB6 application

Asked

Viewed 1,601 times

1

How do I pass VB6 parameters?

Private Sub Command1_Click()
    Dim cnpj As String
    cnpj = "tal"

    Dim chaveCliente As String
    chaveCliente = "tal"

    Dim chaveAcesso As String
    chaveAcesso = "tal"

    Dim status As String
    status = ""

    Dim protocolo As String
    protocolo = ""

    Dim motivoRejeicao As String
    motivoRejeicao = ""

    Dim objFuncao As Funcao

    Set objFuncao = New Funcao

    objFuncao.Consultar(ByVal cnpj As String)

Whereas the Funcao was added as a reference to a COM created in .NET. It is giving syntax error, but everywhere I looked for the syntax of sending parameters is the one in the code.

Is there any other alternative or am I doing wrong?

  • Is the problem on that line? objFuncao.Query(Byval cnpj As String) You should probably just call cnpj with parameter like this: objFuncao.Query(cnpj)

  • What error are you making? Try to explain a little more about your question.

  • The only sentence VB6 returns is that it has a syntax error. I am wanting to send all variables as a parameter to the function that is in the DLL created in . NET, which would look something like this: objFuncao.Query(cnpj, keyClient, keyCcess), but with Byval and writing with cnpj As String, always from syntax error

  • 1

    It seems that you are confusing something, only used (Byval cnpj as String) in the definition of a method and not in your call.

  • I get it, passing parameters only passes the variables even. Now I have another question, in C# I pass some variables of type out empty String along with the method and it returns me the filled variables, as I do this in vb6?

1 answer

1


The syntax error is on this line:

objFuncao.Consultar(ByVal cnpj As String)

The correct would simply be:

objFuncao.Consultar(cnpj)

This format is used in the function signature:

ByVal [nome variável] As [Tipo Variável]
ByRef [nome variável] As [Tipo Variável]

Whereas ByValis the default and can be omitted.

Example:

Private Function Soma(ByVal x As Integer, ByVal y As Integer)
    Soma = x + y
End Function

[..]
    z = Soma(1, 2)

Recommended reading: http://msdn.microsoft.com/pt-br/library/ddck1z30.aspx

Browser other questions tagged

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