How to fix "Subscript out of range" error in XML HTTP Request

How to fix "Subscript out of range" error in XML HTTP Request

Content Index :

How to fix "Subscript out of range" error in XML HTTP Request
Tag : json , By : user121350
Date : January 12 2021, 01:40 AM

like below fixes the issue Your error is coming from attempting to access an index that is out of bounds (too high) in runners collection. When you get to index 11 (0 based - or 12 when 1 based as per VBA JSON Collection) there are only two items, not 3, in runners collection. I usually handle this with an On Error Resume Next On Error GoTo 0 wrapper around the lines which populate the array - this leaves blanks for missing items. By far my preference when you know the dimensions of the array you want to populate and only need to handle some items not being present.
Option Explicit

Public Sub WriteOutResults()
    Dim s As String, json As Object

    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", "https://www.betfair.com/www/sports/exchange/readonly/v1/bymarket?_ak=nzIFcwyWhrlwYMrh&alt=json&currencyCode=USD&locale=en&marketIds=1.161189078,1.161073119,1.161362337,1.161362195,1.161362198,1.161362200,1.161362186,1.161362202,1.161362187,1.161362205,1.161362188,1.161362189,1.161425408&rollupLimit=25&rollupModel=STAKE&types=MARKET_STATE,%20EVENT,RUNNER_DESCRIPTION,RUNNER_STATE,RUNNER_EXCHANGE_PRICES_BEST", False
        s = .responseText
        Set json = JsonConverter.ParseJson(s)
    End With

    Dim runners As Object, runner As Object, results(), r As Variant
    Set runners = json("eventTypes")(1)("eventNodes")

    ReDim results(1 To runners.Count, 1 To 7)
    For Each runner In runners
        r = r + 1
        On Error Resume Next
        results(r, 1) = runner("event")("eventName")
        results(r, 2) = runner("marketNodes")(1)("runners")(1)("exchange")("availableToBack")(1)("price")
        results(r, 3) = runner("marketNodes")(1)("runners")(1)("exchange")("availableToLay")(1)("price")
        results(r, 4) = runner("marketNodes")(1)("runners")(2)("exchange")("availableToBack")(1)("price")
        results(r, 5) = runner("marketNodes")(1)("runners")(2)("exchange")("availableToLay")(1)("price")
        results(r, 6) = runner("marketNodes")(1)("runners")(3)("exchange")("availableToBack")(1)("price")
        results(r, 7) = runner("marketNodes")(1)("runners")(3)("exchange")("availableToLay")(1)("price")
        On Error GoTo 0
    ThisWorkbook.Worksheets("Sheet1").Cells(1, 1).Resize(UBound(results, 1), UBound(results, 2)) = results
End Sub

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Why do I get an error when I enter input? "expression: string subscript out of range"

Tag : cpp , By : Joe
Date : March 29 2020, 07:55 AM
hop of those help? Use a debugger. You don't say what platform you are developing on but common ones are Microsoft Visual Studio, Mac OS X and Linux.
In Visual Studio run in Debug mode. Set the debug settings to stop on a C++ exception.

"Workbook.Sheets.Add After" gives "Subscript out of range" error (VBA)

Tag : excel-vba , By : silvervino
Date : March 29 2020, 07:55 AM
around this issue I have a workbook with four sheets- First, Second, Third and Fourth. I'm trying to add an extra sheet after each sheet for creating pivot tables. They would be named First Pivot, Second Pivot, Third Pivot and Fourth Pivot. , Change this:
NewBook.Sheets.Add After:=Worksheets(CurrSheet.Index)
NewBook.Sheets.Add After:=NewBook.Worksheets(CurrSheet.Index)

Getting "subscript out of range" error from "Find" result

Tag : excel , By : OlioEngr
Date : March 29 2020, 07:55 AM
it fixes the issue The reason you get the error message on the .Find line is that vbscript does not recognize Excels constants, so you need to replace xlValues with the number -4163. (All Excel constant values can be found in the VBA Object Browser).
Also, the line you wrote Set oSht = firstExcel.Worksheets("Input Data") does not make sense to VB because firstExcel is the Excel Application itself and there is no Worksheet object associated with the Excel Application itself, but there is within the Workbook object.
Set firstExcel = CreateObject("Excel.application")
Set wkb = firstExcel.Workbooks.Open("C:\Myroute\excelName.xls")
Set oSht = wkb.Worksheets("Input Data")
Set aCell = oSht.Range("A1:E15").Find(str,,-4163)
If Not aCell is Nothing Then MsgBox aCell.row 'because if it does not find the string, it will not return a range object
const xlValues = -4163

