VBA retrieve object data

mwl707

New Member
Joined
Jun 5, 2024
Messages
6
Office Version
  1. 2021
Platform
  1. Windows
I have an object (JS) i my VBA which is returned from using jsonParser function. The data returned is in the image below

MOT Result Screenshot.jpg


My code includes the following to retrieve the registration and make etc.

assign parseToVb(Response, js, , ok), result
'Fill in Results
'Make
Cells(RR, "L").Value = js.make
'Model
Cells(RR, "M").Value = js.model
'Colour
Cells(RR, "N").Value = js.primaryColour

And this works as I would expect. But what I cant do is reciver the "expiryDate" that is within the motTests

I have tried

MOT = js.motTests.motTestNumber.completedDate etc
MOT = js.motTests.0.expiryDate
MOT =js.motTests[0].expiryDate

but this isnt returning anything. Ideally I want to access this data (expiryDate) without entering the test number as I wont always know it.

Any help or pointers would be much appreciated. Thanks in advance.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
I don't know what object exactly is returned by parseToVb.
I am using possibly a different one:
Code:
' VBA-JSON v2.3.1
' (c) Tim Hall - https://github.com/VBA-tools/VBA-JSON
' JSON Converter for VBA
' Errors:  10001 - JSON parse error
' @class JsonConverter
' @author tim.hall.engr@gmail.com
' @license MIT (http://www.opensource.org/licenses/mit-license.php)
'' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '
' Based originally on vba-json (with extensive changes)
' BSD license included below
' JSONLib, http://code.google.com/p/vba-json/
' Copyright (c) 2013, Ryo Yokoyama
' All rights reserved.
...
however, I would assume the output is similar (you can inspect/debug the object during runtime).
a node contains a collection (base 1), the collection contains a dictionary, so looking for a value would be something like this:
VBA Code:
MOT =js.motTests(1)("expiryDate")
as for debugging and investigating during runtime:

stop the code at this line - use a breakpoint or type Stop just before it:
VBA Code:
Cells(RR, "L").Value = js.make
then use the locals window and the immediate window to study the js object
assuming your object is what I would expect:
VBA Code:
?typename(js.motTests)
'Collection
?js.motTests.count
?typename(js.motTests(1))
'Dictionary
?Join(js.motTests(1).keys,",")
'mottestNumber, .......
?Join( js.motTests(1).items,",")
'13166.....
 
Upvote 1
Solution

Forum statistics

Threads
1,223,896
Messages
6,175,264
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top