Hi,
I want to build a function that will return information about a business subject based on its VAT ID (using an API).
Example:
Code:
Input for a subject with VAT ID 123456789: GetSubjectInfo("123456789")
Expected returns:
GetSubjectInfo(0) = "Company Name"
GetSubjectInfo(1) = "The best Avenue 123"
GetSubjectInfo(2) = "My city"
I have successfully setup the API, so I can easily get this information. But my issue is that I want to build a function that I can use over and over again, therefore I would like it to return all values (7 values to be exact). The best approach seems to be to return an array, but I can't seem to be able to set this up correctly...
This is what I have (based on some Googling):
Code:
Option Compare Database
Option Explicit
Public Function ARES_GetSubjectInfo(strICO As String) As Variant
Dim HTTPreq As Object
Dim URL As String
Dim strBody As String
Dim JSON As Object
Dim arrReturnValues(0 To 6) As String
Set HTTPreq = CreateObject("Microsoft.XMLHTTP")
URL = "https://ares.gov.cz/ekonomicke-subjekty-v-be/rest/ekonomicke-subjekty/" & strICO
HTTPreq.Open "GET", URL, False
HTTPreq.SetRequestHeader "content-type", "application/json"
HTTPreq.Send
Set JSON = JsonConverter.ParseJson(HTTPreq.ResponseText)
arrReturnValues(0) = JSON("obchodniJmeno")
arrReturnValues(1) = JSON("nazevUlice")
arrReturnValues(2) = JSON("cisloDomovni")
arrReturnValues(3) = JSON("cisloOrientacni")
arrReturnValues(4) = JSON("psc")
arrReturnValues(5) = JSON("nazevObce")
arrReturnValues(6) = JSON("kodKraje")
Set HTTPreq = Nothing
Set JSON = Nothing
ARES_GetSubjectInfo = arrReturnValues
End Function
Unfortunately this returns "type-mismatch" error.
The idea is that I will call this function only once and then be able to work with those 7 respective values anywhere in the application.
Can you please push me in the right direction?
Thank you!
Tomas