|
I have a document level application for Excel 2010 using VSTO and c#. The following code is used to call the Excel Growth function.
double[] known_Ys, new_Ys, known_Xs, new_Xs;
Excel.WorksheetFunction wsf = Application.WorksheetFunction;
object results = wsf.Growth(known_Ys, known_Xs, new_Xs, System.Type.Missing);
While debugging, "results" show a type of 'System.Object[*]' which is a System.Object[] with an undefined lower boundary.
Looking at the variable, there is an array of double values that appear to be correct. The lower boundary is 1, and the upper boundary is 5.
When attempting to cast the results to either object[] or double[], I get an exception, "Unable to cast object of type 'System.Object[*]' to type 'System.Object[]' or 'double[]'.
I've also unsuccessfully tried to use the static methods of the Array class to copy the contents out.
Any thoughts on a resolution would be appreciated.
I don't want to use VBA code to resolve the problem if it can be avoided.
I've also considered a work-around, using a hidden worksheet to perform the calculations and copying the results into the c# application, but feel I should be able to handle it in the c# code.
I found the following work-around, unless someone has a better solution.
"results" inherits from System.Array.
System.Array resultsArray = results as System.Array;
if (resultsArray != null)
{
int idx = resultsArray.GetLowerBound(0);
for (int i = 0; i < new_Ys.Length; i++)
{
new_Ys[i] = (double)resultsArray.GetValue(idx);
idx++;
}
return new_Ys;
}
else
{
return null;
}
The conflict is that c# vectors (one dimensional arrays) are always zero based, so explicit casts won't work.
modified 5-Nov-12 6:46am.
|
|
|
|
|
i have two panel in ma form. panel1 with button1 on it at location let say x:10,y:10 and panel2 with button 2 on it at location x:10,y:10.
what actually button1 do:- it hide panel1 and shows panel2 at the same location.
but whenever i click on button1 twice after completion its process it fire button2 click event,
plz help me ASAP
|
|
|
|
|
The problem is that the button click event is happening almost immediately - so the second "click" is going to the correct place - the control at that position on the "new" panel. And that will generate a click event for the new button because that is exactly what should happen.
If you want to stop it, then
1) Create a class level variable:
private DateTime lastSwap = DateTime.Now;
2) In the Button1 click handler, set it:
lastSwap = DateTime.Now; And then swap panels.
3) In the Button2 click handler, check it and ignore if too soon:
if (DateTime.Now < lastSwap.AddMilliseconds(500)) return;
You can change the 500 to any value you think reasonable - 500 provides half a second.
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
hello,
thaks for your quick response...
code is working properly... but it is impossible to implement on big application where there are mre den 20,25 panels and every control takes diff diff tym to execute.
hope you get my point.
thanks once again.
|
|
|
|
|
neeraj@max wrote: are mre den
neeraj@max wrote: takes diff diff tym
neeraj@max wrote: hope you get my point.
No, not really. Try cutting out the childish txtspk and talk like a grown up.
|
|
|
|
|
hello,
thanks for your quick response...
code is working properly... but it is impossible to implement on big application where there are more then 20,25 panels and every control takes different time to execute.
hope you are getting my point.
thanks once again.
|
|
|
|
|
It's not impossible to implement, it's just going to take a while.
|
|
|
|
|
You're missing the point. As a programmer, when you find a solution to the problem, but you have 25 problems - you dont implement the solution 25 times. You implement it once and re-use it 25 times.
Think of it this way - if you have 25 customers, you dont write 25 different classes to represent each customer, you implement once class called "Customer" and reuse it 25 times. The same thing applies here, you need a solution which stops a button being clicked within 500ms of another button (personally I think this is an awful solution to your original problem, but hey if it works for you go with it). Write a class which exhibits this behaviour and attach it to every button which requires it.
|
|
|
|
|
@J4amieC
thanks for your 25 customer and single solution example...
but this solution is suitable for 2,3 panel only becuase
diffrent buttons have diffrent tasks and process time so we cant fix the 500ms for every event.
anyways i am looking for more suitable solution.....
if you come to know any, let me know.
|
|
|
|
|
The 500ms had nothing to do with whatever task the button does, it had to do with stopping a quick double click operating a button which appears after the first click. It should not matter what the second button does!
Anyway your original question asked about 2 panels, and you got a solution to the question as stated. Ask the right question, and you'll get the right answer.
|
|
|
|
|
http://www.youtube.com/watch?v=bpojl4XMweo&feature=g-upl
above link will explain you my problem very clearly.
|
|
|
|
|
|
leave it then i will solve it by myself ...
|
|
|
|
|
by ignoring queued mouse events. i got my answer.
@everybody: thank you every one for your suggestions.
|
|
|
|
|
Hi,
I want to call parameterised function which is written in c++ from c# by using thread and also how will c# know or will get return value from c++ function, so that c# function will proceed further. If you have any example then let me know.
Thanks
sjs
|
|
|
|
|
You can use P/Invoke[^] to call C++ functions within a DLL.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Something like this:
[DllImport("yourdllname.dll")]
public static extern returnType FunctionName(parameterType parameter);
To call it on a thread, call BeginInvoke on a ParameterizedThreadStart instance that in turn calls your PInvoke function.
|
|
|
|
|
if I have this is VB.NET:
Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
Protected Sub OnPropertyChanged(ByVal strPropertyName As String)
If Me.PropertyChangedEvent IsNot Nothing Then
RaiseEvent PropertyChanged(Me, New System.ComponentModel.PropertyChangedEventArgs(strPropertyName))
End If
End Sub
What is the equivalent in C#?
I don't speak Idiot - please talk slowly and clearly
"I have sexdaily. I mean dyslexia. Fcuk!"
Driven to the arms of Heineken by the wife
|
|
|
|
|
Some good examples here[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Thanks for the pointers Richard. I am self-learning C# from a 20 year VB background and some of the constructs are a little confusing!
I don't speak Idiot - please talk slowly and clearly
"I have sexdaily. I mean dyslexia. Fcuk!"
Driven to the arms of Heineken by the wife
|
|
|
|
|
Andy_L_J wrote: some of the constructs are a little confusing! I found exactly the same when I started C# a couple of years ago, but perseverance seems to pay dividends.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Declaring an event is pretty simple. Have a look here: A simple code snippet to add an event[^] The code to create an event is at the top, but the rest just provides a snippet to make it simpler to create them in VS.
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
Thanks Griff, I now have this (and it all seems good - satisfies INotifyPropertyChanged implementation):
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(PropertyName));
}
}
Just need to test it out.
(This is pretty trivial for me in VB.NET, however I am self-learning C# and some of the constructs are still confusing.)
I don't speak Idiot - please talk slowly and clearly
"I have sexdaily. I mean dyslexia. Fcuk!"
Driven to the arms of Heineken by the wife
|
|
|
|
|
You're welcome - it's all pretty easy (I find events and delegates generally a lot simpler to work with in C# than in VB) and a lot of C# just seems clearer then VB; at least there is a clear distinction between a method call and an index!
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
OriginalGriff wrote: at least there is a clear distinction between a method call and an index!
Ah, but the difference between (), [], and {} can be tricky! I keep getting "xyz is a field but being used as a method" compiler errors. It could almost be my sig at the moment lol.
I don't speak Idiot - please talk slowly and clearly
"I have sexdaily. I mean dyslexia. Fcuk!"
Driven to the arms of Heineken by the wife
|
|
|
|