|
Would you mind elaborating a bit Dan ?
|
|
|
|
|
Once you have the decimal value, use String.Format to print the Hex value. For example:
decimal d = 41476521;
string s = String.Format("{0:X}", d);
X --> uppercase A to F letters
x --> lowercase a to f letters
This MUST work
___________________________________
Tozzi is right: Gaia is getting rid of us.
My Blog [ITA]
|
|
|
|
|
No it does not work.....try it:
string sTemp = DateTime.Now.ToString("yyyyMMddHHmmss")+"12345678";
decimal dTemp = Convert.ToDecimal(sTemp);
Console.WriteLine(String.Format("{0:X",dTemp));
|
|
|
|
|
You should use decimal.Parse(sTemp)
The Convert class is not for converting a string into a numeric value.
___________________________________
Tozzi is right: Gaia is getting rid of us.
My Blog [ITA]
|
|
|
|
|
ok, I get the same value as Convert.ToDecimal(sTemp), but regardless I still get an exception when I try and format the decimal value as a Hex string with the "X" format specifier.
|
|
|
|
|
Very odd...
According to MSDN the "X" specifier prints the value in hex format.
The Format method can throw only 2 exceptions: ArgumentNullException (for the string argument) and FormatException (if the format specifiers are not valid).
MSDN tells the "X" specifier is valid only for integral number types, including (in my opinion) the decimal.
If the decimal is not supported (FormatException), the only way I know is to perform a 'manual' conversion to hex. Maybe there are some libs.
You should know how to convert a number to hex. If not, try this:
Perform a serie of divisions to 16, the rest is the hex digit. For example:
--> 315
315 / 16 = 19, rest 11 (B)
19 / 16 = 1, rest 3
1 / 16 = 0, rest 1
(continue until the result of the division becomes zero)
The hex value is 13B (reverse!!!)
___________________________________
Tozzi is right: Gaia is getting rid of us.
My Blog [ITA]
|
|
|
|
|
hi to all,
can some one please tell me why i get
<br />
An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll<br />
<br />
Additional information: Exception has been thrown by the target of an invocation.<br />
for this class, it was working fine until i added the serialization of the ping counter, i tried subclassing the ISerializable in the IPingResponse interface instead but i get the same error
<br />
using System;<br />
using System.Runtime.Serialization;<br />
<br />
<br />
namespace RemotingInterface<br />
{<br />
[Serializable()]<br />
public class PingResponse : ISerializable, IPingResponse<br />
{<br />
private DateTime requestTime;<br />
<br />
private DateTime receiveTime;<br />
<br />
private int pings;<br />
<br />
<br />
#region Serialisation Functions<br />
<br />
public PingResponse(SerializationInfo info, StreamingContext ctxt)<br />
{<br />
this.requestTime = (DateTime)info.GetValue("RequestTime", typeof(DateTime)); <br />
this.receiveTime = (DateTime)info.GetValue("ReceiveTime", typeof(DateTime)); <br />
this.pings = (int)info.GetValue("PingCount", typeof(int)); <br />
}<br />
<br />
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)<br />
{<br />
info.AddValue("RequestTime", this.requestTime);<br />
info.AddValue("ReceiveTime", this.receiveTime);<br />
info.AddValue("PingCount", this.pings);<br />
}<br />
<br />
#endregion Serialisation Functions<br />
<br />
public PingResponse(DateTime request)<br />
{<br />
this.requestTime = request;<br />
}<br />
<br />
<br />
public DateTime ReceiveTime<br />
{<br />
set<br />
{<br />
this.receiveTime = value;<br />
this.pings++;<br />
}<br />
}<br />
<br />
public TimeSpan TransmissionTime<br />
{<br />
get<br />
{<br />
return this.receiveTime - this.requestTime;<br />
}<br />
}<br />
<br />
public int PingCount<br />
{<br />
get<br />
{<br />
return this.pings;<br />
}<br />
}<br />
}<br />
}<br />
kind regards,
g00fy
|
|
|
|
|
You should also tell us when this error is coming (while serialization or deserialization).
I would guess its while deserializing data from an old version of this class (where there was no pings field). Thus the line this.pings = (int)info.GetValue("PingCount", typeof(int)); will fail and the error given comes because the constructor is invoked via reflection.
You should probably put a Try-Catch around this line and anaylze the exception to determine if I'm correct. If yes, then you have to decide what to do when dealing with an old instance (e.g. ignoring it and leaving pings at 0).
|
|
|
|
|
the exception is being thrown from the client code
<br />
namespace SMSRemotingClient<br />
{<br />
internal class ServerStatusChecker<br />
{<br />
private IRemoteData remoteObject;<br />
<br />
internal ServerStatusChecker(IRemoteData remoteObj)<br />
{<br />
this.remoteObject = remoteObj;<br />
}<br />
<br />
internal void CheckStatus()<br />
{<br />
try<br />
{<br />
IPingResponse response = this.remoteObject.Ping(DateTime.Now); <br />
<br />
response.ReceiveTime = DateTime.Now;<br />
<br />
Debug.WriteLine("ping: " + DateTime.Now.ToString("h:mm:ss.fff"));<br />
Debug.WriteLine("ping turn-around: " + response.TransmissionTime.Milliseconds + " millisecs");<br />
Debug.WriteLine("ping count: " + response.PingCount);<br />
}<br />
catch(SocketException se)<br />
{<br />
Debug.WriteLine("its all gone pear-shaped, the server is offline when trying to ping"); <br />
}<br />
catch(RemotingException re)<br />
{<br />
Debug.WriteLine(re.Message);<br />
}<br />
catch(Exception see)<br />
{<br />
Debug.WriteLine(see.Message);<br />
}<br />
}<br />
}<br />
}<br />
see.Message gives
<br />
The type RemotingInterface.PingResponse in Assembly StationUpdateInterface, Version=1.0.2103.19283, Culture=neutral, PublicKeyToken=null is not marked as serializable.<br />
a try catch aarounf the line you suggested gives nothing, the exception is always from the client
|
|
|
|
|
Did you notice that the exception message has totally changed?
The new error means that the PingResponse class (which I assume is written by you) needs to be serialized. Thus you have to mark it with the Serializable attribute. Do this by just writing [Serializable] just above the class definition:
[Serializable]
public class PingResponse {
...
}
Other possibility would be to implement ISerializable in this class but then you would have to serialize it yourself.
|
|
|
|
|
hi Robert,
thank you for your help and patience.
i have the class marked as Serializable and i also implement the ISerializable interface
im not sure what the serializable attribute does, im thinking it just lets the clr know that this class need to be serialized then looks for a way to do it?
anyway this is the top part of my class, and yes i did notice the exception had changed, but i dont know why, all i did was put in the try catch
the rest of the class is just member accessors
<br />
using System;<br />
using System.Runtime.Serialization;<br />
<br />
<br />
namespace RemotingInterface<br />
{<br />
[Serializable]<br />
public class PingResponse : ISerializable, IPingResponse<br />
{<br />
private DateTime requestTime;<br />
<br />
private DateTime receiveTime;<br />
<br />
private int pings;<br />
<br />
<br />
#region Serialisation Functions<br />
<br />
public PingResponse(SerializationInfo info, StreamingContext ctxt)<br />
{<br />
this.requestTime = (DateTime)info.GetValue("RequestTime", typeof(DateTime)); <br />
this.receiveTime = (DateTime)info.GetValue("ReceiveTime", typeof(DateTime)); <br />
<br />
try<br />
{<br />
this.pings = (int)info.GetValue("Pings", typeof(int)); <br />
}<br />
catch(Exception e)<br />
{<br />
Console.WriteLine(e.Message);<br />
}<br />
}<br />
<br />
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)<br />
{<br />
info.AddValue("RequestTime", this.requestTime);<br />
info.AddValue("ReceiveTime", this.receiveTime);<br />
info.AddValue("Pings", this.pings);<br />
}<br />
<br />
#endregion Serialisation Functions<br />
thanks again,
g00fy
|
|
|
|
|
Hi guys
i need help for developeing the graphic component for polar chat. i need some sample code for developing the polar chart??
code is -
//This program graphs the equation r = A * Sin(B * t).
PointF[] objAr;
double t = 0;
int i=0;
double dt = PI / 100;
do
{
objAr=new PointF[i+1];
r = System.Math.Cos(t) * System.Math.Sin(t);
//r = 3*System.Math.Sin(t);
//r = valueA * System.Math.Sin(valueB * t);
if (r>=0)
{
r=System.Math.Sqrt(r);
x = (r * System.Math.Cos(t))+50;
y = (r * System.Math.Sin(t))+50;
}
PointF PointFn=new PointF(Convert.ToSingle(x),Convert.ToSingle(y));
objAr[i]=PointFn;
t = t + dt;
i++;
}while(t <= 2 * PI);
objGraphics.DrawCurve(new Pen(new SolidBrush(Color.Red),2),objAr);
but this code generate only single line not curve according to values.
|
|
|
|
|
Well I think its because you recreate the Point array objAr in every iteration. As you don't seem to know how many points will be in the result I would recommend storing all points in an ArrayList and copying them to an array afterwards:
PointF[] objAr;
double t = 0;
double dt = PI / 100;
ArrayList pointsList = new ArrayList();
do
{
r = System.Math.Cos(t) * System.Math.Sin(t);
if (r>=0)
{
r=System.Math.Sqrt(r);
x = (r * System.Math.Cos(t))+50;
y = (r * System.Math.Sin(t))+50;
}
PointF PointFn=new PointF(Convert.ToSingle(x),Convert.ToSingle(y));
pointsList.Add(PointFn);
t = t + dt;
}while(t <= 2 * PI);
PointF[] objAr = new PointF[pointsList.Count];
pointsList.CopyTo(objAr);
objGraphics.DrawCurve(new Pen(new SolidBrush(Color.Red),2),objAr);
Haven't checked it for correctness but it should at least give you the idea of what I mean.
|
|
|
|
|
Hi guys, I work maintaining a system in C# and I was assigned
to write some code that will take take the credit card number
read by the credit card machine and automatically put that into
a text box in the program so the user doesnt have to manually type
it in once they scan the credit card. We have a NetCom K23P by
tillsmith and I dont know how to go about this. It has an RS232
connector but thats about it. Does any one have experience with this?
Thanks in advanced guys.
-Charles
|
|
|
|
|
.NET 2 makes this a snap using System.IO.Ports u can easily monitor the COM ports
otherwise u could use MSComm COM/OCX control, or use interop
these devices usually only have ASCII text from the reader, not sure about your model
basically u need to monitor the port for activity, when u detect something on the port identify that it is in the correct format, ie., check card track data formats then read the data onto your form.
i created a service to do this that maintains the form status so if a user swipes a card and the form is closed the service re-opens it an populates the form with the data.
the service just runs its own thread to monitor the port, basically blocking on port activity rather than polling the port continuously.
hope that helps,
g00fy
|
|
|
|
|
Thanks so much for your help g00fy! I think I will go
with the simplest way, which would probably be
using .NET 2's System.IO.Ports...
-Charly
|
|
|
|
|
only trouble there is that the beta is timebombed so if its a commercial app you may need to be aware of that. im not sure if only the IDE stops working or if all apps created in it stop as well
hopefully full release of .NET 2 is not far off, its alot better
regs,
g00fy
|
|
|
|
|
Hi
I was wondering if anyone could offer some advice on authenticating a .NET application with LDAP. The code seems to work fine with AD, but fails with LDAP:
(extract)
DirectoryEntry entry = new DirectoryEntry("LDAP://testdomain/DC=testdomain", "testdomain/testuser", textPassword.Text);<br />
<br />
Object obj = entry.NativeObject;<br />
DirectorySearcher search = new DirectorySearcher(entry);<br />
search.Filter = "(SAMAccountName=testuser)";<br />
search.PropertiesToLoad.Add("cn");<br />
SearchResult result = search.FindOne();<br />
<br />
if (null == result)<br />
{<br />
.<br />
.<br />
.<br />
}
The test PC runs on a Windows XP box with .NET Framework 1.1, and is bound to the respective authentication server every time.
The authentication server is a Mac OS X 10.4 server running LDAPv3.
Any suggestions?
|
|
|
|
|
I have a login web page writtin in C#.Net, when the user logs to goes against AD, if that is successful, then it passes the user name and password to an exe that is also written in C#.Net that checks if the user name is sync with our other network applications.
The problem I am having is that user can not have any spaces in there password, if they do it will get chopped of any not sync the correct password to the apps, any ideas on how I can fix this problem?
Thanks
har04mich
|
|
|
|
|
Have a look at the parameters that you are passing. You might try putting quotes around them: "
This will not parse as part of the parameters; but be sure to escape any existing "s appropriately.
By the way, its extremely bad practice passing passwords as command-line parameters: I'd suggest trying to have the password checked by your web app against the domain, and then just passing the user's name itself to your separate application to do whatever it does with it.
|
|
|
|
|
Hi guyz.
I am trying to lock the bits of a gif image which is 32-bit. However, I am getting an invalid parameter on this code :
BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), <br />
ImageLockMode.ReadWrite, PixelFormat.Format32BppArgb);
where b is the bitmap variable in which I load the image in!
Can any body help out on this? because I really have no idea now...since in 24-bit withPixelFormat24BppRgb(bmp + jpg) worked correctly!
To Dare Is To Do
|
|
|
|
|
|
Hello
Why do you think your GIF image is 32-bit ? You can check the PixelFormat property and you will see, that it's Format8bppIndexed .
You can try to use ImageLockMode.ReadOnly mode or lock your image with PixelFormat.Format8bppIndexed or convert your image to 32-bit before (which will be useful if you are planning some image processing routines).
With best regards,
Andrew
|
|
|
|
|
Yep that's actually what I'm trying to do!
To convert to 32-bit from 8 bit index....how?? bcos I really do not know!
Thanks guys
To Dare Is To Do
|
|
|
|
|
Hello.
You can use the next code:
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(bmp);
g.DrawImage(src, 0, 0, width, height);
g.Dispose();
With best regards,
Andrew
|
|
|
|