Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...It's extraordinarily refreshing to see truly expert advice without having to wade through hipper than thou attitude..."

Geography

Where in the world do Tek-Tips members come from?
Motlatjo (Programmer)
19 Jul 12 7:36
Hi

i need to separate 1 text file into 100 records in each file, so my logic create those text file, but the data is not complete in each text file, 5 records are missing.

In this code, first i load all records into a listbox, then try to separate them in 100s

private void WriteToFile()
{
int RowCount = listBox1.Items.Count;
string FileName = "C:\\Users\\bbdnet0986\\Documents\\MyExpotedQADATA";
StreamWriter sw = new StreamWriter(FileName + ".txt");
int inc = 0;
int counter = 0;
//StreamWriter sw = new StreamWriter(FileName+inc + ".txt");
for (int i = 0; i < listBox1.Items.Count; i++)
{
sw.WriteLine(listBox1.Items[i].ToString());
string me = listBox1.Items[i].ToString();

if (RowCount > 100)
{

listBox2.Items.Add(listBox1.Items[counter].ToString());
counter++;
if (counter == 100)
{

inc++;
sw = new StreamWriter(FileName + inc + ".txt");

//counter = counter - 100;
RowCount = RowCount - counter;
counter = 0;
//FileName = FileName + inc + ".txt";
}
}

else
{
sw.WriteLine(listBox1.Items[i].ToString());
}

}
sw.Close();
}
phinoppix (Programmer)
23 Jul 12 12:00
homework? okay, try to code this pseudo:

CODE

function main()

  let sourceStream = open source file
  let filecounter = 1

  while sourceStream NOT eof
    call copyLines(sourceStream, filecounter)
    increment filecounter
  loop

end function


function copyLines(sourceStream, filecounter)
  let linecounter = 1
  let file = "file" + filecounter
  open newbuffer

  while sourceStream NOT eof and linecounter not 100
    let line = read sourceStream
    write to newbuffer
    increment linecounter
  loop

end function 
It's not a perfect pseudo but this should give you an idea.
wink

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close