New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement For Each on the Dictionary #17
Comments
The solution to this might look something like:
but I can't quite get the syntax to cooperate. |
Wow, can't believe I hadn't tested this, great catch @dimitrimitropulos. I'll look into it, but if you find a solution please let me know. |
That requires a Public Property Get NewEnum() As IUnknown
Attribute NewEnum.VB_UserMemId = -4
'Gets an enumerator that iterates through the collection.
Set NewEnum = dict_pKeyValues.[_NewEnum]
End Property Member attributes can't be entered directly in the VBE though; needs to be exported, edited in notepad, and then imported back in. |
was this bug ever fixed? Having issues with this in the latest version on a Mac |
I don't believe it was ever fixed. I would do so myself, but I have long since moved on from VB. You could patch it yourself by copying the |
Sorry sir
The Converter.bas is okay I can pull data from any REST website, the
problem here is as follows:
*(1) Formatting the Ms Access query into Json string and send data*
*(2) How to use "POST" method*
Sorry I'm not a guru in VBA , that is why I'm struggling like this.
Any help on the above will be highly appreciated
Regards
Chris
…On Mon, 9 Sep 2019 at 13:20, Dimitri Mitropoulos ***@***.***> wrote:
I don't believe it was ever fixed. I would do so myself, but I have long
since moved on from VB.
You could patch it yourself by copying the cls file into your project and
using it instead, and then add in what I had above and see if you can get
it to work.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#17?email_source=notifications&email_token=ALEEAHKI6A65VTQ54VOUXUTQIYWOVA5CNFSM4CEB4SH2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6HF7PQ#issuecomment-529424318>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALEEAHJ5BD4QXW2XHYQD7R3QIYWOVANCNFSM4CEB4SHQ>
.
|
@skchan2 This hasn't been fixed just yet, I gave it a good go, but couldn't quite get it working right. Will look into it again in the future, but if you get it working please send a PR or a code sample! |
it would help a lot if some of this stuff was documented, but my recollection is that it (e.g. If anyone reading this issue knows of documentation for adding |
another thing is that, maybe we can update it so that this class is only referenced when not on a PC (im seeing the for each issue when testing on PC, but run fine when I remove the class). |
@dimitropoulos I tried adding your code, but still not able to get it to work. Oddly, the original code is not even working in Windows. Getting stuck in the "For Each" part, weird
|
yeah, I'm sorry. I won't be much help to you at this point. My VB days are behind me and I don't really remember how it works in this case. What I do remember is that you're stepping into somewhat uncharted territory so my best suggestion is to try and find (or construct) simpler versions of the same functionality for any other collection and see if you can get it to work. that... or... find some documentation (I was never able to find the documentation for this stuff but that was a few years ago now so maybe it now exists). |
Thank you so much I have finally shifted to dot-net-framework
(edit: removed signature)
|
Final update: I believe I was able to get a version with your original code working. As I noted in my earlier post, your code uses a dictionary object when the library is available, or when the OS isn't a mac. This is an issue because NewEnum can't be used on a dictionary and can only be used on a collection. The solution is to iterate through the keys, add them to a collection, and return that collection from NewEnum. I believe in your code, when it's used a mac or when ScriptingDictionary isn't available, it store the keys in an array. And when it is available, it stores the keys scripting.dictionary object. So you can do conditional compilation to determine which of these to iterate through, add them to a collection, and return that collection to NewEnum. I believe my main changes to your code were adding the NewEnum method, adding a private collection field called Coll at the top of this module, and setting coll = nothing in the class_terminate event. It works for me on Windows, but I don't have a mac to test on so I can't confirm. |
@beyphy the link is broken, could you update it? |
This could be achieved by constructing the IEnumVariant struct in memory e.g.: https://stackoverflow.com/a/52261687/6609896
|
@skchan2 @dimitropoulos made a modification based on the code presented. Public Function NewEnum()
Attribute NewEnum.VB_UserMemId = -4
'Gets an enumerator that iterates through the collection.
#If Mac Or Not UseScriptingDictionaryIfAvailable Then
Set NewEnum = dict_pKeyValues.[_NewEnum]
#Else
Set NewEnum = CallByName(dict_pDictionary, "_NewEnum", vbMethod)
#End If
End Function I wasn't sure if the IUnknown interface would be supported by the Mac version of VBA, so I changed the return value to Variant. (This has been confirmed to work in my environment.) |
|
observe the following comparison:
The current implementation provides a way to For Each using
.Keys
and.Items
, but not with the dictionary object itself (as Scripting.Dictionary allows).The text was updated successfully, but these errors were encountered: