|
Thanks to you both...sometimes I get so tired that I cannot see the forest through the trees. Its like staring at a misspelled word and not being able to 'see' it. I have marked both answers (which were identical) as correct (after I slapped myself for not seeing something so obvious). Thank you again for taking the time..Best Regards, Pat
|
|
|
|
|
I have a program that runs fine on several machines (xp, win7) however on one machine (vista) I get an error that it can't find one of the refernce dlls.
I can run the project on that machine in visual studio, but when I click on the application (from the debug folder), it has the dll not found error.
I have tried copying the dll pretty much everywhere unsuccessfully.
|
|
|
|
|
At work we have our legacy code written in Borland c++ and we wish to gradually work our way over to c# and .net and create software that is a series of modules/exes. I have to write a new module soon and was wondering if it is possible to talk to non .net cpp functions from my .net exe and what the mechanism would be. If anyone knows of an article on this or could explain the procedure to me it would be appreciated.
|
|
|
|
|
The methods in the C++ dll should be marked extern "C" so that it can be used in the C++ dll. In the .Net code, you can make use of DllImport attribute to call those methods.
|
|
|
|
|
The cpp code is an existing application, the c# is going to extend the application so there are no dll's. I was thinking of using something along the lines of shared data which i have done before and if it was possible shared functions.
|
|
|
|
|
|
Not sure this will work, cpp code is an existing app which isn't com but borlands owl based.
|
|
|
|
|
|
You would use P/Invoke to call your own C or C++ native code, in the same way you can call existing Win32 functions. Here[^] is a little article on the subject. It still is Work In Progress.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Thanks, i will take a look at this.
|
|
|
|
|
Another thing you could also use that may be easier than doing PInvokes as suggested is to use Microsoft's Managed C++ to wrap the existing Borland C++ application. Microsoft's Managed C++ is capable of doing both managed (.NET) and unmanaged (Native) code within the same modules, functions, etc.
I used this technique but went in reverse - I had a native app that I wanted to talk to a .NET DLL and this is how I did it. The code in the Managed C++ part is very small, but it does the job and does it easily.
I would recommend this approach.
|
|
|
|
|
I know a lot of people recommend this; however I don't really understand why I would start using a third language (and a separate project and DLL) to link two existing code bases when it can be done without. I'm not saying it is no good, just I don't do it that way.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Hi guys,
I am beginner and developing a test program.
this is the description:
Calculate the total mark and final grade:
Labs Mark is an integer from 0 to 10;
Assignmnet1 mark is an integer from 0 to 20
Assignmnet2 mark is an integer from 0 to 20
Final exam Mark is an integer from 0 to 50
Student passes the unit if and only if
• (Labs Mark + Assignment1 Mark + Assignment2 Mark)>=25 and Final exam Mark >=25
There are five grades, which should calculate as below:
• F If the total mark is less than 40;
• MF if (40<=total Mark<50) or (total mark>=50 but student didn’t passed);
• P if (50<= total Mark <60) and student passed;
• C if (60<= total Mark <70) and student passed;
• D if (70<= total Mark <80) and student passed;
• HD if total mark >=80;
this is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Assignmnet2
{
public class ITECH3219Student
{
//definition of Class's Field
private string FirstName;
private string SurName;
private int StudentId;
private int LabsMark;
private int Assignment1;
private int Assignment2;
private int Final;
// public string Grades;//In order to return the Student Grade.
public int TotalMark;
//defination of Class Properties
public string Fr_name
{
get { return FirstName; }
set { FirstName = value; }
}
public string Sr_Name
{
get { return SurName; }
set { SurName = value; }
}
public int St_Id
{
get { return StudentId; }
set { StudentId = value; }
}
public int Lb_Mark
{
get { return LabsMark; }
set
{
if (value > 0 && value <= 10)
{
LabsMark = value;
}
}
}
public int Ass1
{
get { return Assignment1; }
set
{
if (value > 0 && value <= 20)
{
Assignment1 = value;
}
}
}
public int Ass2
{
get { return Assignment2; }
set
{
if (value > 0 && value <= 20)
{
Assignment2 = value;
}
}
}
public int Fnl
{
get { return Final; }
set
{
if (value > 0 && value <= 50)
{
Final = value;
}
}
}
//define Constructor of Class
public ITECH3219Student(string Fr_Name, string Sr_Name, int St_Id, int Lb_Mark, int Ass1, int Ass2, int Fnl)
{
this.FirstName = Fr_Name;
this.SurName = Sr_Name;
this.StudentId = St_Id;
this.LabsMark = Lb_Mark;
this.Assignment1 = Ass1;
this.Assignment2 = Ass2;
this.Final = Fnl;
}
//define the class's methods
public bool Passed()
{
return ((LabsMark + Assignment1 + Assignment2) >= 25 && (Final >= 25));
}
public readonly string Grade()
{
}
public override string ToString()
{
return string.Format("Name:{0}\nSurname:{1}\nID:{2:D6}",
name, surname, studentID);
}
}
}
my problem is I don't know what should I write in this Part:
public readonly string Grade()
{
}
I appreciate if someone help me.
|
|
|
|
|
Use pre tags.
The modifier readonly can not be applied to methods (nor does it make sense, so why is it there anyway?)
What do you want to write there? The code to calculate the grade?
|
|
|
|
|
Firstly, thankx for your reply.
yes, I need the code to calculate the grade.
|
|
|
|
|
At a first glance it doesn't look too hard, what have you done so far?
edit: I have some code here, but I haven't tested it and I may not fully understand your requirements, so be careful and test it.
if (TotalMark >= 80)
return "HD";
if (TotalMark < 40)
return "F";
if ((LabsMarks + Assignment1 + Assignment2) >= 25 && Final >= 25)
{
if (TotalMark < 50)
return "MF";
if (TotalMark < 60)
return "P";
if (TotalMark < 70)
return "C";
if (TotalMark < 80)
return "D";
}
else
{
return "MF";
}
|
|
|
|
|
What were you smoking when you decided to check the scores in that order?
|
|
|
|
|
Nothing. What is wrong about the order?
Suppose TotalMark is 75, the expected result is D
if (TotalMark < 50)
return "MF";
if (TotalMark < 60)
return "P";
if (TotalMark < 70)
return "C";
if (TotalMark < 80)
return "D";
|
|
|
|
|
I didn't say that it wouldn't work, I asked why you went in that order? What made you decide to test the last case in the list first, and then go back to the first case?
By the way, if they passed, then there's no way they scored less than 50, since 50 is the minimum required to pass. So, you'll never get to the return "MF" under if (TotalMark < 50).
|
|
|
|
|
William Winner wrote:
By the way, if they passed, then there's no way they scored less than 50, since 50 is the minimum required to pass. So, you'll never get to the return "MF" under if (TotalMark < 50).
Ok I couldn't know that, there was no description of how TotalMark should be calculated
|
|
|
|
|
Ooh do you mean "why check for < 40 and >= 80 first"?
Because they are the only two cases where you don't need to know whether the student passed, so you can skip that calculation. I know it's pointless to optimize, it's a bit of a reflex (I learned to program in assembly first - I'll blame that)
Not that it's any faster..
|
|
|
|
|
Like the other responder said,
public readonly string Grade() is not the normal way to write a read-only property if that is what you're trying to do.
It should be
public string Grade
{
get
{
}
}
So, now you just need to test the scores to determine the grade...this isn't that complicated. Just go in order of what your prof gave you.
int totalMark = LabsMark + Assignment1 + Assignment2 + Final;
if (totalMark < 40)
{
return "F";
}
else if (!Passed())
{
return "MF";
}
else if (totalMark < 60)
{
return "P";
}
it's true that you don't need the else if's, but it makes the code a lot more readable.
|
|
|
|
|
I have Simulated OPC Server like Kepware,Matrikon and i need to access the OPC Server through C# Code.I have VB Code but I need to do in C#.
|
|
|
|
|
I have a senior developer that consistently checks for null after initializing an object...
<code>
CustomObject tmp = new CustomObject();
if (tmp == null)
{
throw new NullReferenceException();
}
</code>
I personally don't see the need to do this. Can anyone explain if this is a good/bad/old practice?
Thanks in advance.
|
|
|
|
|
Yes, that belongs in coding horrors.
|
|
|
|