Open Haliiliya opened 4 years ago
Most likely issue is that you forgot to use the set statement with the new operator.
Set obj = new Collection
Hope that helps, Andrew.
From: Hali Iliya notifications@github.com Sent: Monday, December 30, 2019 10:02:13 AM To: VBA-tools/VBA-JSON VBA-JSON@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: [VBA-tools/VBA-JSON] Invalid Use of new keyword (#157)
I do the same that you do in tutorial video but I got this error message Invalid Use of new keyword
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/VBA-tools/VBA-JSON/issues/157?email_source=notifications&email_token=AIKTRA3SQMMKIIUNFSUSZWLQ3IEPLA5CNFSM4KBNK2CKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IDLMLDA, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIKTRA3PHOKOAJAX5A64AKLQ3IEPLANCNFSM4KBNK2CA.
From: Hali Iliya notifications@github.com Sent: Monday, December 30, 2019 10:02:13 AM To: VBA-tools/VBA-JSON VBA-JSON@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: [VBA-tools/VBA-JSON] Invalid Use of new keyword (#157)
I do the same that you do in tutorial video but I got this error message Invalid Use of new keyword
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/VBA-tools/VBA-JSON/issues/157?email_source=notifications&email_token=AIKTRA3SQMMKIIUNFSUSZWLQ3IEPLA5CNFSM4KBNK2CKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IDLMLDA, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIKTRA3PHOKOAJAX5A64AKLQ3IEPLANCNFSM4KBNK2CA.
I am getting this same error, but it is not in my code that the error is pointing to. It is pointing to Private Function json_ParseObject, the 3rd line of code in that function calls "Set json_ParseObject = New Dictionary". This is where the error shows.
Difficult to say what might be wrong without some surrounding code around the issue. Post a reduced code sample that demonstrates what you are experiencing.
Here's the example that does not work
Sub Parser()
Dim para As Paragraph
Dim xmlhttp As New MSXML2.XMLHTTP60
Dim url As String
url = "https://jsonplaceholder.typicode.com/todos/1"
xmlhttp.Open "GET", url, False
xmlhttp.Send
Dim Json As Object
Set Json = JsonConverter.ParseJson(xmlhttp.responseText)
MsgBox Json("title")
End Sub
Here's how to fix it
'Private Function json_ParseObject(json_String As String, ByRef json_Index As Long) As Dictionary
Private Function json_ParseObject(json_String As String, ByRef json_Index As Long) As Object
Dim json_Key As String
Dim json_NextChar As String
'Set json_ParseObject = New Dictionary
Set json_ParseObject = CreateObject("Scripting.Dictionary")
In the module that has json_ParseObject, do you have a reference for Microsoft Scripting Runtime? The fix looks like you do not as it is changing from early binding (using new) to late binding (using CreateObject).
Or do you have multiple Dictionary classes? If using "new Scripting.Dictionary" works instead of just "new Dictionary", then this is likely the reason.
Here's the example that does not work
Sub Parser() Dim para As Paragraph Dim xmlhttp As New MSXML2.XMLHTTP60 Dim url As String url = "https://jsonplaceholder.typicode.com/todos/1" xmlhttp.Open "GET", url, False xmlhttp.Send Dim Json As Object Set Json = JsonConverter.ParseJson(xmlhttp.responseText) MsgBox Json("title") End Sub
Here's how to fix it
'Private Function json_ParseObject(json_String As String, ByRef json_Index As Long) As Dictionary Private Function json_ParseObject(json_String As String, ByRef json_Index As Long) As Object Dim json_Key As String Dim json_NextChar As String 'Set json_ParseObject = New Dictionary Set json_ParseObject = CreateObject("Scripting.Dictionary")
thanks
I do the same that you do in tutorial video but I got this error message Invalid Use of new keyword Here is my code
Set MyRequest = CreateObject("WinHttp.WinHttpRequest.5.1") MyRequest.Open "GET", "https://jira.atlassian.com/rest/api/2/issue/JRA-9.json" MyRequest.send ' MsgBox MyRequest.ResponseText Dim Json As Object Set Json = JsonConverter.ParseJson(MyRequest.ResponseText) MsgBox Json("key")
Also I running Microsoft Script Running.