|
hdv212 wrote: Is there any way to copy assmeblies that registered in GAC to local drive ?
Lets you want to copy System.Data.dll from GAC [ Just for Example ]
Open Command Prompt.
Move to Directory
C:\WINDOWS\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089>
Use DIR
07/04/2009 04:12 PM <DIR> .
07/04/2009 04:12 PM <DIR> ..
07/04/2009 04:12 PM x,xxx,xxx System.Data.dll
1 File(s) x,xxx,xxx bytes
2 Dir(s) xx,xxx,xxx,xxx bytes free
Now use Copy command to copy the System.Data.Dll
cheers,
Abhijit
CodeProject MVP
Web Site:abhijitjana.net
When you ask a question, remember to click "Good Answer", If the Answer is helps you.
|
|
|
|
|
Hello everyone,
2 days ago i bought a relays card wich is controlled by rs232 ComPort.
It works with the suplied software, that's written in visual basic.
But i code in visual c#, so i downloaded visual basic but i have som problem understanding how to convert sertan things from visual basic to c#.
i will post some code and hope someone could help me out, the problem is in a byte buffer, wich wil sent the commands to my serial port.
Send_buffer(0) = 2 ' Get Ports
Send_buffer(1) = 0 ' Broadcast
Send_buffer(2) = 0
Send_buffer(3) = Send_buffer(0) Xor Send_buffer(1) Xor Send_buffer(2)
SerialPort1.Write(Send_buffer, 0, 4)
i know a little bit what is happening here, but i dont know how to use it in c# thanks so far;)
|
|
|
|
|
Okay, the first four lines are arrays. That mean that you can refer to them like you do in VB, but the brackets need to be square [] instead of curly (). XOR is a logical operator, the equivalent in C# is the ^ symbol. The method call is the same. Don't forget the semicolons at the end of every statement
As to what happens on a high level, you simply fill a small array with numbers and send it over a serial port
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Computafreak wrote: instead of curly ().
Parentheses () aren't curly, braces {} are.
|
|
|
|
|
Ah, my terminology is a bit off. To me, () are curly, [] are square, {} are squiggly. Unsurprisingly, I feel rather silly when I talk about programming syntax
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
i now have this:
ArrayList al = new ArrayList();
al[1] = 8;
al[2] = 1;
al[3] = 3;
al[4] = 8 ^ 1 ^ 4;
serialPort1.Open();
serialPort1.Write(al, 0, 4);
serialPort1.Close();
but it returns this error:
Error 2 Argument '1': cannot convert from 'System.Collections.ArrayList' to 'byte[]' C:\Users\Clean Totaal\AppData\Local\Temporary Projects\WindowsFormsApplication1\Form1.cs 31 31 WindowsFormsApplication1
What is going wrong?
|
|
|
|
|
Using your example above try (remember arrays are zero based in c#, not 1):
byte[] ab = new byte[4];
ab[0] = 8;
ab[1] = 1;
ab[2] = 3;
ab[3] = ab[0] ^ ab[1] ^ ab[2];
serialPort1.Open();
serialPort1.Write(ab, 0, 4);
serialPort1.Close();
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Thank YOU its working!!
|
|
|
|
|
byte[] al = new byte [ 4 ] ;
|
|
|
|
|
Here is my Code
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Data.Odbc;
using My;
using System.Data;
namespace FirstCitizensBank_DropOffReport
{
class Program : MyGeneral
{
public static string dataBasePath;
public static string dbname;
public static string strconn;
static void Main(string[] args)
{
StartUp("", "", true);
dataBasePath = ConfigPath + "Empathic\\FirstCit\\";
dbname = "Bank";
strconn = "";
try
{
string repname = dataBasePath + "Reports\\Dropoff" + myDate.ToString("yyyyMMdd") + ".xls";
DateTime enddate = myDate.AddDays(-myDate.Day);
DateTime startdate = enddate.AddDays(1).AddMonths(-1);
MyWriteExcel exl = new MyWriteExcel(repname, dataBasePath + "Reports\\Templates\\DropoffTemp.xls");
enddate = startdate.AddDays(-1);
dbname = "Bank";
dbname = dbname + myDate.AddMonths(-1).ToString("yyMM");
WriteMonth(ref exl, startdate, enddate, "C");
enddate = startdate.AddDays(-1);
startdate = startdate.AddMonths(-2);
dbname = "Bank";
dbname = dbname + myDate.AddMonths(-2).ToString("yyMM");
WriteMonth(ref exl, startdate, enddate, "D");
exl.Save();
exl.Close();
MyEmail email = new MyEmail("", "First Citizens Bank Dropoff Report", "Please see attached report");
email.AddAttachment(repname);
email.AddBCC(CommonEmail);
email.sendEmail();
endProgram();
}
catch (Exception e)
{
WriteToLog("@Failed: " + e.ToString());
HelpPage(e.ToString(), "Failed");
}
}
public static void WriteMonth(ref MyWriteExcel exl, DateTime startdate, DateTime enddate, string column)
{
string sql = "select count(*) as total, sum(iif(mid(CALLSTATUS, 1, 2) >= '06', 1, 0)) as entered, sum(iif(DONE is not null, 1, 0)) as completed"
+ " from " + dbname + " where startdate >= " + startdate.ToString("yyyyMMdd") + " and startdate <= " + enddate.AddMonths(+1).ToString("yyyyMMdd")
+ " and stopdate is not null";
OdbcConnection conn = new OdbcConnection(strconn);
conn.Open();
OdbcCommand cmd = new OdbcCommand(sql, conn);
OdbcDataReader dr = cmd.ExecuteReader();
dr.Read();
int total;
int entered;
int completed;
int abandoned;
if (!(int.TryParse(dr["total"].ToString(), out total) && int.TryParse(dr["entered"].ToString(), out entered) && int.TryParse(dr["completed"].ToString(), out completed)))
{
Exception myex = new Exception("Failed to convert one of the counts to an integer");
throw myex;
}
dr.Close();
dr.Dispose();
abandoned = entered - completed;
sql = "select avg(duration) as avgdur from " + dbname + myDate.AddMonths(-1).ToString("yyMM") + " where startdate >= " + startdate.ToString("yyyyMMdd") + " and startdate <= " + enddate.AddMonths(+1).ToString("yyyyMMdd")
+ " and stopdate is not null and DONE is not null";
cmd.CommandText = sql;
dr = cmd.ExecuteReader();
dr.Read();
double avgcompleted;
if (!double.TryParse(dr["avgdur"].ToString(), out avgcompleted))
{
Exception myex = new Exception("Failed to convert one of the average duration to a double");
throw myex;
}
dr.Close();
dr.Dispose();
sql = "select avg(duration) as avgdur from " + dbname + " where startdate >= " + startdate.ToString("yyyyMMdd") + " and startdate <= " + enddate.AddMonths(+1).ToString("yyyyMMdd")
+ " and stopdate is not null and DONE is null";
cmd.CommandText = sql;
dr = cmd.ExecuteReader();
dr.Read();
double avgdrop;
if (!double.TryParse(dr["avgdur"].ToString(), out avgdrop))
{
Exception myex = new Exception("Failed to convert one of the average duration to a double");
throw myex;
}
dr.Close();
dr.Dispose();
sql = "select callstatus, count(*) as num from " + dbname + " where startdate >= " + startdate.ToString("yyyyMMdd") + " and startdate <= " + enddate.AddMonths(+1).ToString("yyyyMMdd")
+ " and stopdate is not null group by callstatus";
cmd.CommandText = sql;
dr = cmd.ExecuteReader();
int linenum = 3;
exl.WriteCell(column + linenum.ToString() + ":" + column + linenum.ToString(), total);
linenum++;
exl.WriteCell(column + linenum.ToString() + ":" + column + linenum.ToString(), entered);
linenum++;
exl.WriteCell(column + linenum.ToString() + ":" + column + linenum.ToString(), completed);
linenum++;
exl.WriteCell(column + linenum.ToString() + ":" + column + linenum.ToString(), abandoned);
int minutes = ((int)Math.Round(avgcompleted, 0) / 60);
int seconds = ((int)Math.Round(avgcompleted, 0) % 60);
string line = minutes.ToString() + ":" + seconds.ToString();
linenum++;
exl.WriteCell(column + linenum.ToString() + ":" + column + linenum.ToString(), line);
minutes = ((int)Math.Round(avgdrop, 0) / 60);
seconds = ((int)Math.Round(avgdrop, 0) % 60);
line = minutes.ToString() + ":" + seconds.ToString();
linenum++;
exl.WriteCell(column + linenum.ToString() + ":" + column + linenum.ToString(), line);
object[] zerofill = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
exl.WriteRange(column + "11:" + column + "38", zerofill);
while (dr.Read())
{
if (dr["callstatus"].ToString() == "00_SurveyInt")
linenum = 11;
if (dr["callstatus"].ToString() == "01_SurveyCode")
linenum = 12;
if (dr["callstatus"].ToString() == "02_Visit_Date")
linenum = 13;
if (dr["callstatus"].ToString() == "03_Visit_Time")
linenum = 14;
if (dr["callstatus"].ToString() == "04_Purpose_Visit")
linenum = 15;
if (dr["callstatus"].ToString() == "06.1_First_Impres")
linenum = 16;
if (dr["callstatus"].ToString() == "06.2_OV_SatB")
linenum = 17;
if (dr["callstatus"].ToString() == "06.3_OV_RecB")
linenum = 18;
if (dr["callstatus"].ToString() == "06.4_OV_Value")
linenum = 19;
if (dr["callstatus"].ToString() == "06.5_Trans_Time")
linenum = 20;
if (dr["callstatus"].ToString() == "06.5Service")
linenum = 21;
if (dr["callstatus"].ToString() == "06.6_Employee_Pro")
linenum = 22;
if (dr["callstatus"].ToString() == "06.7_Employee_Acc")
linenum = 23;
if (dr["callstatus"].ToString() == "06.8_Employee_Thank")
linenum = 24;
if (dr["callstatus"].ToString() == "06.9_Employee_Sat")
linenum = 25;
if (dr["callstatus"].ToString() == "06.9.1_Employee_WOW")
linenum = 26;
if (dr["callstatus"].ToString() == "06.9.2_Demographics")
linenum = 27;
if (dr["callstatus"].ToString() == "06.9.3_Gender")
linenum = 28;
if (dr["callstatus"].ToString() == "06.9.4_Age")
linenum = 29;
if (dr["callstatus"].ToString() == "07_Draw")
linenum = 30;
if (dr["callstatus"].ToString() == "13_Phone")
linenum = 31;
if (dr["callstatus"].ToString() == "12_Rules")
linenum = 32;
if (dr["callstatus"].ToString() == "11_ContestRules")
linenum = 33;
if (dr["callstatus"].ToString() == "08_Exit_System")
linenum = 34;
if (dr["callstatus"].ToString() == "10_Kicked")
linenum = 35;
if (dr["callstatus"].ToString() == "Repeat")
linenum = 36;
if (dr["callstatus"].ToString() == "Start")
linenum = 37;
if (dr["callstatus"].ToString() == "06_Instruc_1")
linenum = 38;
exl.WriteCell(column + linenum.ToString() + ":" + column + linenum.ToString(), dr["num"]);
}
}
}
}
Here are my expected results
From the first DB
00_SurveyInt 172
01_SurveyCode 641
02_Visit_Date 146
03_Visit_Time 18
04_Purpose_Visit 7
06.1_First_Impres 6
06.2_OV_SatB 64
06.3_OV_RecB 10
06.4_OV_Value 5
06.5Service 2
06.5_Trans_Time 5
06.6_Employee_Pro 14
06.7_Employee_Acc 10
06.8_Employee_Thank 2
06.9.1_Employee_WOW 5
06.9.3_Gender 4
06.9.4_Age 4
06.9_Employee_Sat 3
06_Instruc_1 4
07_Draw 4
08_Exit_System 1360
10_Kick 9
11_ContestRules 3
12_Rules 14
13_Phone 31
Repeat 1
Start 21
and these are the results the process is returning
Survey Intro 172
Survey Entry Code 641
Visit_Date 146
Visit_Time 18
Purpose_Visit 7
First_Impres 6
OV_SatBranch 64
OV_RecBranch 10
OV_Value 5
Trans_Time 5
Service 2
Employee_Pro 14
Employee_Acc 10
Employee_Thank 2
Employee_Sat 3
Employee_WOW 5
Demographics 0
Gender 4
Age 4
Draw 4
Phone 31
Rules 14
Contest Rules 3
Exit System 9
Kicked Out 0
Repeat 1
Start 21
Instructions 4
I cant figure out why these arent matching up if someone could help me identify the problem please.
modified on Thursday, July 23, 2009 1:43 PM
|
|
|
|
|
whwen comparing two strings, you should use the
s1.Equals(s2) . The code s1 == s2 just returns true if they are the same object not the same value.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
|
I was sure that it was the case. I have just chickened and according to Troelsen, == and .equals both compare content.
I think it's wrong, but going by what Luc says below it makes some sort of sense. I have java as well as C#, there it is absolutly == comnpares references and .equals() compares values.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Well .net is better than Java. (duh!)
|
|
|
|
|
PIEBALDconsult wrote: Therefore == == Equals !
|
|
|
|
|
Aren't all strings "interned" in .NET, i.e. two strings holding the same value actually point to a single instance?
[EDIT] No, they are not (see this little article[^]). However, string1==string2 and string.Equals(string1,string2) both call the string.Equals method and generate the correct result no matter what. [/EDIT]
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
modified on Friday, September 4, 2009 1:02 PM
|
|
|
|
|
head is bowed.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Depending on your point of view, fortunately or unfortunately, not all strings in the CLI are interned. Essentially, any string loaded with the MSIL ldstr command is interned, and anything programatically interned is interned. For example, if we run the following code
string interned1 = "hello";
string interned2 = "hello";
string notinterned = new String("hello".ToCharArray());
string interned4 = string.Intern(notinterned);
Console.WriteLine(RuntimeHelpers.GetHashCode(interned1));
Console.WriteLine(RuntimeHelpers.GetHashCode(interned2));
Console.WriteLine(RuntimeHelpers.GetHashCode(notinterned));
Console.WriteLine(RuntimeHelpers.GetHashCode(interned4)); then we get the corresponding output
58225482
58225482
54267293
58225482 As you can see from the output, the interned strings all show the same "memory location" while the programatically constructed string shows a different location.
(.NET 3.5) In terms of string equality, though, the override of operator== calls the public static string.Equals(string, string) method which calls a private static method to determine equality. string.Equals(string) calls the private static method directly.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Ummm .... they both work.
Case in point;
static void Main(string[] args)
{
string strTest1 = "This is a test";
string strTest2 = "This is a second test";
Console.WriteLine("strTest1 == strTest2 : {0}", strTest1 == strTest2);
Console.WriteLine("strTest1 == \"This is a test\" : {0}", strTest1 == "This is a test");
Console.WriteLine("strTest1.Equals(strTest2) : {0}", strTest1.Equals(strTest2));
Console.WriteLine("strTest1.Equals(\"This is a test\") : {0}", strTest1.Equals("This is a test"));
Console.ReadLine();
}
output
strTest1 == strTest2 : False
strTest1 == "This is a test" : True
strTest1.Equals(strTest2) : False
strTest1.Equals("This is a test") : True
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
Hi Nagy,
Nagy Vilmos wrote: s1 == s2 just returns true if they are the same object
as others already told you, this is completely wrong.
I did some investigation, triggered both by this thread and by the lean-and-mean competition, and that resulted in this little article of mine[^].
|
|
|
|
|
Dunno, step through it with the debugger and see what's actually happening.
|
|
|
|
|
I have solved this problem and appreciate all the reply's. The problem was that if a call status came back that wasn't in one of my if statements the program was defaulting to the last line number used since i am not increamenting line numbers.
I am sure this is a rookie mistake and i thank you.
|
|
|
|
|
Yeah, see? Use a switch instead.
|
|
|
|
|
Hi
Is there any way to inject new class to assemby ?
The Reflexil is good tool to assembly manipulation, but it works fine when i change the existing code or add some code to existing method, when i add new class to my assembly by reflexil, the output assembly does not works and throw exception. how can i do that ?
thanks
|
|
|
|
|
Hi guys!
Please help, I am trying to pass data from form1 to form2 using a datagridview cell click event (passing data from datagridview1 in form1 to datagridview2 in form2)
It is working fine if I open form1 and then form2, if I open form2 before form1 then it doesn't because it can't capture instance of form1 to access it.
Here is what I am doing presently:
in Parent (MDI), I have a public form instance for form1, I use that when I open form1 and then pass that instance to form2 when I open it.
This is what I am doing:
In Parent:
public frmGrid1 frm1;
....
//Form1 click event in parent
frm1 = new frmGrid1(m_ADBCnn, 1, notWorkedToolStripMenuItem.Text);
frm1.MdiParent = this;
frm1.Show();
....
//Form2 click event in parent
frm2 = new frmGrid2(frm1,m_ADBCnn,1,presentToolStripMenuItem.Text);
frm2.Show();
frm2.MdiParent = this;
I then assign frm1 in the constructor of form2 as follows:
private frmGrid1 frm1;
public frmGrid2(frmGrid1 f1)
{
try
{
InitializeComponent();
frm1 = f1;
}
catch (Exception ex)
{
MessageBox.Show("Failed on initialization: " + ex.Message);
}
}
Again, this works if I open form1 before form2. How can I retrieve frm1 from frm2 if it is null?
Please help
Sameer
|
|
|
|
|