Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8977735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:26:25+00:00 2026-06-15T19:26:25+00:00

I am having trouble accessing the second item in the list and I cannot

  • 0

I am having trouble accessing the second item in the list and I cannot see why any help would be appreciated.

class Datapoints
    {
        List<Datapoint> datapoints;                                         //Creates a list of datapoints from Datapoint
        private string fileName;
        public string Filename { get { return fileName; } }

        public Datapoint GetDatapoint(int i)                                //Creates an instance of a Datapoint called GetDatapoint                        
        {
            if (i < datapoints.Count)
                return datapoints[i];
            else
                return null;
        }

        public Datapoints(string fName)                                     //Method that creates a new list of datapoints with the objects of Datapoint within it
        {
            this.fileName = fName;
            datapoints = new List<Datapoint>();
            TextReader tr = new StreamReader(fileName);
            string input;
            while ((input = tr.ReadLine()) != null)
            {
                string[] bits = input.Split(',');
                Datapoint a = new Datapoint(bits[0], bits[1], bits[2]);
                datapoints.Add(a);
            }
            tr.Close();

        }

Here is the form, what I am trying to make happen is to have the boxes show the three numbers in the file when pressing the next button.

private void InitTextBoxes()
        {
            if (myDatapoints.Count > 0)
            {
                Datapoint a = myDatapoints.getItem(0);
                textBoxLatitude.Text = a.Latitude;
                textBoxLongtitude.Text = a.Longtitude;
                textBoxElevation.Text = a.Elevation;
                buttonNext.Enabled = true;
                buttonPrevious.Enabled = true;
            }
            count = 0;
            textBoxLatitude.Enabled = false;
            textBoxLongtitude.Enabled = false;
            textBoxElevation.Enabled = false;
            buttonDone.Visible = false;
            buttonDone.Enabled = false;
            addingData = false;
            saved = true;
            openToolStripMenuItem.Enabled = false;
        }


        private void openToolStripMenuItem1_Click(object sender, EventArgs e)
        {

            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Csv Files (*.csv)|*.csv|Text files (*.txt)|*.txt|All files (*.*)|*.*";
            if (ofd.ShowDialog(this).Equals(DialogResult.OK))
            {
                myDatapoints = new Datapoints(ofd.FileName);
                this.Text = "Data Entry - " + ofd.SafeFileName;
                InitTextBoxes();
                if (myDatapoints.Count > 0)
                {
                    buttonNext.Enabled = true;
                    buttonPrevious.Enabled = true;
                    closeToolStripMenuItem.Enabled = true;
                    saveAsToolStripMenuItem.Enabled = true;
                }
            }

        }



        private void buttonNext_Click(object sender, EventArgs e)
        {


                count++;
                if (count == myDatapoints.Count)
                    count = 0;

            Datapoint a = myDatapoints.getItem(count);
            textBoxLatitude.Text = a.Latitude;
            textBoxLongtitude.Text = a.Longtitude;
            textBoxElevation.Text = a.Elevation;

            textBoxTest.Text = Convert.ToString(myDatapoints.Count);

        }

        private void buttonPrevious_Click(object sender, EventArgs e)
        {

        } 

Also, when I initiate the boxes, I cannot change the datapoints.GetItem to anything but (0) as if i do there is an error in the following line I believe this is the heart of the problem but I cannot see why. The error is

Object reference not set to an instance of an object.

Within the file I am using to test there are 9 numbers (1,2,3,4,5,6,7,8,9) so it ought to take the middle three when I select 1, bit it doesn’t!

 internal Datapoint getItem(int p)
        {
            if (p < datapoints.Count)
            {
                return datapoints[p];
            }
            else
                return null;
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:26:27+00:00Added an answer on June 15, 2026 at 7:26 pm

    in the datapoints constructor you are only storing the first three (if you file contains only one line)

    either change file format to only have 3 numbers per line
    ex:

    1,2,3

    4,5,6

    7,8,9

    or change logic to store all values from single line ex:

       while ((input = tr.ReadLine()) != null)
            {
                string[] bits = input.Split(',');
                if (bits.Length % 3 != 0)
                {
                   //error bad file 
                }
                else
                {
                   int count = bits.Length / 3;
                   int i = 0;
                   while (count > 0)
                   {
                       Datapoint a = new Datapoint(bits[i], bits[i+1], bits[i+2]);
                       datapoints.Add(a);
                       i += 3;
                       count--;
                   }
                 }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble accessing both the Class and the current element. How can
I'm having trouble accessing the value of a calculated field from a list which
For some reason I'm having trouble accessing the fopen() function from inside a class
I'm having trouble accessing some variables in my program. I have one class called
I'm having trouble accessing a parent's variable like the following: class Priveleges { protected
Having trouble accessing javascript code in a mixed html/js ajax response. jQuery ajax doc
I'm having trouble accessing my IIS 7.5 express site in FireFox but i can
I am having trouble accessing the data field. I receive the error: Databinding methods
I'm having trouble accessing the id , area and theme values in my ViewData.
CakePHP Newbie :) I am having trouble accessing another controller and passing that data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.