Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple C# problem 1

Status
Not open for further replies.

airprox

Programmer
Dec 2, 2006
12
GB
Hi folks,

I've just started teaching myself C#, I actually design freeware scenery for Flight Sim and needed an application to do a particular task... can't be that hard! Well, I've finally gotten to the stage where I have actually got an application doing what I want it to do... kinda! It's only part finished, but basically it's a form with various textboxes and comboboxes which are read and transfered to a text file in a certain format with extra text in between. I'm using a lot of strings!

The problem is that when I hit the button to write the text file, everything works as it should except that the textboxes and comboboxes then clear... I'd like them to stay with the present content even though I've completed the task. Some of the data I'll be inputting will be the same for different files, so keeping the fields filled will save time... I'll post the code, I wonder if someone will be able to suggest what I need to add to the end to keep the data in the fields. Many Thanks in advance, Alun.

I've only copied the main bit, if you need it all just ask... and I realise it's very basic, but it's my first application!

string myRegion = comboBox1.Text;
comboBox1.Text = "";
string myCountry = comboBox2.Text;
comboBox2.Text = "";
string myState = comboBox3.Text;
comboBox3.Text = "";
string myCity = comboBox4.Text;
comboBox4.Text = "";

string myName = textBox4.Text;
textBox4.Text = "";
string myIcao = textBox5.Text;
textBox5.Text = "";
string MyMagvar = textBox6.Text;
textBox6.Text = "";



string string1 = "c:\\";
string string2 = "_AFDX.xml";
string myLinea = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n"
+ "<FSData\r\n"
+ "version=\"9.0\"\r\n"
+ "xmlns:xsi=' + "xsi:noNamespaceSchemaLocation=\"bglcomp.xsd\" >\"\r\n"
+ "<Airport\r\n"
+ "region=\"";
string myLineb = "\"\r\n"
+ "country=\"";
string myLinec = "\"\r\n"
+ "state=\"";
string myLined = "\"\r\n"
+ "city=\"";
string myLinee = "\"\r\n"
+ "name=\"";
string myLinef = "\"\r\n"
+ "lat=\"";
string myLineg = "\"\r\n"
+ "lon=\"";
string myLineh = "\"\r\n"
+ "alt=\"";
string myLinei = "\"\r\n"
+ "magvar=\"";
string myLinej = "\"\r\n"
+ "ident=\"";



// Write the string to a file.
System.IO.StreamWriter file = new System.IO.StreamWriter(string1
+ myIcao + string2);
file.WriteLine(myLinea + myRegion +myLineb + myCountry + myLinec
+ myState + myLined + myCity + myLinee + myName + myLinef );

file.Close();


}
}
}
 
string myRegion = comboBox1.Text;
comboBox1.Text = ""; //Remove these lines
string myCountry = comboBox2.Text;
comboBox2.Text = "";//Remove these lines
string myState = comboBox3.Text;
comboBox3.Text = "";//Remove these lines
string myCity = comboBox4.Text;
comboBox4.Text = "";//Remove these lines

string myName = textBox4.Text;
textBox4.Text = "";//Remove these lines
string myIcao = textBox5.Text;
textBox5.Text = "";//Remove these lines
string MyMagvar = textBox6.Text;
textBox6.Text = "";//Remove these lines
 
Excellent stuff... I shall give it a go when I get home from work.

Many Thanks!
Alun
 
Many thanks JurkMonkey... I've tested it and it does exactly what I was after.

Off to discover my next stupid question!
Cheers
Alun
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top