I'm trying to pass an Array to a Sub so the Sub can modify one of the values of the array.
Something like this
Dim a As String = "STARTVALUE"
PopulateDataSet("Management", {a})
Public Sub PopulateDataSet(ByRef SomeRandomOtherVariable As String, ByRef ToBePopulatedVariables() As String)
ToBePopulatedVariables(0) = "TheNewValue"
End Sub
When I run the code I can step through the Sub and see where ToBePopulatedVariables(0) - which is the variable A - has the value "STARTVALUE" and then that value is changes to "TheNewValue".
But when control is passed back to the calling code the value of a reverts back to "STARTVALUE".
I've tried everything I can think of. Any ideas?
Both @karl-anderson and Nadeem_MK suggest the same thing.
But
Dim a As String()
a(0) = "FirstVariable"
PopulateDataSet("Management", {a})
Returns “Object reference not set to an instance of an object.”
When assigning the value to a(0)
However
Dim a As String() = {"FirstVariable"}
Does run.
But I’m still stuck with the new value not being returned to the calling code. I've tried doing this ByVal and ByRef but for Arrays I don't think it matters. –