|
leppie wrote: The MSIL for a switch is jumptable, not if/else branching.
If you have five or less case labels, the code generated uses if/else logic. You can easily determine this by testing the performance, and see the difference between selecting different values.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Or you could try a Dictionary of delegates. It may at least help with maintenance issues.
|
|
|
|
|
Hi,
i have a Java application that stores a timestamp object as a bigint in a MySql database.
Now, my C# application has to convert it to a DateTime object. How do i do this. I tried using the Datetime.FromFileTime(timestamp); but the output it gives is not correct. Here is the sample.
long tm = 1217404627332;
DateTime dt = DateTime.FromFileTime(tm);
Response.Write("Time: " + dt.ToLongDateString());
The output it gives is Tuesday, January 02, 1601 when it should be Wednesday, July 31, 2008
How do i do this? Any help is appreciated. Thanks in advance.
|
|
|
|
|
One approach would be to search for how the number translates to a date in Java, and write code to do a conversion.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
The Windows FILETIME datatype, and hence .NET's DateTime, counts in 100ns intervals: there are 10 million of them in a single second. The base date is 1 January 1601. Your number, big though it is, only means 121,740 seconds or a little less than 34 hours.
You need to find out how large a time interval one tick represents in your source data, and you need to find out what the base date is, so that you can manipulate it correctly for .NET.
DoEvents: Generating unexpected recursion since 1991
|
|
|
|
|
Java time represents milliseconds since January 1, 1970, so if you account for that date instead of the January 1601 date, you should be OK.
long tm = 1217404627332;
DateTime dt = new DateTime(1970,1,1,0,0,0);
dt = dt.AddMilliseconds(tm);
MessageBox.Show("Time: " + dt.ToLongDateString());
HTH - although I get Wednesday July 30,2008....closer!
-curtisk
|
|
|
|
|
There are three problems i am facing
1. If i specify (1,1) then i should get A1, how can i achieve that.
2. How can i get reference of a particular cell,without using Range class , i want to get cell's forecolor and backcolor directly.
|
|
|
|
|
i have created a winform.but i can't connect it with my database.there are no error has shown but there have 3 warning about path.but i can't find the right path.How can I solve this problem?
|
|
|
|
|
Well, hard to say without knowing what sort of DB it is, and what your warnings are, and what your connection string is.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
Can you Explain Brielfy what you have done and let us see your code that connects to the Database
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
private static string ToDbfFieldTypeString(Type pType)
{
string sResult = "";
try
{
if (pType == typeof(int))
{
sResult = "int";
return sResult;
}
if (pType == typeof(long))
{
sResult = "long";
return sResult;
}
if (pType == typeof(float))
{
sResult = "float";
return sResult;
}
if (pType == typeof(double))
{
sResult = "double";
return sResult;
}
if (pType == typeof(decimal))
{
sResult = "number";
return sResult;
}
if (pType == typeof(bool))
{
sResult = "char(2)";
return sResult;
}
if (pType == typeof(DateTime))
{
sResult = "date";
return sResult;
}
if (pType == typeof(string))
{
sResult = "string";
return sResult;
}
}
catch //(Exception excp)
{
sResult = "";
}
return sResult;
}
-------------------------------------------------------------------
i change the if-else structure to switch structure as follow:
but it tell me to input an integer value at switch();
switch (pType)
{
case typeof(int):
return "int";
case typeof(long):
return "long";
case typeof(float):
return "float";
case typeof(double):
return "double";
case typeof(decimal):
return "number";
case typeof(bool):
return "char(2)";
case typeof(DateTime):
return "date";
case typeof(string):
return "string";
}
So,buddy,could you help me modify the code to compile success?
And tell me what type of value does the switch(?) allow to use? Thanks!
|
|
|
|
|
panyl wrote: but it tell me to input an integer value at switch();
No, it tells you you need an integral type. I googled your error message and found this:
The C# compiler informs us that a switch statement can only take certain integral types. To be more specific, it can take an sbyte, byte, short, ushort, int, uint, long, ulong, char, string, or an enum-type. C# realizes that the switch has received a yyy object and since it cannot convert a yyy into the above integral types, it reports an error.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
A switch statement can take an enum because:
"Every enumeration type has an underlying type, which can be any integral type except char." source MSDN[^]
In your situation this helps because you can use the GetTypeCode() method which returns an enum member.
deciaml d = 0;
switch (d.GetTypeCode())
{
case TypeCode.Decimal:
Console.WriteLine("It's a deciaml");
break;
case TypeCode.Int32:
Console.WriteLine("It's an int");
break;
default:
Console.WriteLine("WTF?");
break;
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
|
Hi Friends,
I have MCTS Exam(70-536 & 70-528) Document and Dumps .
I like upload the file to code project.How to upload the file to codeproject
|
|
|
|
|
That's not what CodeProject is for.
Life, family, faith: Give me a visit.
From my latest post: "The themes and truths of the Jewish holidays follow God's complete plan for this world. They are the root from which Christianity sprang and the historical reasons the church had for leaving them behind were unsound."
Judah Himango
|
|
|
|
|
You need to submit a article first, and then you will see how to add a file to codeproject.
|
|
|
|
|
I have created a project which contains a main window form that spawns a series of new windows forms which are Top most application. Upon creation of each new window the focus stays with the current application( Firefox for example) as desired.
The problem occurs after I close one of the spawned windows using (this.close). The spawned form correctly returns focus to the users application which had focus last. However when the next spawn appears, the focus is taken away and given to this program.
Any Ideas?
|
|
|
|
|
Zocrates wrote: Any Ideas?
Are you still operating forms in multiple threads. My example using timers to create and show a second form still never steals the focus from another application like Notepad. I just keep typing into Notepad while my second form appears on top then, on a timer, closes, then appears again, and closes again.
led mike
|
|
|
|
|
I am no longer using multiple threads. When the timer fires and a second form popups up, close this form, but either do not click on the main form, or have it minimized. When the next fires do you retain focus? This is where the problem is.
|
|
|
|
|
Zocrates wrote: When the next fires do you retain focus? This is where the problem is.
led mike wrote: I just keep typing into Notepad while my second form appears on top then, on a timer, closes, then appears again, and closes again.
As I stated, From Form1 I create and show Form2 as TopMost. Form2 has it's own timer and closes itself. This repeats Three times until finally only Form1 is open, all the while I am typing in Notepad.
led mike
|
|
|
|
|
When you say it closes itself does the app close it? I would like the user to close the form when they are done with it.
|
|
|
|
|
Zocrates wrote: I would like the user to close the form when they are done with it.
Ah, I missed that, yes when I close it (the user) then it produces the problem you have reported when it opens the next time.
This appears to be a Windows Forms behavior because I cannot reproduce the problem in my MFC example.
led mike
|
|
|
|
|
This is weird; I'm assigning a Rectangle to another Rectangle, and the width doesn't change:
viewPortInstance.Bounds = layoutSize;
layoutSize is: {X = 0 Y = 0 Width = 800 Height = 400}
Before the statement is executed, viewPortInstance.Bounds is: {X = 0 Y = 0 Width = 1018 Height = 266}
After the statement, viewPortInstance.Bounds is: {X = 0 Y = 0 Width = 1018 Height = 400} ?!
The width didn't change! (layoutSize is the same.) viewPortInstance is a PictureBox.
I also tried:
viewPortInstance.Bounds = new Rectangle (layoutSize.Location, layoutSize.Size); with the same results.
Then when I looked at layoutSize.Size with QuickWatch, the "value" was: "The runtime has refused to evaluate the expression at this time." Excuse me? I didn't know it had a choice in the matter!
Anyone have any idea what's going on?
|
|
|
|
|
Hi,
Try overriding SetBoundsCore of PictureBox. The Bounds property setter isn't always actually changing the values.
Mika
|
|
|
|