|
KiTsuNeKo wrote: Never wait for a chance to come, Believe in your own potential and go get it!
You can use Reflector[^] to investigate MSIL code...
|
|
|
|
|
I want to multiply 2 XML nodes and want to append the result in another XML node in C#.What will be the code.If there is already exist one XML file there.I want to do the coding in a Class File.
|
|
|
|
|
Select the nodes, grab the values, multiply them and stuff the result in.
What specific part are you stuck on ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
This is the code:
This code is actually calculating one specific node with a user defined rate value.But this code I made for one sample windows application.
But now I need only one class file where no user defined rate is there.
rate is also available in the XML file.
And these code is for one specific node.I need to do the calculations for each and every nodes where Attribute is mention as coverage.
public void CalculateCommissionAmount(string policyXML, string rate)
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(policyXML);
XmlElement root = xmldoc.DocumentElement;
if (Convert.ToDouble(rate) < -5)
{
MessageBox.Show("Invalid Rate - Rate cannot be less than -5%.");
}
else if (Convert.ToDouble(rate) > 100)
{
MessageBox.Show("Invalid Rate - Rate cannot be more than 100%.");
}
else
{
try
{
XmlNodeList xmlnode = xmldoc.GetElementsByTagName("PersonalAutoVehicle");
for(int i=0; i
|
|
|
|
|
saymajum wrote: .I need to do the calculations for each and every nodes where Attribute is mention as coverage.
OK, so you need to use SelectNodes where the attribute exists. XPath allows you to do this.
Use SelectNodes, not GetElementsByTagName. XPath is a lot more flexibile than that.
use double.TryParse, not convert.ToDouble, that will tell you without throwing an exception if the conversion is not possible.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks a lot I am trying in that way
|
|
|
|
|
How to loop in every nodes of a XML file through C# codes
|
|
|
|
|
Assuming it's in an xml document, you can use the SelectNodes method to get through a list of nodes, then you'd need to recurse from there.
However, I believe that an XmlReader just steps through them, that may be better/easier.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks,
But my scenario is:
There is a already existing Xml file.I have to take to nodes from there multiply it and result will come in the 3rd node that will be created dynamically.Coing in C#.
|
|
|
|
|
OK, so you don't want to iterate over every node, at all. You have specific paths you can pass into an XPath to get the values you want, you can use int.TryParse to get the numbers out, and then you need to add a node. XmlDocument is what you need. And probably a good read of the MSDN, it doesn't sound like you know much about using XML, yet.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Yes it's true,
After that I need loop also to itarate for each an every nodes.
|
|
|
|
|
OK, well, I answered that already.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
how do you attach a serial command to a button in c#?
i have a lutron rs232 controller for my lights, and i want to know how you attach an on/off command to it.
this is what i have
private void button1_Click(object sender, EventArgs e)
{
SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
port.Open();
port.Write("SDL,1,0") //just an example, "Set Dimmer Level, zone 1, 0 for off"
port.Close();
}
now the (SDL,1,0) i've put a "/r/n" as well, but i get no response.
|
|
|
|
|
dirtylarry wrote: how do you attach a serial command to a button in c#?
I wouldn't. I'd put all the serial communications in a class (or classes) of its own. I'd then call that class from the user interface.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
* Reading: Developer Day 5
Ready to Give up - Your help will be much appreciated.
My website
|
|
|
|
|
Does it work when you send the same string using a terminal emulator
(such as Hyperterminal) with the same port settings ?
If not, anything is possible.
If so, maybe you need some delay between port.Open/Write/Close so the
control lines can settle (actually the lutron peripheral can react to their new
state).
|
|
|
|
|
in hyperterminal, it works fine, i need to set ascii characters, but it works fine in ht.
|
|
|
|
|
OK - I believe you're sending Unicode characters in this case, you'd need to build a byte [] or something to send ASCII ( or there are conversion classes in there somewhere )
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Although MSDN states "By default, SerialPort uses ASCIIEncoding ..."
|
|
|
|
|
I am trying to setup an array of forms so that each uses the same original form yet will get different data.
I used the following command
List<form1> forms = new List<form1>();
Is this correct and if so how does this get assigned a different number to forms.
Each time I instantiate a new form it shows as "forms = 0".
How do I solve this problem.
Thanks,
Michael
|
|
|
|
|
MAW30 wrote: Each time I instantiate a new form it shows as "forms = 0".
Sounds to me like you expected creating forms to magically add them to this list. forms.Add(new Form1()) is how to add a form to the list, and create it.
I don't like your idea, you'd do better to have an array of data sources.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
is there a way in c# to communicate to the serial port over tcp/ip?
|
|
|
|
|
Hi,
I am in bit of a trouble. I had made a flexible and all in all well working diagnostic tool that doubled as a fast prototype of the new functionality for my ongoing project.
The project is in C++, while the diagnostic tool is in C#. Both in .NET. Originally I planned to re-write the tool under C++, however few problems came up and my timeframe became smaller and smaller. Now onto my question:
Is there a way to package my C# diagnostic tool as a .DLL, and load that library in main project that is in C++. As far as I know the language in which library is written should be irrelevant, however upon looking all over the net I didn't find a proper solution to my problem.
wbr,
Victor
|
|
|
|
|
Just create a class library project, put the code in there, build it, and then import the dll into your C++ project.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks,
Well this is the gist of what I was trying to do, however I never done things to that regard, and could not find proper guides.
I am aware of how to compile a C# project into a DLL, however there are three sepcifics I am shaky about:
1) how do I mark functions I would like to export in C#?
(something similar to C++'s AFX_MANAGE_STATE(AfxGetStaticModuleState()); i guess?)
2) can I only export functions, or can I export and entire class?
3) in C++ do I just do #include <libname> and than define a class of the same name as one exported earlier?
Once again sorry for bombarding you with questions....
wbr,
Victor
|
|
|
|
|
1 - if they are public, they are exported
2 - the classes are also exported, if they are public. Basically, in .NET, a dll is referenced and everything in there is the same as if it was written into the project directly. The only point of difference is that anything marked internal is public inside the dll, and private outside it.
3 - I don't know, doesn't C++/CLI offer a list of references in the project ? I'd expect you'd add the dll as a reference, then you'd have access to the objects, same as I do in C#.
lechium121 wrote: Once again sorry for bombarding you with questions....
Not at all, that's why I'm here.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|