1

I have an object with several fields:

address.kondition, address.sprache, address.waehrung and so on.

How can I access the fields in a function dynamically? I tried the following code, but address.field gives an error:

Private Sub fkt1()
    Dim address As New objAddress

    fkt2("Kondition", "1", address)
    fkt2("Sprache", "D", address)
End Sub

Private Sub fkt2(ByVal field As String, ByVal defaultvalue As String, ByVal address As objAddress)
    If address.field = 0 Then
        MsgBox("Not defined")
        address.field = defaultvalue
    Else
        ...
    End If
End Sub
5
  • What's the error? Is field an integer or a string? You use both types against it. Commented Jul 22, 2016 at 14:48
  • 1
    Ahhh! The old "gives an error" problem. If I had a shilling for every time... Commented Jul 22, 2016 at 14:52
  • The error is that "field is not a member of objAddress" as There doesn't exist a field "address.field". "Field" should represent "Kondition" or "Sprache" as "field" is a variable which can contain the string "Sprache" for example. By the way: Kondition is an integer and Sprache is a String Commented Jul 22, 2016 at 15:13
  • 1
    Check the accepted answer here. Should be enough to get you started. Commented Jul 22, 2016 at 15:44
  • Edit your post to show us your objAddress class. While you are editing the post, include your error message that you posted in the comments. Commented Jul 22, 2016 at 15:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.