Discuss about Programming here. You may release your source, post guide and even ask questions!
Moderator: wizme
Nerrazzuri
Destiny General
Posts: 1110 Joined: Sun Dec 20, 2009 9:15 pm
Post
by Nerrazzuri » Sun Jun 27, 2010 11:11 am
Need some help on my NRZBot v2.1
I'm able to copy the texts on every textbox to a .txt file using StreamWriter class but hell I can't retrieve it back to the textbox from the .txt file.
here is the code i use to write to the .txt file
Code: Select all
String^Skill1 = textBox2->Text;
String^Skill2 = textBox3->Text;
String^Skill3 = textBox4->Text;
String^Charge1 = textBox5->Text;
String^Charge2 = textBox6->Text;
String^Charge3 = textBox7->Text;
String^ValueHP = textBox1->Text;
String^ValueMP = textBox8->Text;
StreamWriter^ sWriter = gcnew StreamWriter("c:\\BotSettings.txt");
sWriter->WriteLine(Skill1);
sWriter->WriteLine(Skill2);
sWriter->WriteLine(Skill3);
sWriter->WriteLine(Charge1);
sWriter->WriteLine(Charge2);
sWriter->WriteLine(Charge3);
sWriter->WriteLine(ValueHP);
sWriter->WriteLine(ValueMP);
sWriter->Close();
And I've tried to read through some examples on google but return no result. Wish someone who can help me on this.
zile
Apprantice Knight
Posts: 17 Joined: Sun May 30, 2010 4:46 pm
Post
by zile » Sun Jun 27, 2010 2:03 pm
I'm not using MFC, so im not sure if this can be used.
get the line of the file with
ifstream.h into a variable
then SetDlgItemText for that textbox,
then continue getting the next line
http://www.cplusplus.com/doc/tutorial/files/
hope it helps
Nerrazzuri
Destiny General
Posts: 1110 Joined: Sun Dec 20, 2009 9:15 pm
Post
by Nerrazzuri » Sun Jun 27, 2010 2:21 pm
zile wrote: I'm not using MFC, so im not sure if this can be used.
get the line of the file with
ifstream.h into a variable
then SetDlgItemText for that textbox,
then continue getting the next line
http://www.cplusplus.com/doc/tutorial/files/
hope it helps
I'm not using MFC either, I'm using Windows Form C++/CLI class, so SetDlgItemText doesn't work for me.
NoobHacker
Headmaster of Darkness
Posts: 576 Joined: Tue Dec 29, 2009 12:31 pm
Post
by NoobHacker » Sun Jun 27, 2010 2:31 pm
Nerrazzuri wrote: Need some help on my NRZBot v2.1
I'm able to copy the texts on every textbox to a .txt file using StreamWriter class but hell I can't retrieve it back to the textbox from the .txt file.
here is the code i use to write to the .txt file
Code: Select all
String^Skill1 = textBox2->Text;
String^Skill2 = textBox3->Text;
String^Skill3 = textBox4->Text;
String^Charge1 = textBox5->Text;
String^Charge2 = textBox6->Text;
String^Charge3 = textBox7->Text;
String^ValueHP = textBox1->Text;
String^ValueMP = textBox8->Text;
StreamWriter^ sWriter = gcnew StreamWriter("c:\\BotSettings.txt");
sWriter->WriteLine(Skill1);
sWriter->WriteLine(Skill2);
sWriter->WriteLine(Skill3);
sWriter->WriteLine(Charge1);
sWriter->WriteLine(Charge2);
sWriter->WriteLine(Charge3);
sWriter->WriteLine(ValueHP);
sWriter->WriteLine(ValueMP);
sWriter->Close();
And I've tried to read through some examples on google but return no result. Wish someone who can help me on this.
for me i will use array
Code: Select all
string^writedata = textBox2->text +";" + textBox3->text + ";" + textBox4->text + ";" + textBox5->text + ";" + textBox6->Text + ";" + textBox7->Text + ";" + textbox1->text + ";" + textBox8->text;
StreamWriter SR = gcnew StreamWriter("C:\\settings.txt");
SR->Write(writedata);
SR->dispose();
for reading,use this
Code: Select all
Streamreader^SR = gcnew StreamReader("C:\\Settings.txt");
string[]^readdata = SR->Readtoend->Split(";");
textBox2->text = string[0]->tostring();
textBox3->Text = string[1]->ToString();
//blablabla
NOte:you can use \n to spllit the data u wrote using streamwriter
Alot
ers in xemectrum!
Nerrazzuri
Destiny General
Posts: 1110 Joined: Sun Dec 20, 2009 9:15 pm
Post
by Nerrazzuri » Sun Jun 27, 2010 3:50 pm
Instead of using your codes, this is mine.
Code: Select all
String^ delimiter = ";";
String^ fileName = "c:\\Settings.txt";
StreamReader^ sr = gcnew StreamReader(fileName);
try
{
while (sr->Peek() >= 0)
{
String^ r = sr->ReadLine();
array<String^>^ items = r->Split(delimiter->ToCharArray());
}
}
finally
{
sr->Close();
}
Ok, got rid of that error. Still it doesn't re-write it back into my textBox. Clueless. >.<
NoobHacker
Headmaster of Darkness
Posts: 576 Joined: Tue Dec 29, 2009 12:31 pm
Post
by NoobHacker » Sun Jun 27, 2010 9:29 pm
Nerrazzuri wrote: Instead of using your codes, this is mine.
Code: Select all
String^ delimiter = ";";
String^ fileName = "c:\\Settings.txt";
StreamReader^ sr = gcnew StreamReader(fileName);
try
{
while (sr->Peek() >= 0)
{
String^ r = sr->ReadLine();
array<String^>^ items = r->Split(delimiter->ToCharArray());
}
}
finally
{
sr->Close();
}
Ok, got rid of that error. Still it doesn't re-write it back into my textBox. Clueless. >.<
=/ can show me how you rewrite into your textbox?
Alot
ers in xemectrum!
Nerrazzuri
Destiny General
Posts: 1110 Joined: Sun Dec 20, 2009 9:15 pm
Post
by Nerrazzuri » Sun Jun 27, 2010 10:22 pm
NoobHacker wrote: Nerrazzuri wrote: Instead of using your codes, this is mine.
Code: Select all
String^ delimiter = ";";
String^ fileName = "c:\\Settings.txt";
StreamReader^ sr = gcnew StreamReader(fileName);
try
{
while (sr->Peek() >= 0)
{
String^ r = sr->ReadLine();
array<String^>^ items = r->Split(delimiter->ToCharArray());
}
}
finally
{
sr->Close();
}
Ok, got rid of that error. Still it doesn't re-write it back into my textBox. Clueless. >.<
=/ can show me how you rewrite into your textbox?
I can't, I have no idea how to write it back into the textbox from the text file. :S