|
I have two forms, Form1 and Form2. I am trying to pass struct data from Form1 to Form 2 and each time, I get these errors:
C:\WINXP\Profiles\Owner\My Documents\Visual Studio 2005\Projects\Object\Object\Form1.cs(29,25): error CS1502: The best overloaded method match for 'Object.Form2.Form2(Object.Form2.client)' has some invalid arguments
C:\WINXP\Profiles\Owner\My Documents\Visual Studio 2005\Projects\Object\Object\Form1.cs(29,35): error CS1503: Argument '1': cannot convert from 'Object.Form1.client' to 'Object.Form2.client'
My Form1.cs is:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Object
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public struct client
{
public string ClientMatter;
public string ClientName;
}
private void button1_Click(object sender, EventArgs e)
{
client mary;
mary.ClientName = "mary";
Form2 frm = new Form2(mary);
frm.Show();
}
}
}
My Form2 code is:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Object
{
public partial class Form2 : Form
{
public struct client
{
public string ClientMatter;
public string ClientName;
}
public Form2(client mary)
{
InitializeComponent();
label1.Text = mary.ClientName;
}
private void Form2_Load(object sender, EventArgs e)
{
}
}
}
|
|
|
|
|
You have two different client types in different scopes. The two types are:
Object.Form1.client
Object.Form2.client
Basically, you have nested the definition of the struct inside the form class. The client struct definition should be placed outside the class.
Extract one client struct out from the form class and delete the other client struct definition.
|
|
|
|
|
You could add a constructor to Form2 that accepted the struct as a ref parameter...
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi All,
Can anyone send some links on creating well organised/factored reuseable classes. I've been looking through google but haven't found much as of yet.
Thanks,
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
|
Isn't it just!
Thanks for this ... really good reading.
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
experance really helps in this, and mark clifton a fellow cp'er has written some good articles on this.
You can only be young once. But you can always be immature.
- Dave Barry
|
|
|
|
|
Im trying to send a class full of variables to a DLL Method and then have that method do some calculations and then send the class back to the client. IS that possible? Im getting an error that the current argument cant be converted.
|
|
|
|
|
Yes this will work just fine, so long as the "class full of variables" is a class that's visible to both sides.
e.g. MyProgram - references MySharedDll
Creates new <code>ClassFullOfVariables</code>
Sends instance over to MyOtherDll
MySharedDll
Contains the type
<code> class ClassFullOfVariables { ... }</code>
MyOtherDll - referencesMySharedDll
Contains a method: <code>DoCalculations(ClassFullOfVariables input)</code>
|
|
|
|
|
Cozmo23 wrote: IS that possible?
Yes.
are you passing the object ? does dll file have the defination of that class?
can you put the code over here
Best Regards
-----------------
Abhijit Jana
"Success is Journey it's not a destination"
|
|
|
|
|
The class you're passing back and forth would have to be defined in another DLL, that your other DLL would then "use".
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
What I have done so far is included the Class "PumpTest" (Class full of variables) in both the client and the DLL and attempted to use the code
"pTest = Calc.TableIIcalc(pTest); " to pass the PumpTest pTest to the DLL.
My DLL looke like this
public PumpTest TableIIcalc(PumpTest pTest)
{
calculations
return pTest;
}
I planned on making the PumpTest class its own DLL, would that solve the problem?
|
|
|
|
|
What makes you think this will not work?
You can only be young once. But you can always be immature.
- Dave Barry
|
|
|
|
|
Well I get two errors with the "pTest = Calc.TableIIcalc(pTest);" line of code
The first is a invalid arguments error, the second is Argument '1', cannont convert from 'Namespace.PumpTest' to 'Namespace2.PumpTest' they aren t actually called namespace but I cant post too much info about the program on the web. Namespace is the name of the client and namespace two is the name of the DLL.
|
|
|
|
|
Hello,
I'm stuck with the following issue:
let's say there is a DateTime 'timepoint', wich is passed in my method. I need to check now, whether timepoint's DayOfWeek is between 'fromDayOfWeek' and 'toDayOfWeek'.
that's what I've done so far:
protected override bool checkTimepoint(DateTime timepoint, DayOfWeek from, DayOfWeek to)
{
bool retValue;
retValue = timepoint.DayOfWeek >= from && timepoint.DayOfWeek <= to;
return retValue;
}
This will work for ranges like Monday-Friday, Thursday-Wednesday, Wednesday-Wednesday, but it will fail for something like Saturday-Sunday, since Sunday (0) is lower than Saturday(6).
Any idea on how to logically implement this issue?
Thanks in advance.
|
|
|
|
|
We solved a similar problem by using a mapping from DayOfWeek to integer that returned 7 instead of 0 for Sunday.
This way your code would work, too.
Not very nice but it works.
For .net the week start on Sunday
-^-^-^-^-^-^-^-
no risk no funk
|
|
|
|
|
This will fix the problem for Saturday-Sunday, but it will not solve for Saturday-Tuesday.
|
|
|
|
|
why not:
protected override bool checkTimepoint(DateTime timepoint, DayOfWeek from, DayOfWeek to)
{
return timepoint.DayOfWeek >= from && timepoint.DayOfWeek <= to;
}
-Spacix
All your skynet questions[ ^] belong to solved
I dislike the black-and-white voting system on questions/answers.
|
|
|
|
|
because this doesn't work.
testcase:
timepoint = new DateTime(2008,5,4);//sunday, 0
from = DayOfWeek.Friday; // 5
to = DayOfWeek.Tuesday; // 2
return 0 >= 5 && 0 <= 2;
return value is 'false', but sunday is between friday and tuesday!
|
|
|
|
|
You can use the CultureInfo class to set the first day of the week.
using System.Threading;
Thread.CurrentThread.CurrentCulture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday;
So, set the first day of the week to whatever day you want, and then do your comparison.
protected override bool checkTimepoint(DateTime timepoint, DayOfWeek from, DayOfWeek to)
{
Thread.CurrentThread.CurrentCulture.DateTimeFormat.FirstDayOfWeek = from;
bool inRange = timepoint.DayOfWeek >= from && timepoint.DayOfWeek <= to;
Thread.CurrentThread.CurrentCulture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday;
return inRange;
}
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
modified on Friday, May 2, 2008 1:26 PM
|
|
|
|
|
Huh, interesting.
I wonder how it performs in a loop.
|
|
|
|
|
If performance is an issue (in a loop), you could always wait until the loop is done and reset to the proper 1st day at that point, thus saving n calls to do it in that checkpoint function.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Just thought I'd let you know I was completely wrong.
I posted a new response to the OP with the correct solution.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
What? Say it ain't so!
|
|
|
|
|
return ( true ) ;
Every timepoint falls between some DayOfWeek X and some DayOfWeek Y.
buchstaben wrote: Thursday-Wednesday
Did you mean that?
If you want Sunday to sort higher than Saturday, then you can simply add seven to it, but you'll need to store the values as integers rather than as the provided enum values.
int x = (int) timepoint.DayOfWeek ;
int y = (int) from ;
int z = (int) to ;
x += x==0 ? 7 : 0 ;
y += y==0 ? 7 : 0 ;
z += z==0 ? 7 : 0 ;
return ( x >= y && x <= z ) ;
but that's rather ugly.
|
|
|
|