hi,
i am enclosing a test macro. In this macro i create a dictionary object to count the number of processA and processB values for a given ID.
For some reason it is not working
any ideas?
hi,
i am enclosing a test macro. In this macro i create a dictionary object to count the number of processA and processB values for a given ID.
For some reason it is not working
any ideas?
What do you think dic_InFl_SiteIds should be?
Everyone who confuses correlation and causation ends up dead.
sorry ..........it should be "dic_Ids"
I figured. Would you also care to be a little more specific than "not working"?
the first time through when i find an ID that is not in the dictionary i add it to the dictionary like this
First line adds it to dictionary and 2nd/3rd line re-assigns values in procA and procB to dictionary.......but for some reason its not updating. it stays at zero even if "ProcA_array(LC1, 1)=1"![]()
Please Login or Register to view this content.
Why don't you just use a pivot table?
The reason for the code not working is that dic_Ids.Item(ID_array(LC1, 1)) returns a copy of the array and that's what you change. You need to use something like this:
![]()
Please Login or Register to view this content.
thanks.
Based on your code i also came up with a soln.
Basically you CAN NOT do this assignment and i dont know why:
but you CAN do this type of assignment:![]()
Please Login or Register to view this content.
i am also enclosing the code i came up with .........thanks again for your help.![]()
Please Login or Register to view this content.
For the reason I gave you. This:
returns a copy of the array in the Dictionary, so when you do this:![]()
Please Login or Register to view this content.
you only update the copy.![]()
Please Login or Register to view this content.
but why does this work then:
wouldnt your comments about the "copy" still apply? thanks again for your help![]()
Please Login or Register to view this content.
No because you are assigning the array directly to the dictionary item. In the former case, you have to return the (copy of the) array before you can access an element of it (to read or write).
Another option see code comments:-
Results start column "G"
Regards Mick![]()
Please Login or Register to view this content.
Mick,
Other than using Q rather than vTemp, is that different from mine? (BTW, you forgot to alter the bit in the Else part)![]()
To be Honest I've only just seen your code. If I'd seen it before I posted , I would not have bothered !!!!!
No worries - thought I was missing something.
i hope you dont think i am totally stupid but i just dont get this statement
"In the former case, you have to return the (copy of the) array before you can access an element of it (to read or write)"
i just dont see why i cant make this type of assignment
i can display to the screen the contents of this![]()
Please Login or Register to view this content.
so why cant i make an assignment to it.........just dont get the "copy thing"![]()
Please Login or Register to view this content.
granted we have a fix i am just trying to understand why could not do what i thought should work
Whenever you put an array into a Dictionary, or get one out, you are dealing with a copy. So if you create an array variable, load it into a Dictionary and then alter the original array variable, the Dictionary contents don't change.
In order to access any element of the array, you have to return the whole array first. In the case of your code, there is an implicit variable created similar to my vTemp variable, which is a copy of what is in the Dictionary (that's just the way it works).
Reading the copy (e.g. outputting to messages/immediate window) is fine because it's a copy - so the contents are the same as the array in the Dictionary.
Writing to an element also changes the copy only.
The only way to update the array contents is to assign a new array back to the Dictionary item.
I don't really know how else to put it I'm afraid.
BTW, the same is true of the Collection object.
Last edited by romperstomper; 10-23-2014 at 11:01 AM.
thanks......that does help a little more.......
Hello Welchs101,
I use this technique a lot. Here is my version of the macro. It outputs the results on "Sheet3".
![]()
Please Login or Register to view this content.
Last edited by Leith Ross; 10-23-2014 at 10:18 PM.
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks