Results 1 to 3 of 3

Thread: OutOfRangeExceptionHandler error while debugging

  1. #1
    raffs03 is offline C# Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Jan 2012
    Rep Power

    Lightbulb OutOfRangeExceptionHandler error while debugging

    Hello everyone i need some help regarding to my problem.

    I'm making a weatherforecast apllication(REST method in C# language)
    i write the code and it shows no error or warnings.
    but when i run the debugger it show an error(See pics)
    PS: im using Visual basic 2010 professional edition.

    This is the codes that i write.

    using System.Xml.Linq;
    using System.Net;

    namespace RESTService
    public partial class Form1 : Form
    public Form1()

    // Obtain the Foracast.

    // Display the Forecast data.
    // Holds all of the weather data
    XDocument GetData;

    // Contains just the forecast.
    IEnumerable<XElement> Forecast;

    //Specifies which Forecast to use.
    Int32 ForecastNumber;

    // Defines the maximum number of farecast.
    Int32 MaxForecasts;

    // Contains a list of icons associated with the forecast.
    IEnumerable<XElement> Icons;

    // Specifies which icon to use.
    Int32 IconNumber;

    public void GetForecast()
    // Contains the result of a retry request.
    DialogResult TryAgain = DialogResult.Yes;

    // Keep trying to get the weather data until the user
    // Gives up or the call is successful.
    while (TryAgain == DialogResult.Yes)
    // Get the weather data.
    GetData =
    + "/ForecastXML/index.xml?query="
    + txtLocation.Text);

    // End the loop
    TryAgain = DialogResult.No;
    catch (WebException)
    TryAgain = MessageBox.Show(
    "Couldn't obtain the weather data! \r\n Try again?",
    "Data Download Error",

    // Obtain all the forecasts.
    Forecast =

    // Define the maximum number of forecasts.
    MaxForecasts = Forecast.Count() - 1;

    // Specify which forecast to use.
    ForecastNumber = 1;

    // Specify which icon to use.
    IconNumber = 1;

    // Reset the buttons.
    btnNext.Enabled = true;
    btnPrevious.Enabled = false;

    public void DisplayData(Int32 FNumber)
    // Display the title of the current forecast.
    txtTitle.Text = Forecast.ElementAt(FNumber).Element("title").Value;

    // Display detailed forecast information.
    txtForecast.Text = Forecast.ElementAt(FNumber).Element("fctext").Value;

    // Obtain a list of icons associated with the forecast.
    Icons = Forecast.ElementAt(FNumber).Element("icons").Elements("icon_set");

    // Define the maximum numbers of available icons.
    IconSelect.Maximum = Icons.Count() - 1;

    // Display the icon on screen.
    wbIcon.Url = new Uri(Icons.ElementAt(IconNumber).Element("Icon_url").Value);

    Can somebody correct what error i made? Because i try fixing it almost an hour but i can't see my error
    i tried changing the value of "Fnumber" but the error is still there.
    PS: I hope this is the right place to post this topic.
    Last edited by JohnH; 01-18-2012 at 6:16 AM. Reason: code box

  2. #2
    JohnH's Avatar
    JohnH is offline C# Forum Moderator
    .NET Framework
    .NET 4.5
    Join Date
    Apr 2011
    Rep Power
    txtTitle.Text = Forecast.ElementAt(FNumber).Element("title").Value ;
    According to exception there is not an element at index FNumber.

  3. #3
    raffs03 is offline C# Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Jan 2012
    Rep Power
    Thanks for the heads up. I change the FNumber to ForecastNumber and it works! thnx m8.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts