1

I'm trying to create a program in which I'm assigning array to array. They are declared like that:

Const Deck_Size = 52

Private Deck(Deck_Size), Table_Deck(Deck_Size) As String

So, in my program I have written this line:

Deck = Table_Deck

And what this does, how i can understand from results I'm getting, that "Table_Deck" pointer have been assign to "Deck". For e.g.

Table_Deck = "As","Ks","Qs","Js",...

Deck = "2h", "3h", "4h", "5h",...

After this code line: Deck = Table_Deck, I have this:

Table_Deck = "As","Ks","Qs","Js",...

Deck = "As","Ks","Qs","Js",...

And here comes the problem.

When the next code line is done (which is: Table_Deck(1) = Table_Deck(4)), I get this result: Table_Deck = "Js","Ks","Qs","Js",..., but as well "Deck" changes too...

Deck = "Js","Ks","Qs","Js",...

So, I assume that this is pointers fault. Can anyone tell me how I can solve this problem, if I want to change element in only one array.

1 Answer 1

4

Right, your assignment changes the array reference. Afterwards, both Deck and Table_Deck reference the exact same array. So any changes you make to Deck's content will be visible through the Table_Deck reference as well. You have to copy the content instead:

    Table_Deck.CopyTo(Deck, 0)
Sign up to request clarification or add additional context in comments.

Comments

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.