Hi,
I'm a newbie in x and I was trying to write this c# code (sorry for the double Static void but for some reason it won't let me edit):
static void Main(string[] args) static void Main(string[] args) { Response response = ReadSerie(); Serie serie = response.seriesResponse.series[0]; Console.WriteLine("Serie: {0}", serie.Title); foreach (DataSerie dataSerie in serie.Data) { if (dataSerie.Data.Equals("N/E")) continue; Console.WriteLine("Fecha: {0}", dataSerie.Date); Console.WriteLine("Dato: {0}", dataSerie.Data); } Console.ReadLine(); }
I did try in this way but I have errors in every strFmt saying "The name 'Exception' does not denote a class, a table, or an extended data type. " and the foreach the syntax is not correct it seems:
using BanxicoDll; using System; using System.Console; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Net; using System.Runtime.Serialization.Json; using System.Runtime.Serialization; class BanxicoConsumo { static void Main() { ; BanxicoDll.DataSerie dataSerie; str url = "https://www.banxico.org.mx/SieAPIRest/service/v1/series/SF61745/datos/2023-01-31/2023-01-31"; // Crea una instancia de la clase Program de la DLL BanxicoDll Program banxico = new Program(); try { // Utiliza el método ReadSerie de la instancia de Program para obtener la respuesta del API Response response = BanxicoDll.Program::ReadSerie(url); // Si la respuesta no es nula, procesa la serie if (response != null && response.seriesResponse.series.Length > 0) { BanxicoDll.Serie serie = response.seriesResponse.series.GetValue(0); info(strFmt("Serie: %1", serie.Title)); for (BanxicoDll.DataSerie dataSerie : serie.Data) { if (dataSerie.Data == "N/E") continue; info(strFmt("Fecha: %1", dataSerie.Date)); info(strFmt("Dato: %1", dataSerie.Data)); } } else { info(strFmt("No se pudo obtener la serie del API de Banxico.")); } } catch (Exception::CLRError) { info("Se produjo un error al conectarse con el API de Banxico."); } } }
Thank you so much Martin, you are great.
Ah, sorry. The namespace is System.Collections, not just System.
Yes, sorry, I copied the wrong code. In regards to your suggestion, it says that "The name 'System.IEnumerable' does not denote a class, a table, or an extended data type." Do I have to update any model or declare any library?
I'm not familiar with this syntax
for (BanxicoDll.DataSerie dataSerie : serie.Data)
and you don't seem to have in your C# code. This is whay you're using:
foreach (DataSerie dataSerie in serie.Data) { ... }
This is basically a shortcut for using an enumerator - foreach calls GetEnumerator() method of serie.Data and iterates the elements. X don't have foreach, but you can do the same thing as foreach. For example:
System.IEnumerable series = serie.Data; System.Collections.IEnumerator enumerator = series.GetEnumerator(); while (enumerator.MoveNext()) { DataSerie serie = enumerator.Current; ... }
That worked! Thanks Martin. As for the "for" statement how would it work? I'm checking the documentation and the syntax in x is "for ( initialization ; test ; increment ) { statement }" but I don't know how would it apply if I have it in c# as:
for (BanxicoDll.DataSerie dataSerie : serie.Data) { if (dataSerie.Data == "N/E") continue; info(strFmt("Fecha: %1", dataSerie.Date)); info(strFmt("Dato: %1", dataSerie.Data)); }
Throw away all those 'using' statements that you don't need, especially 'using System'. This is causing a name conflict; the compiler doesn't know whether Exception means the F&O enum or System.Exception class.
Hi André, I'm checking this enum "Exception" in the AOT and it appears under System Documentation - Base Enums - Exception. But it won't show to which model it belongs as it does for the other base enums under Data Types:
Also, the exact error is not highlighting the line with catch. Is highlighting every line that starts with info. Thanks in advance.
Hi Daniel,
I guess the exact error is highlighting the line with catch (Exception::CLRError)? In that case, check which model references you have set for your custom model. The model containing the Exception enumeration might not be referenced yet.
André Arnaud de Cal...
292,160
Super User 2025 Season 1
Martin Dráb
230,962
Most Valuable Professional
nmaenpaa
101,156