Referencing other workbook works for most but gets "subscript out of range" error for two machines

Tag : excel , By : vbanos
Date : March 29 2020, 07:55 AM
this one helps. This would be an appropriate place to use object variable (to represent a Workbook object) instead of relying on Activate methods. Note this may require modifications elsewhere, if you are relying on ActiveWorkbook or unqualified Sheets, etc.
 Dim wbMaster as Workbook
 If Not IsAlreadyOpen("Master.xlsm") Then
    Set wbMaster = Workbooks.Open(filepath, ReadOnly:=False, UpdateLinks:=False, Password:="password here")
    Set wbMaster = Workbooks("Master.xlsm")
 End If
 With wbMaster.Sheets("This Sheet")
     .Cells.EntireRow.Hidden = False
     .Cells.EntireColumn.Hidden = False
     .AutoFilterMode = False
 End With  

How can I resolve the error "URL scheme must be "http" or "https" for CORS request." for t

Tag : javascript , By : Vasiliy
Date : March 29 2020, 07:55 AM
I wish this help you You need to be serving your index.html locally or have your site hosted on a live server somewhere for the Fetch API to work properly. The files need to be served using the http or https protocols.
If you just clicked on your index.html from your file explorer than your browser is grabbing those files directly from your file system. This is why the error is showing you an absolute path from the root folder on you computer.
Related Posts Related QUESTIONS :
  • Incorrect type. Expected "object"
  • json_to_record with embedded encoded json in PostgreSQL >= 10
  • Nested json extract from powershell
  • Parsing Json using Golang
  • Type 'number' is not assignable to type 'string'. How to cast number to string
  • kubectl - format the resource quota values in json format
  • Initializing and inserting nested JSON data in Golang?
  • Open JSON files in PhpStorm built-in web server
  • Extract Badge ID from JSON in .gitlab-ci.yml
  • Sharing Json Schema files among projects with versioning
  • Export Json data to an excel file using Angular 4
  • Return an empty array instead of null with golang for json return with gin
  • can Kafka connect value conveter (JSONConverter) can be used to convert GPB?
  • read json and access multiple keys
  • Spark How to get number of Keys changed in two JSONS in Scala?
  • Break JSON in pager "less"
  • How to filter Map in Flutter?
  • Convert hashmap to simple object in Groovy
  • Not extracting json properly using json4s
  • How do I display JSON data in my tableView when objects have the same value?
  • Where I can parse IoT data in Azure so I can afterwards save it to SQL DB
  • How to unmarshal this json string
  • What's wrong with my JSON?
  • JSON parsing problem in BlackBerry
  • GWT: How can I use JsonpRequestBuilder to handle a Json response of a list
  • JSON feed to Java Object
  • json character encoding problem
  • JSON Loading Speed Optimization: Use online API vs. create my own API based on that?
  • How can I access some JSON documents from my AWS lambda function?
  • How to extract multiple correlating variables from a JSon
  • Schema/Resolve for nested objects graphql/mongoose
  • Dynamics 365 opportunity EntityType processid and stagename error
  • How to convert dataframe output to json format and then Normalize the data?
  • In Angular, how do I avoid a "Property 'json' does not exist on type 'Object'" error?
  • Python giving vague error when trying to parse JSON object
  • Invalid JSON literal: xxx when calling ASMX service from Angular8
  • How to write the data converted from json to csv without skipping the rows
  • Unpacking JSON Into Flat Format
  • TypeError: items is undefined while reading a json using fetch in reactjs
  • How to insert date to the web path api
  • schema validation get value from sum of another value of json
  • Deleting a field in nested objects in JQ
  • Get multiple JSON keypair values within a JSON object only if a specific keypair value matches iterable
  • parse contents from returned json to el-dropdown-item
  • Replace content by key in JSON
  • JSON parsing using String Condition with JMESPATH
  • Only Output Rule Alerts to Suricata EVE
  • How to unmarshal a json string with a hyphen in key to a struct?
  • How can I aggregate sub-values into arrays with jq?
  • How to parse JSON array in Flutter with length of one?
  • Python: Combine multiple lists into one JSON array
  • jq - parsing complex JSON into a string
  • Json array elements duplication using jolt
  • How to read multiple json files
  • How to configure different levels for different appenders but under same logger in logback
  • How to skip text at the beginning of a json file in python
  • Value of type 'Type' has no subscripts Error Swift
  • Map mongo aggregation result to array
  • How to convert Matrix HTML to JSON in Typescript (for sending through api)
  • jsonschema - oneOf keyword behaves unexpectedly
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com