Skip to content
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

Exception with key declared as string and modified in sub byref as variant #27

Open
omegastripes opened this issue Nov 8, 2019 · 0 comments

Comments

@omegastripes
Copy link

There is a simplified snippet from a project with Scripting.Dictionary, which works fine:

Sub testDict()
    
    Dim dict As Variant
    addValue dict
    
End Sub

Sub addValue(dict)
    
    Dim key As String
    
    Set dict = CreateObject("Scripting.Dictionary")
    createKey key
    dict(key) = "value"
    
End Sub

Sub createKey(key)
    
    key = "a"
    
End Sub

There is the same snippet with VBA-Dictionary, and it throws an exception in Property Let Item(): "Invalid procedure call or argument" with #Const UseScriptingDictionaryIfAvailable = True or "Variable uses an Automation type not supported in Visual Basic" with #Const UseScriptingDictionaryIfAvailable = False

Sub testDict()
    
    Dim dict As Variant
    addValue dict
    
End Sub

Sub addValue(dict)
    
    Dim key As String
    
    Set dict = New Dictionary
    createKey key
    dict(key) = "value"
    
End Sub

Sub createKey(key)
    
    key = "a"
    
End Sub

Note for commenters: I do not need to change anything in the project, more of that, the issue can be fixed by Dim key As Variant. The snippet is simplified as much as possible, also subs are used instead of functions because they returns data via several variables byref in the project. It works with no issues with Scripting.Dictionary, now I tried VBA-Dictionary and found some difference, that is why I reported here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant