Click here to Skip to main content
15,867,305 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello. I have a job to do. It consists in loading the file in C # (I have 3 datasets), changing symbols, for example, a, b, c to numbers from 1 to 3. Find the smallest and largest value in the columns. I have to load the file into windows form (I have to do gui). Reading in by pressing the button.

What I have tried:

I sit on it for 3 days and I haven't come up with anything. I just have something like this. I know how to check the maximum value for only one column. I don't know how to convert symbols to numbers. In another file there are a, b, c etc. And the size of the cells differs. I don't know how to do it automatically either.

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Data.OleDb;
using System.Text.RegularExpressions;

namespace testtabele
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            
            InitializeComponent();

        }

        DataTable table = new DataTable();

        private void Form1_Load(object sender, EventArgs e)
        {

            table.Columns.Add("A1", typeof(string));
            table.Columns.Add("A2", typeof(string));
            table.Columns.Add("A3", typeof(string));
            table.Columns.Add("A4", typeof(string));
            table.Columns.Add("A5", typeof(string));
            table.Columns.Add("A6", typeof(string));
            table.Columns.Add("A7", typeof(string));
            table.Columns.Add("A8", typeof(string));
            table.Columns.Add("A9", typeof(string));
            table.Columns.Add("A10", typeof(string));
            table.Columns.Add("A11", typeof(string));
            table.Columns.Add("A12", typeof(string));
            table.Columns.Add("A13", typeof(string));
            table.Columns.Add("A14", typeof(string));
            table.Columns.Add("A15", typeof(string));
            table.Columns.Add("A16", typeof(string));
            table.Columns.Add("A17", typeof(string));           
            dataGridView1.AutoGenerateColumns = true;
            

            dataGridView1.DataSource = table;




        }
        private void button1_Click(object sender, EventArgs e)
        {
            string[] lines = File.ReadAllLines(@"C:\australian.dat");
            string[] values;

            

            for (int i = 0; i < lines.Length; i++)
            {
                values = lines[i].ToString().Split(' ', ',');

                
                string[] row = new string[values.Length];

                for (int j = 0; j < values.Length; j++)
                {
                    
                    row[j] = values[j].Trim();

                }
                
                table.Rows.Add(row);
            }

            double max = 0;
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                if (max < double.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString().Replace(".", ",")))
                {
                    max = double.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString().Replace(".", ","));
                    textBox1.Text = max.ToString();
                }


            }
            double min = 0;
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                if (i == 0)
                {
                    min = double.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString().Replace(".", ","));
                }
                if (min > double.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString().Replace(".", ",")))
                {
                    min = double.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString().Replace(".", ","));
                }
            }

            textBox2.Text = min.ToString();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            
        }
        

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            
        }
    }
}
Posted
Updated 12-Mar-21 7:14am
v4
Comments
Richard Deeming 12-Mar-21 12:59pm    
Well, keep thinking. Nobody here is going to do your job for you, even if you had provided a workable specification.
Member 15098633 12-Mar-21 13:09pm    
I send, what i had.
NotTodayYo 12-Mar-21 13:08pm    
What did you want from us?
Member 15098633 12-Mar-21 13:10pm    
I writted in question. I know how to check the maximum value for only one column. I don't know how to convert symbols to numbers. In another file there are a, b, c etc. And the size of the cells differs. I don't know how to do it automatically either
NotTodayYo 12-Mar-21 13:34pm    
Nobody here knows how to convert symbols to numbers either because we have no idea what that means. What symbols? And how does one know what number a certain symbol represents?

If dog is a symbol, what number should that be?

In other words, we have no idea what you are talking about so we can't help at all.

Quote:
I sit on it for 3 days and I haven't come up with anything.

Solutions are:
- Think about hiring a professional programmer.
- Have a talk with your teacher.
- Learn C# and windows forms.

[Note to anonymous downvoters of 2021/04/14]
This "non solution" was written against first version of question.
the whole "What I have tried:" was the little quote up there, no detail, no code.
 
Share this answer
 
v2
Comments
BillWoodruff 12-Mar-21 18:42pm    
My vote of #1: This is not a solution; it's a comment with an explicit "go away" message.
Ralf Meier 13-Mar-21 7:01am    
@Bill:
I have to break a stick for Patrice. This is an often given answer (as well as Solution) to questions like this. I you make a downvote here you must make this by each and every question which gets an "Solution" like this.
Of course - you are right - it's not a Solution, the Solution (in my opinion) could one if the OP gives much more Information about his problem. I also stuck at the point "conversion Symblos to Numbers" ...
BillWoodruff 13-Mar-21 9:52am    
Hi Ralf, I take my responsibilities as a CP Mentor seriously, and, I really hesitate to down-vote ... if I can see a shred of relevance to the technical content of the OP's post, usually I don't vote.

Any solution that insults, discourages, the OP gets down-voted and/or reported.

imho, OriginalGriff has earned the right to make frequent advisory comments posted as solutions by his almost unique contributions to CP and QA over so many years: his imitators who post inferior me-too stuff (to pad their reps ?) have earned nothing.

Because "lots of people do it" doesn't make it "right."

At age 77.5, near blind in one eye, increasingly limited vision in the other, leaky heart valve, etc., I don't have time to read/respond to many posts :)
Ralf Meier 13-Mar-21 10:14am    
Hi Bill,
I agree with you ... and I doesn't meant OriginalGriff as reference - I'm definately in the position to see there a difference ... :-)
I think you have also read the rest of my comment - I also try to be serious too ...
BillWoodruff 13-Mar-21 10:46am    
Hi Ralf, I respond at length only to people I take seriously :) fwiw: I respect you and Patrice. You have every right to question my behavior and intent: the truth I face liberates me; the truth I hide from destroys me :)

The "ideal" QA solution could be every mentor and mvp taking a major role in managing QA ? Oh, I forgot ... this is not an ideal world :)
This forum is for asking specific questions, not asking someone to do all your work for you.

If you get stuck on something specific please ask.
 
Share this answer
 
Comments
BillWoodruff 12-Mar-21 18:44pm    
My vote of #1: This is not a solution; it's a comment, and repeats the comments you've already made.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900