TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Deep D
NA
1k
1.3k
How do I print data from .txt to textbox list?
Nov 19 2013 9:40 PM
I can't get the data to print from my .txt to my textbox? I really don't understand why. Here is what I have
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;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
const int ROWS = 5;
const int COLS = 5;
double[,] iArray = new double[ROWS, COLS];
string[] nArray = new string[5];
double[] finalGradesArray = new double[5];
const double TOTAL = 4;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
PopulateArrays();
Calculations();
//read Names.txt file
ReadFile();
}
private void ReadFile()
{
//read namesFile and show it on listbox
StreamReader namesFile;
int index = 0;
namesFile = File.OpenText("Names.txt");
while (!namesFile.EndOfStream)
{
//studentsNamesListBox.Items.Add(namesFile.ReadLine());
nArray[index] = namesFile.ReadLine();
studentsNamesListBox.Items.Add(nArray[index]);
index++;
}
namesFile.Close();
}
private void PopulateArrays()
{
StreamReader scoresFile; //to read the file
string line; //to hold a line from the file
string[] dArray; //to hold the value from text file
int i;
int j;
/* double[,] fArray = new double [5, 5];
double[,] total = new double[5, 5];
//to hold the iArray 2-D
double newArray;
*/
//open Scores.txt file
scoresFile = File.OpenText("Scores.txt");
//read the lines from the file
for (i = 0; i < iArray.GetLength(0); i++)
{
line = scoresFile.ReadLine(); //read a line from the file
dArray = line.Split(','); //split "," out of the strings
for (j = 0; j < 5; j++)
{
iArray[i, j] = double.Parse(dArray[j]); //= double.Parse(dArray[j]); //the new 1-D array will be [0] = 1.0 [1] = 0.8 [2] = 0.9... and so on ...
}
}
scoresFile.Close();
//call calculations method so the data from iArray is calculated
//double[] tempArray = Calculations(iArray);
}
private void Calculations()
{
int i;
int j;
double average = 0;
for (j = 0; j < 5; j++) //sum up the column only
{
for (i = 0; i < 5; i++)
{
if (i != j) //ignore student own evaluation
{
average += iArray[i, j]; //Like this!!
//max number is 1
//accumulate with values
}
}
average = (average / TOTAL); //divide by number of column excluding his own for average
finalGradesArray[j] = average; //store the average in the grade array
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
//when click calculate button evaluation average grade * project grade = averagegradetextlabel
double projectGrade;
double averageStudent;
int index;
projectGrade = double.Parse(projectGradeTextBox.Text);
if (studentsNamesListBox.SelectedIndex != -1)
{
index = studentsNamesListBox.SelectedIndex;
averageGradeStudentLabel.Text = (projectGrade * finalGradesArray[index]).ToString();
/*
for (index = 0; index < 5; index++)
{
averageStudent = projectGrade * finalGradesArray[index];
averageGradeStudentLabel.Text = averageStudent.ToString("p2");
}
*/
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void studentsNamesListBox_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
Reply
Answers (
0
)
get files from ftp to local
open a file from database to new tab