0

How do i load a text file to a windows clr textbox?
and how do i save the lines of the textbox to a file?

2
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by Martje
0

How do i load a text file to a windows clr textbox?

Using a System::IO::StreamReader object and it's ReadToEnd() method. This will give you a String ^ to which you can set your textBox1.Text.

and how do i save the lines of the textbox to a file?

Use a System::IO;:StreamWriter object. It has methods Write() and WriteLine() that you can use just like the Console::Write() and WriteLine() See how far you get with that and post back if you need more information.

Edited by jonsca: n/a

0

The reading of the file went well but when i need to save the file i get a An unhandled exception of type 'System.IndexOutOfRangeException' occurred] My code looks like this :

StreamWriter^ outfile = gcnew StreamWriter("fffffff.ini");
		 textBox2->Lines[linesuckup.linenum]="[textline1]="+textBox1->Text;
		 outfile->Write(textBox2->Lines);
        outfile->Close();

I dont understand how i am getting this error and whats causing it, to my appearance everything seems fine and logical.

Edited by Martje: n/a

0

Something is wrong with your linesuckup.linenum value. Where is that coming from? Check it versus textBox2->Lines->Count .

0

[edit]Problem solved, thank you all who helped me.

Something is wrong with your linesuckup.linenum value. Where is that coming from? Check it versus textBox2->Lines->Count .

Yep you were right now that thats fixed i notice that i cant change my lines :S
this line of my code isn like this :

textBox4->Text=textBox3->Text;
textBox4->Lines[4]=textBox4->Lines[4]->Replace(textBox4->Lines[4],"succes");

The code looks ok to me but textbox4 line 4 doesnt change to "Succes".

Edited by Martje: n/a

0

I was having some deja vu as I believe I have helped you with this last issue before:
http://www.daniweb.com/forums/thread261339.html
Even though Lines is technically read/write it seems as if you have to write via setting it equal to a "gcnew'd" array.

Hahahaha, i knew someone solved that problem for me and when i took a second look in my old post's i saw the fix and edited my post :D

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.