|
Nope. Also don't use bold text and don't expect too much help. We know who you are Subin Raju, and the level of abuse you hurled at Paul Marfleet when he tried to help you. Now, unlike you, I will be polite to people on these forums but not to a berk like you.
|
|
|
|
|
How to write a while loop?
oooo
|
|
|
|
|
As it is written in any other programming language.
rahul
modified on Thursday, April 3, 2008 7:30 AM
|
|
|
|
|
while()
{
}
Now, buy a beginners book on C#!
|
|
|
|
|
Hi,
bool I_need_programming_info=true;
while(I_need_programming_info) {
Book tutorial=BuyBook();
StudyBook(tutorial);
Book reference=BuyBook();
StudyBook(reference);
string guide=@<a href="http://www.codeproject.com/KB/tips/HowToUseGoogle.aspx">"http://www.codeproject.com/KB/tips/HowToUseGoogle.aspx"</a>;
BrowseAndRead(guide);
GoogleAround();
ReadDocumentation();
}
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
One of the best pieces of code I've seen in a while
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
I may be being a little pedantic, but wouldn't a do...while loop be better so he has to execute those instructions at least once?
Dave
|
|
|
|
|
Hi,
sure do ... while() can be useful, although I seldom use it, under most
circumstances I prefer for(; ; ) , often with one or more explicit exit tests.
However those may be topics for a more advanced thread, and since the OP asked for a while
loop explicitly I wanted to keep it as simple as possible. Besides, assuming some
perseverance, the given algorithm will teach him all the other loop constructs too.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
I've never used it actually.
I just thought
Book tutorial=BuyBook();
StudyBook(tutorial);
Book reference=BuyBook();
StudyBook(reference);
string guide=@"http://www.codeproject.com/KB/tips/HowToUseGoogle.aspx";
BrowseAndRead(guide);
GoogleAround();
ReadDocumentation(); should be executed at least once
Dave
|
|
|
|
|
Actually it needs to get executed forever, since people forget and technology evolves.
And my while loop takes care of that, the condition is always true.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Hi,
I have a little issue with some code I'm doing. Basically I have a source xml document that looks like this:
<Paragraph>This is a <Emphasis Type="Bold">test</Emphasis> line with these:<List><Entry>Keyword alpha</Entry><Entry>Keyword Bravo</Entry></List></Paragraph>
and the problem is this, if I wanted my code to tag a specific word for example replace the word alpha with
<Emphasis Type="Italic">alpha</Emphasis>
to create this new node:
<Paragraph>This is a <Emphasis Type="Bold">test</Emphasis> line with these:<List><Entry>Keyword <Emphasis Type="Italic">alpha</Emphasis></Entry><Entry>Keyword Bravo</Entry></List></Paragraph>
is there a way of identifying a specific point in the overall line to correctly replace it, given that the word alpha could conceivably appear before or after the instance to be tagged?
At the moment I am attempting to use a function that pulls the Paragraph Node to text (innertext) and clears out everything after the required word and then starts to create a new string builder by individually pulling innerxml of each node until the patterns match.
To me this is incredibly convoluted, is there a better way?
|
|
|
|
|
You could use richTextBox to view the text. Then you can use some of the controls of this richTextBox to get the current position or better the selected text and add your tag in the begginig of the selection and the close tag at the end of the selection, and save it.
|
|
|
|
|
Thanks for the reply I appreciate the information.
The text is already displayed in a RichTextBox object but without the tags, that is to say the user sees XmlNode.InnerText. Indeed the position of the selection is recorded and used but the problem is that if there are other tags in the root node, or the word is nested then I'm finding it impossible to relate the position from the plain text back to the correct position in the InnerXml
|
|
|
|
|
If you read an XML document into a big honkin' string you can simply use Replace()
Or Notepad --Added
Krippers wrote: To me this is incredibly convoluted, is there a better way?
I'm still trying to figure out what the question is...
Are you asking how to find the XmlElements in an XmlDocument that contain certain text?
Or how best to make the replacement once you've found one such XmlElement?
I wrote the following on the assumption that it is the latter...
Provided you loaded the document into an XmlDocument, you can enumerate the Entry elements to find the one(s) you want to affect.
I just noodled about and wrote:
System.Xml.XmlDocument doc = new System.Xml.XmlDocument() ;
System.Xml.XmlElement ele ;
doc.AppendChild ( ele = doc.CreateElement ( "Test" ) ) ;
ele.InnerText = "Keyword alpha" ;
string[] temp = ele.InnerText.Split ( new char[] { ' ' } , 2 ) ;
ele.RemoveAll() ;
ele.AppendChild ( doc.CreateTextNode ( temp [ 0 ] + " " ) ) ;
System.Xml.XmlElement nod ;
ele.AppendChild ( nod = doc.CreateElement ( "Emphasis" ) ) ;
nod.InnerText = temp [ 1 ] ;
The result:
<Test>Keyword <Emphasis>alpha</Emphasis></Test>
You didn't make the requirements very clear so I chose your simpler example.
You may need to use a Regular Expression to split the InnerText.
Or perhaps you could use XSLT to perform the change.
modified on Thursday, April 3, 2008 1:28 PM
|
|
|
|
|
Hi, and thanks very much for the reply I appreciate the effort. That all looks good and I can see it working but I'm probably going to have an issue with multiple instances of the required word in a nested tree. Let me show you what the situation could be:
Source Document:
<Manual>
<Chapter>
<Paragraph>In the beginning I had a car</Paragraph>
<Paragraph>It was a <Emphasis Type="Bold">fast</Emphasis> car</Paragraph>
<Paragraph>The dashboard had: <List><ListItem>Lights</ListItem><ListItem>Dials</ListItem><ListItem>Dashboard</ListItem></List> on the Dashboard</Paragraph>
<Paragraph>I like fast cars and I like their dashboards.</Paragraph>
</Chapter>
</Manual>
What the user actually sees is a richTextBox output of each Paragraph element.
User view:
<manual><br />
<chapter><br />
<paragraph>In the beginning I had a car</paragraph><br />
<paragraph>It was a <emphasis type="Bold">fast</emphasis> car</paragraph><br />
<paragraph>The dashboard had: <list><listitem>Lights</listitem><listitem>Dials</listitem><listitem>Dashboard</listitem></list> on the Dashboard</paragraph><br />
<paragraph>I like fast cars and I like their dashboards.</paragraph><br />
</chapter><br />
</manual>
If the user selected the third Dashboard on the third line then would that be an issue to the code you provided?
Many thanks for the help.
|
|
|
|
|
I thought we were talking about an XML document, what's with the RichTextBox?
Certainly a RichTextBox can take care of itself.
|
|
|
|
|
hi all can anyone help me in this regard..in my application iam using a drop down list and in the selected index changed event of that iam writing some code to make the controls visible false.this works fine when the page is loaded for the first time.when i select any value from the drop down next time this event is not executed.is the selected index changed event works only for the first time when the page loads??
here is the code..
ASPX page
<asp:Panel ID="pnlRegions" runat="server" Height="29px" Width="500px">
<asp:Label ID="lblregion" CssClass="lbl" Font-Bold="true" runat="server" Text="Region"></asp:Label>
<asp:DropDownList ID="ddlRegion" runat="server" Width="165px" OnSelectedIndexChanged="ddlRegion_SelectedIndexChanged"/>
<asp:Button ID="btnFind" runat="server" Text="Find Restaurant" OnClick="btnFind_Click"/> <br /><br />
</asp:Panel>
<asp:Panel ID="pnlDisplay" runat="server" >
<asp:Label id="lblTotalRest" runat="server" CssClass="NormalText" Text="Total Records" Width="186px" ></asp:Label>
<asp:Button id="btnDisplay" runat="server" CssClass="button" Text="Display" OnClick="btnDisplay_Click"></asp:Button>
</asp:Panel>
CODE BEHIND
protected void ddlRegion_SelectedIndexChanged(object sender, EventArgs e)
{
ClearClassData();
pnlDisplay.Visible = false;
}
protected void btnFind_Click(object sender, EventArgs e)
{
grdDescList.Visible = true;
pnlDisplay.Visible = true;
GetRestaurant("REGION");
ClearClassData();
}
the event get executed only after the find button click when i checked by putting breakpoints..
any help will be appreciated.
pintoo
|
|
|
|
|
has autopost back property of this control is set true or not.
rahul
|
|
|
|
|
yes rahul it was not set to true..
thanks for the valuable suggestion.
now it is working fine..
pintoo
|
|
|
|
|
I am creating application on C#.net vs2003.
Is there any method to reset the binding that had done previously.
txtBox.DataBinding.Add("Text", dt, "Cid");
similarly can we reset this binding?
I read about a method ResetBinding(),
But dont know how to use it?
Does it like txtBox.ResetBindings();
If yes, then why the code-editor is not showing the method in pop-up box,
which appears when we type Control. after . a box appears showing all methods related to control, In my vs its not showing ResetBindings() method, Why?
plz help.
modified on Thursday, April 3, 2008 7:02 AM
|
|
|
|
|
txtBox.DataBindings["Text"].Clear()?
So far I have not used the individual clear. I usually clear all the databinding [.DataBindings.Clear()] when i change the datasource.
|
|
|
|
|
darkelv wrote: I usually clear all the databinding [.DataBindings.Clear()] when i change the datasource.
Can u tell me how to use this?
DataBindings.Clear() will clear all the binding attach to the form controls, or what?
|
|
|
|
|
It clears the databindings of the control.
|
|
|
|
|
What the hell is wrong with this?
myStoredProcedure definition:
UPDATE Reminders SET lastModificationTime = [@lastModificationTime]
WHERE reminderId=[@reminderId];
lastModificationTime is set to Date/Time in my table
I just want to update the damn time from my code:
<code>
updateCommand.CommandText = "myStoredProcedure"
updateCommand.Parameters.AddWithValue("lastModificationTime", DateTime.Now);
updateCommand.Parameters.AddWithValue("reminderId", 1);
updateCommand.ExecuteNonQuery();
</code>
I get a "Data type mismatch in criteria expression" for the last modification time parameter
|
|
|
|
|
Think you might want to be putting an '@' before you sql parameters in the code.
Regards,
Rob Philpott.
|
|
|
|