|
The Knowledge wrote: How to search a string in a paragraph
Use IndexOf or a regular expression.
|
|
|
|
|
I am new programer and for class I have to make a program that store employee data, writes them to a random access file (Employee.dat), be able to edit them, print reports, etc...
I am trying to write a line each time the user hits ADD on the enter employee form.
here is what I have
StreamWriter sw = null;
validation();
getInputValues(contact);
tring filename = "Employee.dat";
contact.MyFile = new FileStream(filename, FileMode.Append);
if (validation() == false)
{
contact.Close();
return;
}
else
{
{
try
{
sw = new StreamWriter(contact.FileName);
sw.WriteLine(contact.Serialize());
}
catch (Exception ex)
{
MessageBox.Show("eror saving contact" + contact.FileName + ex.Message);
}
finally
{
if (sw != null)
{
sw.Close();
}
}
lstContacts.Items.Add(contact.LastName + "\t" + contact.FirstName);
contact = null;
}
}
}
but it just writes over the previous employee (first line of the .dat file)
How do I make it so that it write on the next line.
Thanks for your help in advance
kyle
Kyle Maldonado
|
|
|
|
|
Hi
i think calling flush on the streamwriter should solve the problem.
just one more remark..
i would change this part here
StreamWriter sw = null;
validation();
getInputValues(contact);
string filename = "Employee.dat";
contact.MyFile = new FileStream(filename, FileMode.Append);
if (validation() == false)
{
contact.Close();
return;
}
else
{
{
to
StreamWriter sw = null;
if (!validation())
{
return;
}
getInputValues(contact);
string filename = "Employee.dat";
contact.MyFile = new FileStream(filename, FileMode.Append);
it's a bit shorter, prevents you from validating the input data twice and you don't have to open the file and then close again if the input data is invalid.
greets
m@u
|
|
|
|
|
Thanks but one question. What does flush do?
kyle
Kyle Maldonado
|
|
|
|
|
streamwriter and stream use a buffer. they don't write immediately to the file.
flush forces the stream(-writer) to write down the buffer.
alternatively you can set the autoflush flag of the streamwriter to true. the streamwriter writes the data then immediatly to the file without buffering it first.
|
|
|
|
|
its not letting me add the flush method
wont it just be StreamWrite.Flush() its not letting me add the flush part.
Kyle Maldonado
|
|
|
|
|
i'm not quite sure what you mean, but maybe my first post was a bit cofusing.
the Flush Method is an Instance-Method of Streamwriter, so StreamWriter.Flush will get you a compiler Error.
You must call Flush on your StreamWriter - Instance:
wr.Flush();
|
|
|
|
|
hi,
I Have one form(frmTicket) which the user got to choose a city from a combobox in it.
there is a button next to combo box which opens another from(frmSearchCity) that is searching For cities.
the second form(frmSearchCity) has a textbox and a datagridview which on textchange event of the textbox the datagrid updates.
what I want to do is that when I double click on one of cells , this form(frmSearchCity) get closed and the value which I clicked, be the selected text(city) of the comboBox in the firstform(frmTicket).
please help me
|
|
|
|
|
Create win app, name main form Sender, add another form - Reciever
and code:
namespace WindowsApplication1 {<br />
public partial class Sender : Form {<br />
Reciever reciever;<br />
public Sender() {<br />
InitializeComponent();<br />
<br />
reciever = new Reciever();<br />
reciever.Show();<br />
}<br />
<br />
private void button1_Click( object sender, EventArgs e ) {<br />
reciever.Controls["label1"].Text = textBox1.Text;<br />
}<br />
}<br />
}
|
|
|
|
|
Really thanks ,really helpful
thanks
|
|
|
|
|
Hi,
I'm writing a mobile application and I have to use over-sized fonts and buttons so the user can use the touch-screen with fingers rather than stylus. When an error occurs I display a standard MessageBox which works fine but the button to close it is tiny and is placed on the title bar of the MessageBox.
Is there any way of increasing the MessageBox font, or placing a large button on the MessageBox ?
Thanks
|
|
|
|
|
dubbele onzin wrote: Is there any way of increasing the MessageBox font, or placing a large button on the MessageBox?
I don't think so, but you could easily create your own form to display errors and call that instead of MessageBox.
Another trick I've seen used is not to bother with MessageBoxes at all and to have some kind of status pane/symbol/widget in your application to highlight errors.
"On one of my cards it said I had to find temperatures lower than -8. The numbers I uncovered were -6 and -7 so I thought I had won, and so did the woman in the shop. But when she scanned the card the machine said I hadn't.
"I phoned Camelot and they fobbed me off with some story that -6 is higher - not lower - than -8 but I'm not having it."
-Tina Farrell, a 23 year old thicky from Levenshulme, Manchester.
|
|
|
|
|
Hello,
I want to know how we can publish our website after it is finished in VSStudio2005. Can somebody help me.
Regards
|
|
|
|
|
GaneshKumarVkm wrote: I want to know how we can publish our website after it is finished in VSStudio2005.
Select the 'Publish' option from the 'Build' menu.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
I used WebBrowser to get an html Document, in which there was a "Submit" button. I can get this HtmlElement. How to emulate a click in a program?
Call the elem's Click is invalid, cause it's a delegate , it can only appear in the leftside of a + or +=.
Thanks.
|
|
|
|
|
Have you considered calling the method that handles the Click event?
I will use Google before asking dumb questions
|
|
|
|
|
It's an "event delegate", you cannot call it in your code. You can only use it at the left side of + or += operator.
You know, I download an html document, it's written by other people. In the page there was a button. I want to emulate a "click" of the button in my program.
I googled but no useful result.
|
|
|
|
|
is it possible to return a bool on the Dictionary.ContainsKey where the key is a regex pattern?
for example if i have a hashtable (or a dictionary) of regex patterns as keys, and i want to know if the string the user entered matches to the key, do i have to search key by key with a "foreach" or does any one know a solution for searching faster.
Thanks.
|
|
|
|
|
never.reply wrote: do i have to search key by key with a "foreach"
Yes
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Instead of wasting time on typing so much. You could have tried it with some regex example. That would have taken less time.
Anyways it is possible
Nana
|
|
|
|
|
"Anyways it is possible"
How is that possible
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add(@"^L(\w{1})$", "0");
Why does dic.ContainsKey("LA") return false when it matches regex?
|
|
|
|
|
First thing I think the interpretation is wrong.
You are not using a Regex as a key of the dictionary.
Its a string object.
Then how can you search the contains key on regex?
Nana
|
|
|
|
|
You have to iterate over the dictionary I'm afraid. You are trying to shoehorn functionality into an item that is only a key, and has no purpose other than to identify a particular item in the collection for quick retrieval.
|
|
|
|
|
The biggest problem with that is that the value passed in may match more than one key's pattern even though the patterns are unique. You'll need to decide what to do in those cases. Iteration will be required.
|
|
|
|
|
hi guys
what is this operator " {0} "?
such as:
Console.WriteLine("Property Value: {0}", ///);
saeed ghanavat
|
|
|
|