|
I was going to suggest using a masked text box or handling the lose focus event, but others have beat me to it and even provided a solution. One change I would make to Davey's suggestion is to use an ErrorProvider instead of a message box.
/ravi
|
|
|
|
|
Use a DateTimePicker instead.
And always use an ISO 8601 format: yyyy-MM-dd
|
|
|
|
|
PIEBALDconsult wrote: always use an ISO 8601 format: yyyy-MM-dd
You try getting UK users to enter data like that. I wish they would as it makes so much more sense - but they just complain as it's not intuitive for them! I always handle dates that way in code, but for the UI I have to use dd/MM/yyyy.
Dave
|
|
|
|
|
|
Thanks to all for your useful suggestions
|
|
|
|
|
I'm using Visual C#.Net coding
I have an array of bytes
public Byte[] byArrData;
I have to send 15 bytes command. In that 2 bytes( byArrData[4], byArrData[5]) is user input. It will be given as integer and it should be converted to hex and send higher byte first and then the lower byte.
For eg. UserId = 1000. In hex it is '03E8' so byArrData[4] = E8 and byArrData[5] = 03.
byArrData[0] = 0x40;
byArrData[1] = 0x12;
byArrData[2] = 0x00;
byArrData[3] = 0x05;
byArrData[4] = UserIdHigherByte;
byArrData[5] = UserIdLowerByte;
byArrData[6] = 0x00;
byArrData[7] = 0x00;
byArrData[8] = 0x00;
byArrData[9] = 0x00;
byArrData[10] = 0x00;
byArrData[11] = 0x00;
byArrData[12] = 0x70;
byArrData[13] = 0x05;
byArrData[14] = 0x0A;
How should I convert it and send in C#. Please help
|
|
|
|
|
(byte)n;
(byte)(n >> 8);
Write it as it is or you can put it in a loop.
Eslam Afifi
|
|
|
|
|
Can you explain it a bit more. What is n?
|
|
|
|
|
I didn't notice you have named the integer. n is the UserId
Eslam Afifi
|
|
|
|
|
I think this would work:
int num = 1000;
byte one = (byte)(0x00FF & num);
byte two = (byte) ((0xFF00 & num) >> 8);
So, you know 1000 is 03E8.
If you AND this with 0xFF00 then you get left with 0300 we then RIGH SHIFT it by 8 which leaves us with just 03
For the other half we AND the original number with 0x00FF which leaves us with 0x00E8
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
You don't have to AND with 1
Eslam Afifi
|
|
|
|
|
Exception System.OverflowException was thrown in debuggee:
Arithmetic operation resulted in an overflow.
Apparently I do.
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
int n = 1000;
System.Diagnostics.Debug.WriteLine((byte)n);
System.Diagnostics.Debug.WriteLine((n >> 8));
This compiles and runs fine.
Eslam Afifi
|
|
|
|
|
But this doesn't:
int n = 1000;
byte i = (byte)n;
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
No, it does.
int n = 1000;
byte i = (byte)n;
System.Diagnostics.Debug.WriteLine(i);
Eslam Afifi
|
|
|
|
|
Huh, what version of the framework are you using?
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
I targeted 2.0, 3.0 and 3.5 and it works with all of them. I don't know why you got that exception but ANDing with 1 just gives you another integer and it's just an extra operation.
Eslam Afifi
|
|
|
|
|
Weird, actually a byte can only go from 0-255, which is why when I try to cast the int (1000) to a byte I get the overflow exception, since 1000 is too big to fit into 255.
I'm not sure why our results vary but, there it is
EDIT: I am using SharpDevelop, if you're using VS then perhaps it's changing something that SD isn't.
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Well, I've just got that thought. In my Visual Studio, the "Check for arithmetic overflow/underflow" option is not enabled. I'm pretty sure that's the reason. The compiler neglects the overflow (data loss which is fine in this case). But I’m curious; the code you provided does the same (casting from int to byte if I’m not wrong).You're right. ANDing with 1 removes possible overflow.
Eslam Afifi
modified on Monday, June 16, 2008 11:32 PM
|
|
|
|
|
Thanks for all the reply. But I should get the value as
byArrData[4] = E8;
byArrData[5] = 03;
If i do
byArrData[4] = (byte)((unUserID) >> 8);
byArrData[5] = (byte)(unUserID);
I'll get 232 & 03.
How should I get the hex value? Please help
|
|
|
|
|
Actually, everything is represented in binary. A byte is 8 bits an you're storing the values in byte[]
232 is 11101000 in binary. The way you see it (decimal, binary, octal, hexadecimal ...) doesn't matter because it's actually stored in binary.
If you want to get a string representing the value in hexadecimal, use ((byte)(unUserID >> 8)).ToString("X") // this returns a string
Eslam Afifi
|
|
|
|
|
When I tried that "Cannot convert from string to byte" error is coming. Any solution.
|
|
|
|
|
|
I would require the code/methods for detecting different firewalls installed on a system. Though I have done this for Windows Firewall, I would require help in detecting other firewalls installed.
-----Have A Nice Day-----
|
|
|
|
|
I think you can do this with WMI, You should find a reference on that to help you.
See here[^], read the question on "How does Windows Security Center detect third-party products and their status?"
Simon
|
|
|
|