Problems by using byref

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lola

    Problems by using byref

    Hello:

    This is my first message, and my english is a little poor, sorry about
    the inconvenience.

    I'm writing code with Visual Basic for Applications. Platform is
    Windows 2000, coding with Access 2000. I write the following sub:
    [color=blue]
    > Public Sub ObtainFieldAndV alue(ByVal st As String, ByVal sNew As String, _
    > sf As String, sv As String)
    > 'Here goes the code, a select in which values to sf and sv are assigned
    > 'For example:
    >
    > Select Case TranslateTable( st)
    > Case "TABLE1"
    > sf = "FIELDS_NAM E"
    > sv = ValueForField
    > 'etc
    > End Select
    > End Sub[/color]

    I don't declare that sf and sv are Byref, because I understand that
    ByRef is the default, and not putting it it's the same that putting it
    as ByRef.

    After that Sub, I write another Function in which I call this,
    ObtainFieldAndV alue. We get something like this:
    [color=blue]
    > Public Function DoSomething(ByV al sTable As String, ByVal sKey As String) As String
    > Dim sField, sValue As String
    >
    > ObtainFieldValu e sTable, sKey, sField, sValue
    >
    > DoSomething = sField & " = " & sValue
    > End Function[/color]

    When I try to execute that function, I get this error message
    (translated from spanish):

    "Compilatio n error:"
    "Type of ByRef argument doesn't match"

    It marks the parameter sField on the line of the call to
    ObtainFieldValu e as the error.

    Questions are: what's the problem? what am I doing bad? what's
    supposed to be the right way of doing it?

    If you don't understand me, I'll try to be clearer (if I can).

    Thanks anyway.
  • Kris M

    #2
    Re: Problems by using byref

    I would suggest that the assignment statement
    sv = ValueForField
    should be sv = "ValueForFi eld" that way the assigned value is a string.
    perhaps that will clear things up.
    Im not completely sure it will work but but i would try it and see if it
    solves the problem.
    Looks like your trying to put non string data into a variable declared as
    string type.

    "Lola" <maddycl@yahoo. com> wrote in message
    news:6f38a621.0 307240925.4894b [email protected] gle.com...[color=blue]
    > Hello:
    >
    > This is my first message, and my english is a little poor, sorry about
    > the inconvenience.
    >
    > I'm writing code with Visual Basic for Applications. Platform is
    > Windows 2000, coding with Access 2000. I write the following sub:
    >[color=green]
    > > Public Sub ObtainFieldAndV alue(ByVal st As String, ByVal sNew As String,[/color][/color]
    _[color=blue][color=green]
    > > sf As String, sv As String)
    > > 'Here goes the code, a select in which values to sf and sv are[/color][/color]
    assigned[color=blue][color=green]
    > > 'For example:
    > >
    > > Select Case TranslateTable( st)
    > > Case "TABLE1"
    > > sf = "FIELDS_NAM E"
    > > sv = ValueForField
    > > 'etc
    > > End Select
    > > End Sub[/color]
    >
    > I don't declare that sf and sv are Byref, because I understand that
    > ByRef is the default, and not putting it it's the same that putting it
    > as ByRef.
    >
    > After that Sub, I write another Function in which I call this,
    > ObtainFieldAndV alue. We get something like this:
    >[color=green]
    > > Public Function DoSomething(ByV al sTable As String, ByVal sKey As[/color][/color]
    String) As String[color=blue][color=green]
    > > Dim sField, sValue As String
    > >
    > > ObtainFieldValu e sTable, sKey, sField, sValue
    > >
    > > DoSomething = sField & " = " & sValue
    > > End Function[/color]
    >
    > When I try to execute that function, I get this error message
    > (translated from spanish):
    >
    > "Compilatio n error:"
    > "Type of ByRef argument doesn't match"
    >
    > It marks the parameter sField on the line of the call to
    > ObtainFieldValu e as the error.
    >
    > Questions are: what's the problem? what am I doing bad? what's
    > supposed to be the right way of doing it?
    >
    > If you don't understand me, I'll try to be clearer (if I can).
    >
    > Thanks anyway.[/color]


    Comment

    Working...