|
I am a new student in C# using .NET framework. I am trrying to solve the following problem:
Calculate the value of pi from an infinite series, pi = 4 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11...
Print a table that shows the value of pi approximated by computing one term of this series, by two terms, by three terms, etc. How many terms of this series do you have to use before you first get 3.14? 3.141? 3.145? 3.1459?
I understand there is a pattern with the numerator (increment by 2), and you have to add or subtract the values (i.e., odd value, add; even value, subtract), and you increment the number of terms to find pi. I also know that you need a if...else statement to get the loop going. Other than that, I am lost...PLEASE HELP!!! Thanks...
|
|
|
|
|
> How many terms of this series do you have to use before you first get 3.14? 3.141? 3.145? 3.1459?
That's easy. The answer is no number of terms will give you these exact values!
You need to tell the teacher that one of the most important parts of numerical analysis is specifying your desired precision. You should really be asking something like "how many terms does it take to get a value between 3.19999 and 3.14001?" or something along those lines. Otherwise this question is intractable.
Other than that, I'm sorry, but if you can't write this code, you need to change your area of study.
Please, search the internet for "How to Ask Questions the Smart Way"[^]
You should write the code yourself and post what you've written with any specific questions or problems you have.
|
|
|
|
|
I have a little asynch. socket listener that notifies me when data is read. inside of the OnRead callback event it seems that my notifications were overlaping (future notifications triggered before past notifications 1.2.3.4.5. becomes 1.2.5.3.4.). The code goes like this:
private void OnReadComplete( IAsyncResult ar )
{
... copy the m_byBuffer data into byOut ...
... do some work ...
lock(m_ReadLockObject) <-- should block the next read attempt.
{
if (m_netStream.CanRead && (m_Socket.Connected || m_netStream.DataAvailable))
m_netStream.BeginRead(m_byBuffer, 0, m_byBuffer.Length, m_callbackRead, null);
if (bytesRead > 0)
ExecOnDataRead(this, new CClientInfoEventArgs(m_EndPoint, byOut));
}
...
}
The data keeps comming in all jumbled up. Now I can patch this by putting in a sufficiently large delay, like a trace before and after I call ExecOnDataRead to check the current thread ID, OR I can re-arrange the ExecOnDataRead before the BeginRead. The thing is that I know ExecOnDataRead can be quite expensive and I do perform some work before I pass the data on, so I want the next BeginRead to be running while I'm doing that.
Note that a simple trace or debug seems to straighten out the data (obviously time sensitive) so I can't observe what is happening except through the end results. Even putting in a second lock inside ExecOnDataRead, or a static mutex.WaitOne() does not seem to straighten out the data, but as soon as I put in a Trace to print out the thread ID's that are running the ExecOnDataRead to see if they are overlapping, everything straightens out!! Ahrrgg! It's almost like the lock is not locking.
Thanks in advance
Assert(this);
|
|
|
|
|
hi all can any body help me
I'm in my way to start in my graduation project which is a GIS tracking system using a C# programming language to operate with the GIS can any body help me in finding tutorials in this topic
thank you very much
|
|
|
|
|
I have a toolstrip defined with a single toolstriplabel defined. When a user initiates an action, I would like to display the status of what I'm doing while they wait. Seems obvious. The problem is, the information is never displayed. To be more speicific, have a form with one button and a tool strip. Click the button. The click routine then goes a reads a bunch of files. As each file is read, I update the toolstriplabel.text with the file name. However, in my application, the text does not show until the very last file.
What do I need to do?
|
|
|
|
|
You have to call DoEvents to give the label the opportunity to recieve the change message.
---
b { font-weight: normal; }
|
|
|
|
|
I guess I'm feeling a little slow on this one. What do you mean "DoEvents?" Some code is below so that you know exactly what I'm doing.
Thanks so much.
I've got the status strip defined as follows:
this.ssHistoryStatusStrip = new System.Windows.Forms.StatusStrip();
this.sslHistory = new System.Windows.Forms.ToolStripStatusLabel();
// ssHistoryStatusStrip
//
this.ssHistoryStatusStrip.Items.AddRange(new
System.Windows.Forms.ToolStripItem[] {this.sslHistory});
this.ssHistoryStatusStrip.RenderMode =
System.Windows.Forms.ToolStripRenderMode.ManagerRenderMode;
this.ssHistoryStatusStrip.Size = new System.Drawing.Size(691, 22);
this.ssHistoryStatusStrip.TabIndex = 5;
this.ssHistoryStatusStrip.Text = "statusStrip1";
//
I set the text through a function call like this:
private void SetHistoryStatus(string newHistoryStatus)
{
sslHistory.Text = newHistoryStatus;
}
|
|
|
|
|
Hello,
I think this is what Guffa meant.
private void SetHistoryStatus(string newHistoryStatus)
{
sslHistory.Text = newHistoryStatus;
Application.DoEvents();
}
All the best,
Martin
|
|
|
|
|
Aha! This does work. Now I must go search out what this actually is doing. Thanks much for your help!
c
|
|
|
|
|
Hi all. I am developing application using vs2005 and mysql5.0. The problem is I want to store date as dd/mm/yyyy which mysql doesn't allow me to store. Please suggest a way how to do that? I will be very thankful to you.
|
|
|
|
|
fahiemulleh wrote: mysql doesn't allow me to store
Databases store dates in binary form. What you refer to is the output or display or "formatting" of the date after you obtain the date information from the database.
led mike
|
|
|
|
|
so Please tell me How to format date (for display) as dd/mm/yyyy.
|
|
|
|
|
fahiemulleh wrote: so Please tell me How to format date
They hide that information in the documentation[^]
led mike
|
|
|
|
|
I think you are confusing the display format and the storage format. Most databases store datetime as a numeric value, tipically milliseconds since some starting date/time. How that date gets formatted for display is up to your UI code. if your locale settings are not appropriate for the dd/mm/yyyy display format, it likely can't reliably covert that string to a datetime. Since you are using ADO.Net, you should just use a parameterized insert/update query, and provide the date as a DateTime value, rather than a string. If you want to accept that format from your UI , just specify an appropriate IFormatProvider and DateTimeStyle to the DateTime.Parse method.
|
|
|
|
|
I have created MDI Form. Now inside the Child Form i have button and when the button is clicked i want to display another form and hide the current one.
How can i do this ???
|
|
|
|
|
Errm - create the new form and show it, then set the .Visible to false on the current one?
Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world."
Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that."
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
hi
u need to write this code in Button click event.
this.Close();
requiredForm.Show();
regards,
Rahi
|
|
|
|
|
I have done this but still no result. I am currently in index.cs file and want to access StudentArea.cs. Beside Student_Area button code in index.cs file i have wrote the code according to your method and get the following error.
"C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\online_exam_csharp\index.cs(119): An object reference is required for the nonstatic field, method, or property 'System.Windows.Forms.Control.Show()'
"
|
|
|
|
|
hi,
can u send me the exercise what exactly do u want to code?
is it correct: just u have 2 forms page1 and page2
u have one button on page1. when u click on button, the control should move to page2 and page1 should be unloaded.
if not, please try to send me the problem, so that i can write the code and send it to u.
Regards,
Rahi
|
|
|
|
|
Hello Ashraf,
Suppose you have 1 MDI Parent form which is "MAIN" and two mdi child forms which are "child1" and "child2"
In form child1 there is a button for opening child2 form and close child1 form, try this code
child2 objchild2=new child2();
this.hide();
objchild2.show();
|
|
|
|
|
hi,
You can do this by just overriding the constructor of the form that you want to open the last. In overriding the constructor put in it as an argument an instance of type first form (the one that contains the botton). For example, let us say that the last form to open is lastForm and the first one is firstForm.
You write the constructor of lastForm as follows:
public viod lastForm( firstForm first )<br />
{<br />
<br />
InitialyseComponent();<br />
first.dispose();<br />
}
and when calling the last form through the botton, you initialyze a new form and give it as an argument a reference to the current form:
private void button1_click( sender object, e )<br />
{<br />
lastForm last = new lastForm(this);<br />
last.show();<br />
<br />
}
hope it helps
Jamil Abou Khalil
|
|
|
|
|
you have to put following code behind the button against which you want to...
this.hide();
NewForm nw = new NewForm();
nw.ShowDialog();
nw.Activate();
nw.Close();
it is a well experienced code and u should not face any problems.hope your question is answered!
regards
ShaZ JazZ
|
|
|
|
|
I'll start my problem description off with some sample code which will probably do the best job at illustrating the problem.
using System;<br />
<br />
namespace TestCustomTypePropertySetValue<br />
{<br />
public class CustomThing<br />
{<br />
public CustomThing(string input)<br />
{<br />
m_input = input;<br />
}<br />
<br />
public string Input<br />
{<br />
get { return m_input; }<br />
}<br />
private string m_input;<br />
<br />
public override string ToString()<br />
{<br />
return this.Input;<br />
}<br />
<br />
public static implicit operator CustomThing(string input)<br />
{<br />
return new CustomThing(input);<br />
}<br />
<br />
public static implicit operator string(CustomThing thing)<br />
{<br />
return thing.ToString();<br />
}<br />
}<br />
<br />
public class ClassWithThing<br />
{<br />
public CustomThing Thing<br />
{<br />
get { return m_thing; }<br />
set { m_thing = value; }<br />
}<br />
private CustomThing m_thing = new CustomThing("default");<br />
}<br />
<br />
class Class1<br />
{<br />
[STAThread]<br />
static void Main(string[] args)<br />
{<br />
CustomThing thing = "test custom thing input";<br />
<br />
string input = thing;<br />
<br />
ClassWithThing cwt = new ClassWithThing();<br />
System.Reflection.PropertyInfo propInfo =<br />
cwt.GetType().GetProperty("Thing");<br />
<br />
propInfo.SetValue(cwt, "test input", null);<br />
}<br />
}<br />
}
The last line in my sample code (PropertyInfo.SetValue) throws the exception "Object type cannot be converted to target type." If you run the sample code, you might notice that the SetValue doesn't even call the implicit conversion from string to CustomThing.
I'm getting this exception in code where I don't know the type of the property that I'm calling SetValue() on, and I'd rather not have to hack in a check for my custom type. Does anyone have any ideas on how to do this?
|
|
|
|
|
Matt Casto wrote: If you run the sample code, you might notice that the SetValue doesn't even call the implicit conversion from string to CustomThing.
That's because SetValue uses Object type for the value.
Try adding an implicit conversion from Object to CustomThing.
- Xint0
|
|
|
|
|
Xint0 wrote: Try adding an implicit conversion from Object to CustomThing.
I already thought of that, but it doesn't even compile because you can't have a user-defined conversion to or from the base class, so object is definitely out for that.
|
|
|
|