Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear code project members,
I'm a very beginer in Visual C# and I would like you to help me with this problem, which is too simple for a high level community like you but very difficult for me.

The problem:
I have a text file which contains 14 columns and more than 3500 rows of integers. I need to read that file by the click of a button and then load the whole contents into a multi dimensional array. From this array 14 textboxes will be loaded. Then I need that content to change every 50ms. I'll use this application to create a socket over which I'll send the data to a robot controlling a its trajectory.

Best regards
Posted
Updated 29-May-11 11:58am
v2
Comments
Sergey Alexandrovich Kryukov 29-May-11 18:41pm    
There is not a question here. What seems to be a problem?
--SA

If you need info about creating, handling arrays: Array tutorial[^]
If you need info about general file reading stuff like ReadAllText ReadAllLines etc:System.IO.File[^]
If you arent happy with just File class: System.IO.TextReader[^]
If you want a general purpose timer:System.Timers.Timer[^]
There are alternatives to timer class like using threads and use thread.sleep to manage timing checkout System.Threading.Thread[^] also there are many articles and Q&A in CodeProject as well. For instance How to pass ref parameter to the thread[^].
Good luck.
 
Share this answer
 
Comments
Dzmoumou 29-May-11 18:15pm    
thanks
yesotaso 29-May-11 18:18pm    
No problem.
Monjurul Habib 29-May-11 18:35pm    
nice links, my 5.
yesotaso 29-May-11 20:31pm    
Thank you.
thatraja 29-May-11 21:49pm    
Good bunch, my 5!
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{

#region Private Variables

private const string _fileName = @"c:\1.txt";

private List<string> _lineItems = new List<string>();

private StreamReader _sr;

private string[,] _coords;

private Int32 _loopIndex = 0;

private Int32 _rowCount = 0;

#endregion

public Form1()
{
InitializeComponent();
}

private void btnLoadFile_Click(object sender, EventArgs e)
{
Cursor = Cursors.WaitCursor;

ReadFile();

MessageBox.Show("Done importing data !");

btnStart.Enabled = true;
btnLoadFile.Enabled = false;

Cursor = Cursors.Default;

}

private void ReadFile()
{
string _newLine = "";
_sr = new StreamReader(_fileName);

while (!_sr.EndOfStream)
{

_newLine = _sr.ReadLine();

if (_newLine.Length > 1)
{
_lineItems.Add(_newLine);
}
}

_coords = new string[_lineItems.Count, 14];

_rowCount = _lineItems.Count;

for (Int16 _i = 0; _i < _lineItems.Count; _i++)
{

if (_lineItems[_i].ToString().Trim().Length > 1)
Split(_i, _lineItems[_i]);
}

}

private void Split(Int16 _index, string _lineItem)
{
string[] _splitItems = _lineItem.Split(new char[1]{' '});

for (Int16 _i = 0; _i < 14; _i++)
{
_coords[_index, _i] = _splitItems[_i];
}


}

private void btnStart_Click(object sender, EventArgs e)
{
tmrLoop.Enabled = true;
}

private void tmrLoop_Tick(object sender, EventArgs e)
{
LoopData();
}

private void LoopData()
{

textBox1.Text = _coords[_loopIndex, 0];
textBox2.Text = _coords[_loopIndex, 1];
textBox3.Text = _coords[_loopIndex, 2];
textBox4.Text = _coords[_loopIndex, 3];
textBox5.Text = _coords[_loopIndex, 4];
textBox6.Text = _coords[_loopIndex, 5];
textBox7.Text = _coords[_loopIndex, 6];
textBox8.Text = _coords[_loopIndex, 7];
textBox9.Text = _coords[_loopIndex, 8];
textBox10.Text = _coords[_loopIndex, 9];
textBox11.Text = _coords[_loopIndex, 10];
textBox12.Text = _coords[_loopIndex, 11];
textBox13.Text = _coords[_loopIndex, 12];
textBox14.Text = _coords[_loopIndex, 13];

if (_loopIndex == _rowCount -1)
{
_loopIndex = 0;
}
else
{
_loopIndex++;
}

}

}
}
 
Share this answer
 

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