|
I have uploaded a C # ActiveX control inside an MFC ActiveX control.
The WebBrowser inside the C # ActiveX control does not communicate with the script.
Is there a solution?
|
|
|
|
|
Please do not post the same question in multiple forums.
|
|
|
|
|
OK. The .NET Framework side post has been deleted.
|
|
|
|
|
Yes. Since the user can "disable AciveX content", use something else.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I'm building a fraction application and I have recently fixed an issue with a divide by zero exception. However after fixing this problem, a whole new one arose, the problem I am having now is that the textbox in which the answer displays always states the denominator as 0 when it is supposed to show the reduced form.
The code for both is below and I appreciate any help or feedback
<pre>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Fractionapp
{
class Fraction
{
private int numerator;
private int denominator;
public Fraction()
{
numerator = 0;
denominator = 0;
}
public Fraction(int num, int den)
{
numerator = num;
Denominator = den;
Reduce();
}
public int Numerator
{
get
{ return numerator; }
set
{ numerator = value; }
}
public int Denominator
{
get
{
return Denominator;
}
set
{
if (value == 0)
{
throw new ArgumentOutOfRangeException("Denominator", value, "Denominator cannot be zero");
}
}
}
private void Reduce()
{
int GCD = 0;
for (int x = 1; x <= denominator; x++)
{
if ((numerator % x == 0) && (denominator % x == 0))
GCD = x;
}
if (GCD != 0)
{
numerator = numerator / GCD;
denominator = denominator / GCD;
}
}
public override string ToString()
{
return numerator + "/" + denominator;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Fractionapp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnCalculateFraction_Click(object sender, EventArgs e)
{
{
Fraction fr2 = new Fractionapp.Fraction(Convert.ToInt32(txtNumerator.Text), Convert.ToInt32(txtDenominator.Text));
txtReduced.Text = "The lowest form of the inputted fraction is: " + fr2.ToString();
}
}
}
}
|
|
|
|
|
Hi,
you tricked yourself in this one. First some comments, as requested:
1.
property Denominator throws when the value is zero, yet without parameters you create a Fraction with denominator zero??? This should be 1 IMO.
2.
Inside Reduce() you apply a brute force approach by trying each and every possible common divisor. Rather than trying them all in ascending order, you should use descending order and stop as soon as you find one.
3.
Again, inside Reduce(), you also try divisor 1, which always will be a common divisor. Such test is unnecessary, and so is the if (GCD != 0) test, as GCD will be 1 or larger.
4.
In the setter half of Denominator you fail to set anything.
5.
Now check the casing inside your Fraction(int num, int den) constructor!
Please check why several of the above issues are relevant to your program's current symptom.
6.
When you fixed all of the above, then consider entering some negative numbers, and check whether your program fails for negative denominators; fix if necessary.
7.
Rather than using Convert.ToInt32() you should use int.TryParse() which takes a bit more code but offers an indication the text actually is/isn't representing a valid number, so you can act accordingly.
8.
Needless to say, there are much better algorithms to determine a GCD, e.g. Euclid's.
modified 13-Apr-18 22:11pm.
|
|
|
|
|
Thanks for the reply! I guess I'm just not understanding what you're explaining for comments 2, 3, 4. Comment 1 I was messing around trying to fix things (so the exception would fire and forgot to set it back to 1, that's been fixed). If I change the D to a d in the 2 parameter constructor it works perfectly just doesn't fire the exception. Yet changing the d to a D causes any number entered in the denominator box to show as a zero in the answer box. I'm trying to understand why this happens and the code to fix it (has to be simple), I'm a complete coding novice so I don't really understand this without visuals.
|
|
|
|
|
a line
denominator=value;
is missing!
|
|
|
|
|
Hah! I guess that's what I get for copying and pasting, I've got this in like 3 different files (don't ask), one of the programs must've had that line missing and I copied from it, thank you though!
|
|
|
|
|
Rather than using brute-force to find the GCD, you should consider using the Euclidean algorithm:
function gcd(a, b)
while b ≠ 0
t := b;
b := a mod b;
a := t;
return a;
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
I'm displaying data from a stored procedure in excel, columns which have null values in database are displayed
#VALUE! in Excel, what should i do so that i can display them as blank cells?
thanks
|
|
|
|
|
|
|
Hello,
I found a way to resolve this, it is just about adding a test on the value i want to display, i added a test if it is null, i affect an empty string to it, below my code:
<pre> for (int j = 0; j <= rows - 1; j++)
{
var rowItem = dt.Rows[j].ItemArray;
for (int k = 0; k <= rowItem.Length - 1; k++)
{
if (String.IsNullOrEmpty(rowItem[k].ToString()))
allRecords[j + 1, k] = string.Empty;
else
allRecords[j + 1, k] = rowItem[k];
}
}
Thanks ,
|
|
|
|
|
So I very recently started learning my first coding language at college, which is C#, i have an assignment in for Tuesday and cant for the life of me figure out how to complete one of the tasks it asks of me. The task is as follows:
"Write example program code that demonstrates the use of a function that calculates and returns the mean average of 5 values that are passed to it."
If anyone could walk me through what to do or give me some example code as to how they would approach this task then that would be most appreciated.
(I'm using VisualStudio)
|
|
|
|
|
This weekend would be the best time to start learning in C# functions.
To jump start, create a new project in visual studio and choose C#->Windows->Console Application.
class Program
{
static void Main(string[] args)
{
decimal[] values = new decimal[] { 1, 2, 3, 4, 5 };
decimal result = MeanAvg(values);
}
static decimal MeanAvg(decimal[] values)
{
decimal result = 0;
return result;
}
}
|
|
|
|
|
You could also do it this way:
static void Main()
{
double answer = MeanAvg(1,2,3,4,5);
double answer2 = MeanAvg(1,2,3,4,5,6,7,8,9,10);
}
static double MeanAvg(params int [] values)
{
double total = values.Average();
}
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Or this, which has the added benefit of handling a mix of numeric data types, and will throw an exception if you try to pass something that can't be converted to a numeric type:
private static double MeanAvg(params object[] values)
{
return Convert.ToDouble(values.Select(Convert.ToDecimal).Average());
}
These will work:
double answer = MeanAvg(1M,3,3d);
answer = MeanAvg(1M,3M,"3");
But this will throw an exception:
double answer = MeanAvg(1M,3M,"abc");
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
This is a trivial piece of code, and you still have a week. It's a shame that you have been given the solution; the sentence in bold explains quite well what needs to be done.
As for your ASAP; we're volunteers, and even if you were paying me I would not accept it. This ain't the army, and as soon as possible is when it damn well pleases me
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Did you attend the "classes".
How can you have an assignment and not be able to figure it out for "the life of (you)"?
And I thought "mean" AND "average" together was redundant. (As in, the "average" of the average?)
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Why were my answers voted down? They damn well provided a correct answer. This is complete bullsh|t.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
@john-simmons-outlaw-programmer @cyborgkagaw
edit ...
After thinking this over, I have decided that my down-voting posts from Simmons and Gayo was a mistake. I apologize to both of them, and I have up-voted their posts to counteract the down-vote,
While I find the posting of ... what I perceive as ... homework solutions for obviously gimme-codez OP's disturbing, it's obvious to me that my taking this on ... without being part of a sanctioned and widely supported effort by many MVP'a and Mentors ... will just create chaos and bad-feeling.
We're here because we love to code ... aren't we ?
sincerely, Bill
... end edit ...
I have up-voted posts from Vluggen and Schmitz, and down-voted posts from Simmons and Gayo for the following reasons:
If we provide code to people that helps them avoid/shirk their homework, we are degrading the educational process, and contributing to the OP's failure to learn and grow: we are fostering dependency and laziness.
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
modified 14-Apr-18 8:40am.
|
|
|
|
|
BillWoodruff wrote: If we provide code to people that helps them avoid/shirk their homework, we are degrading the educational process, and contributing to the OP's failure to learn and grow: we are fostering dependency and laziness.
Down-voting CORRECT answers is bullsh|t, Bill, regardless of whether or not YOU believe that the user should have gotten said answer.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
John Simmons / outlaw programmer wrote: Down-voting CORRECT answers is bullsh|t, Bill I take the responsibility I believe is involved in being a Mentor on this site seriously.
You continue to be someone I respect technically, and whose many contributions to this site, I have learned from.
sincerely, Bill
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
Yes. The "good samaritan" law should apply. Just don't move them.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|