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

  • SEARCH
  • Home
  • 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 8890767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:34:39+00:00 2026-06-14T22:34:39+00:00

Here is the code as it now stands, I will include all of the

  • 0

Here is the code as it now stands, I will include all of the code of the program as I left some bits out before. The bits I have changed due to your help I have emphasized with asterisks and ///
The first class is the standard one created from Windows Forms when directly editing your form.

namespace DistanceEstimatorFinal
{
    public partial class Form1 : Form
    {
        private bool saved;

        public Form1()
        {

            dataPoints mydataPoints = new dataPoints();
            InitializeComponent();
            dataPoint a = mydataPoints.getItem(0);
            latTextBox.Text = a.CurLatitude;
            longTextbox.Text = a.CurLongtitude;
            eleTextBox.Text = a.CurElevation;
            saved = true;

        }             

        private void latTextBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void openDataListToolStripMenuItem_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))
            {
                *var dp = new dataPoints (ofd.FileName);* /////

            }
        }       



        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (saved)
            {
                if (MessageBox.Show("Save?", "Data Not Saved", MessageBoxButtons.YesNo).Equals(DialogResult.Yes))
                {
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.ShowDialog();

                }

            }
        }

        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd1 = new SaveFileDialog();
            sfd1.Filter = "CSV files (*.csv)|*.csv|Text files ( *.txt)|*.txt |All files (*.*)|*.*";
            sfd1.ShowDialog();
        }

    }
}     

This class was designed to read in the data from a file, I am currently adapting it to read in a file from the open function.

namespace DistanceEstimatorFinal
{    
    public class dataPoints
    {              
        List<dataPoint> Points;
        string p;

        public dataPoints(string path)
        {
            p = path;
            Points = new List<dataPoint>();

            StreamReader tr = new StreamReader(p);

            string input;
            while ((input = tr.ReadLine()) != null)
            {
                string[] bits = input.Split(',');
                dataPoint a = new dataPoint(bits[0],bits[1],bits[2]);              
                Points.Add(a);  


            }

            tr.Close();
        }





        internal dataPoint getItem(int p)
        {
            if (p < Points.Count)
            {
                return Points[p];
            }
            else
                return null;
        }
    }

}

This file held the three variables Distance, latitude and Longtitude.

namespace DistanceEstimatorFinal
{
    class dataPoint
    {
        private string latitude;
        private string longtitude;
        private string elevation;

        public dataPoint()                               //Overloaded incase no value available
        {
            latitude = "No Latitude Specified";
            longtitude = "No Longtitude Specified";
            elevation = "No Elevation Specified";

        }

        public dataPoint(string Latitude, string Longtitude, string Elevation)
        {

            // TODO: Complete member initialization
            this.latitude = Latitude;
            this.longtitude = Longtitude;
            this.elevation = Elevation;

        }

        public string CurLongtitude { get { return this.longtitude; } }
        public string CurLatitude { get { return this.latitude; } }
        public string CurElevation { get { return this.elevation; } }

    }
  • 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-14T22:34:40+00:00Added an answer on June 14, 2026 at 10:34 pm

    Your pathFile is a method local variable, so it’s inacccesible anywhere except the body of that method (here openDataListToolStripMenuItem_Click).

    You could add a parameter to your dataPoints constructor to pass that value to the class:

    public class dataPoints
    {
        List<dataPoint> Points;
        public dataPoints(string path)
        {
            Points = new List<dataPoint>();
            //here `path` from constructor arguments
            TextReader tr = new StreamReader(path); 
            //...rest part of your code
        }
    

    Besides you’ll have to pass the value to this constructor. You didn’t show the code, you have to create dataPoints instanses.

    var dp = new dataPoints(pathFile);
    

    But remember, pathFile is accessible only in openDataListToolStripMenuItem_Click. So you should either create the dataPoints right there, or make your pathFile a field of a form for it to be accessible in any method of that form. Then you’d get an opportunity to access pathFile in any method of this form.


    According to your previous post, this should look like:

    private void openDataListToolStripMenuItem_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))
        {            
            //actually you don't even need to have a separate `pathFile` variable
            //just pass the value from the dialog straight to your `dataPoints` object
            var dp = new dataPoints(ofd.FileName);
            //...rest of your code
        }
    }
    

    P.S.: off-topic, but, please, consider reading MSDN Guidelines for Names

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this div in my code: <div id=advice class=validation-advice style=>some text here</div> Now,
Some time ago, people here helped me very well with code. Now I'm tasked
Here is my code: partial void OnisApprovedChanging(bool value) { this.dateApproved = DateTime.Now; } 'dateApproved'
I used the code described here but now, when I do a for ...
Here my code, I need to insert into mysql database I have mysql,php,android 1)
I have found some code online for red black trees, and am trying to
As it stands right now, I have a literal control on my page. In
Here is my code : #include <stdio.h> #include glut.h float width = 800.0; float
The script is on jsfiddle here : CODE What it does at the moment
Ok the error is showing up somewhere in this here code if($error==false) { $query

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.