|
Use Math.Pow() instead.
H.
|
|
|
|
|
|
<code>^</code> is the logical <a href="http://msdn.microsoft.com/en-us/library/zkacc7k1(VS.80).aspx">XOR</a>[<a href="http://msdn.microsoft.com/en-us/library/zkacc7k1(VS.80).aspx" target="_blank" title="New Window">^</a>] operator. As was mentioned upthread you need to use <code>Math.Pow</code>.
It is a truth universally acknowledged that a zombie in possession of brains must be in want of more brains.
-- Pride and Prejudice and Zombies
|
|
|
|
|
Did you ever screw that one up
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I wrote a program that will search AD and pull all the users int a combo box and then you select the user to unlock and it unlocks the locked out account awesome !
to make things quicker i want to know how could i only populate the combo box with locked accounts ?
thank you for your time
|
|
|
|
|
I have code for a calculator, and continue to get an error that I cannot seem to find.
The error: The type or namespace name 'ArrayList' could not be found(are you missing a using directive or an assembly reference)
I have partial classes, delaring the following in the Calculator.Designer.cs
private string m_value;
private ArrayList m_store;
the rest of the code below is in the Calculator class:
Can someone see what might be missing?
Here is the code:
public partial class Calculator : Form
{
public Calculator()
{
InitializeComponent();
m_value = "";
m_store = new ArrayList();
}
private void btnSeven_Click(object sender, EventArgs e)
{
AddToArray(btnSeven);
}
private void btnEight_Click(object sender, EventArgs e)
{
AddToArray(btnEight);
}
private void btnNine_Click(object sender, EventArgs e)
{
AddToArray(btnNine);
}
private void btnFour_Click(object sender, EventArgs e)
{
AddToArray(btnFour);
}
private void btnFive_Click(object sender, EventArgs e)
{
AddToArray(btnFive);
}
private void btnSix_Click(object sender, EventArgs e)
{
AddToArray(btnSix);
}
private void btnOne_Click(object sender, EventArgs e)
{
AddToArray(btnOne);
}
private void btnTwo_Click(object sender, EventArgs e)
{
AddToArray(btnTwo);
}
private void btnThree_Click(object sender, EventArgs e)
{
AddToArray(btnThree);
}
private void btnZero_Click(object sender, EventArgs e)
{
AddToArray(btnZero);
}
//create method for array to calculate
private void AddToArray(Button btn)
{
//m_value this to set the value
m_value += btn.Text;
//set label lblResult = " to display it to user
lblResult.Text += btn.Text;
//make all enabled to use it
SetEnableOperatorBtns(true);
}
private void btnAdd_Click(object sender, EventArgs e)
{
AddOperatorToArray(btnAdd);
}
private void btnSubtract_Click(object sender, EventArgs e)
{
AddOperatorToArray(btnSubtract);
}
private void btnMultiply_Click(object sender, EventArgs e)
{
AddOperatorToArray(btnMultiply);
}
private void btnDivide_Click(object sender, EventArgs e)
{
AddOperatorToArray(btnDivide);
}
// Method to add the operator to the array
private void AddOperatorToArray(Button btn)
{
//add the value to the arrayList
m_store.Add(m_value);
//display the Result to user
lblResult.Text += btn.Text;
//make the value empty
m_value = "";
//add the opeator to arrayList
m_store.Add(btn.Text);
//make the decimal button enabled
btnDecimal.Enabled = true;
//call the SetEnableOperatorBtns(false); to make all operators unenabled
SetEnableOperatorBtns(false);
}
private void Reset()
{
m_value = "";
lblResult.Text = "";
m_store.Clear();
btnDecimal.Enabled = true;
}
private void SetEnableOperatorBtns(bool enable)
{
btnAdd.Enabled = enable;
btnSubtract.Enabled = enable;
btnMultiply.Enabled = enable;
btnDivide.Enabled = enable;
btnEquals.Enabled = enable;
}
private void btnDecimal_Click(object sender, EventArgs e)
{
//Add to arrayList
AddToArray(btnDecimal);
btnDecimal.Enabled = false;
}
//m_result here take the first element in m_store if this element is
//operator like +*-/, Exception gives us error else if will take the
//digits or dot point
private void btnEquals_Click(object sender, EventArgs e)
{
try
{
// add value to the arrayList
m_store.Add(m_value);
// add operator to the arrayList
m_store.Add(btnEquals.Text);
//take the first element in the array, make sure its a digit
//and then save it on m_result, else it will give exception
float.m_result = float.Parse(m_store[0].ToString());
//loop extracts all elements in arrayList then checks it
//if the element is operator it will calculate the prefix and
//postfix and give us the result
//for loop on arrayList and check for element if equal to opera or not
//if equal operator
for (int i = 0; i < m_value.Length; i++)
{
if(m_store[i].ToString() == "+")
{
lblResult.Text = "";
m_result += float.Parse(m_store[i+1].ToString());
lblResult.Text = m_result.ToString();
}
else
if(m_store[i].ToString() == "-")
{
lblResult.Text = "";
m_result -= float.Parse(m_store[i].ToString());
lblResult.Text = m_result.ToString();
}
else
if(m_store[i].ToString() == "*")
{
lblResult.Text = "";
m_result -= float.Parse(m_store[i].ToString());
lblResult.Text = m_result.ToString();
}
else
if(m_store[i].ToString() == "/")
{
lblResult.Text = "";
m_result -= float.Parse(m_store[i].ToString());
lblResult.Text = m_result.ToString();
}
}
m_store.Clear();
m_value = lblResult.Text;
for(int i=0; i < m_value.Length; i++)
{
if(m_value[i].ToString() == ".")
{
btnDecimal.Enabled = false;
break;
}
else
{
btnDecimal.Enabled = true;
}
}
btnEquals.Enabled = false;
}
catch(Exception exception)
{
MessageBox.Show(exception.Message, "Error");
}
}
private void btnClear_Click(object sender, EventArgs e)
{
Reset();
}
|
|
|
|
|
You forgot to include using System.Collections ?
|
|
|
|
|
I already had the using System.Collections.Generic;
but added the using System.Collections;
The errors I am getting are that:
m_value does not exist in current context
m_store does not exist in current context
|
|
|
|
|
Hi,
some remarks:
1.
the ArrayList class you probably want is located in namespace System.Collections, hence it needs a using System.Collections; statement in every file that wants to use it.
This is different from using System.Collections.Generic;
2.
you should no longer use ArrayList, instead use List<T> which is a generic list holding objects of type T only (your choice of T!); it is supported since .NET 2.0
The generic collections require a using System.Collections.Generic; which you get for free when using Visual Studio.
3.
your ArrayList is appearing in a Calculator.Designer.cs file? I have never seen the Designer use ArrayList like that, and you should not edit designer generated code at all. Put your code in Calculator.cs file, in the constructor, the Load handler, whatever.
|
|
|
|
|
The only code I had in the Designer.cs file was:
private string m_value;
private ArrayList mstore;
The rest of the code is in the is in the Calculator.cs file.
So now I have made the change:
private string m_value;
private List<t>; m_store; // moving the declarations to the cs. file
public Calculator()
{
InitializeComponent();
m_value = "";
m_store = new List<t>();
}
When I remove the values above, the private calls, I get even more errors.
Is using partial classes possibly causing my errors? The code was original in a publ class.
|
|
|
|
|
Hi,
the variable declarations that used to be inside Calculator class in Calculator.Designer.cs file need to be inside Calculator class in Calculator.cs file. And that file needs all the import statements that lead the compiler to recognize the classes you are using (such as System.Collections.Generic for generic lists).
If you plan on accessing m_value and m_store from outside the Calculator class, you would need to change their attribute from private to public, or better yet provide public methods or properties.
I recommend you buy and study a tutorial book on C#, that would guide you step-by-step and teach you good practices from the start.
|
|
|
|
|
Hi,
I am using the CSML libraries which are just what I need. However, it looks like the precision when doing matrix manipulations (taking inverses and matrix multiplication) is only to 4 decimals, even though I'm using doubles. Internally it has to be using many more, but I can't get it to display or use more in further calculations. Suggestions please.
Linda
Linda Woodard
|
|
|
|
|
Hi,
I'm not familiar with the CSML libraries. AFAIK there are only two ways to get bad results with matrices: using a bad algorithm (e.g. not applying pivots), which I don't expect a library to get wrong; and operating on very peculiar matrix values (as in searching the intersection of two almost parallel lines).
Of course, you may have made some silly mistake somewhere outside the library too, as in performing some operations in lower precision, maybe in integers.
Example: int a=1; int b=2; double c=a/b*100.0; would yield c=0.0; !
|
|
|
|
|
I think it's only a matter of displaying the result. Check out some topics on number formatting in MSDN, that should help. Try for example
double x = SomeCalculation();
string resultToDisplay = x.ToString("F9");
to get 9 significant digits, but I am sure there are better ways.
H.
|
|
|
|
|
Thanks. I think this will help. I need to actually use the results, not really display them, but I know how to do that. Painful and inelegant, but at this point...
Linda
|
|
|
|
|
This looked like it should work and it does if you are dealing with doubles. Unfortunately I'm dealing with matrices and the Matrix.ToString() does not take any arguments. So I'm still looking.
Linda
|
|
|
|
|
Hi there,
Thanks for taking interest in my question. Actually, I wanted to know the process of creating a Gel Button (Stylish, glowing, shining and colourful button control) in Visual C#. I went through many tutorials in both google and MSDN, but all of them mentioned WPF in them and the code was in XAML. I have not started programming in XAML or WPF yet, but I know that they can be used to create graphically rich UI applications. However, is there any way I can create Gel buttons in Visual C# for my Windows form? Please help.
Thank you,
Rajdeep.NET
|
|
|
|
|
|
Hello,
I have been struggling for the past 3 days to do this but I simply can't find any good info on how to do it.
Please let me explain what I want.
I have a compiled software. I want users to be able to brand this software with their own ICON, ABOUT IMAGE and DETAILS.
How can I do this ?
In my oppinion, there are 2 ways to do this :
add the image and details file in to the exe and also, change the exe icon. I don't think this is possible.
create an exe from my application, that will automaticaly add in it the Brandable Software File, About Image and Details file. When I run this newly created exe, it can extract the files in a temp file and run the Branded software.
How can I do that ? Is there any other way ? Did I explain correctly what I want ?
PS: I am programming in VS 2008 c# with .net 3.5
Thank you
|
|
|
|
|
sodevrom wrote: create an exe from my application, that will automaticaly add in it the Brandable Software File, About Image and Details file. When I run this newly created exe, it can extract the files in a temp file and run the Branded software.
How can I do that ? Is there any other way ? Did I explain correctly what I want ?
Hello Sodevrom,
Generating an .exe (executable) file from within your application is an impossible task! But yes, other executable files can make your way, like files with .vbs and .bat extensions (which are also executable). The source files are written in Notepad as usual and then are saved with a name and a required executable extension. You can use the FileStream property of .NET to create a notepad file and write the code to it. Then, you can use the File.Move(); function to rename the file to any execuatble extension you want, but not any .exe. Hope this information helps. For more information, search Google or MSDN.
Happy Programming,
Rajdeep.NET
|
|
|
|
|
|
Hello,
This is not exactly what I need. A friend of mine made me a DLL a while back, that had 3 functions :
start_exe(string exe name)
add_file(string file path,string source path)
create_exe(icon path,string file_of_the_file_to_run_when_oppening_exe)
And it worked perfectly in C++, but it does not work very good in c#.
Any other ideeas ?
|
|
|
|
|
You want to replace resources in an existing .exe file?
If the .exe file is a .NET assembly, that's pretty easy. Take a look at Mono.Cecil[^].
|
|
|
|
|
Hello,
This is pretty difficult. Are you sure this will modify the resources from a .exe from another .exe file.
So if I have APP1 that controls APP2, can I modify the resources of APP2 from APP1 ?
Thank you
|
|
|
|
|
Yes, Cecil can open .exe files, modify them, and save back the changes.
Use something like this:
AssemblyDefinition asm = AssemblyFactory.GetAssembly("myassembly.exe");
asm.MainModule.Resources.Add(new EmbeddedResource(
"ResourceName", ManifestResourceAttributes.Public,
File.ReadAllBytes("image.png")
));
AssemblyFactory.SaveAssembly(asm, "myassembly.branded.exe");
|
|
|
|