|
Divide the number by ten, round it and finally multiply with ten:
int x = 15;
x = (int)(Math.Round(x / 10.0) * 10.0);
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
wow you'r really good in c# =O
Sorry i'm new to all this and i don't have much time for learning it...
hmm
<br />
#region Vbar1<br />
<br />
vbar1.Value x = 15;<br />
x = (vbar1.Value)(Math.Round(x / 10.0) * 10.0);<br />
<br />
#endregion<br />
the debugger says vbar1 is a field but it's used like a type @_@
and what's the 15 for?
-- modified at 14:15 Tuesday 14th August, 2007
|
|
|
|
|
okay thanks all for helping me =]
here's the source and exe:
hosted.filefront.com/sylenze
|
|
|
|
|
hi there,
i m doing comparision like this:
if (xmlnode[i].NextSibling.HasChildNodes == true)
to know that is there any further node?
but when this codes is giving error after last node
the error is
Object reference not set to an instance of an object.
anybody knows the solution..?
Becoming Programmer...
|
|
|
|
|
xmen_xwk wrote: xmlnode[i].
Either this is NULL
or
xmen_xwk wrote: xmlnode[i].NextSibling
this is NULL
|
|
|
|
|
what do you mean?
Becoming Programmer...
|
|
|
|
|
Hello,
I guess you have to do an !=null check:
if(xmlnode[i].NextSibling!=null)
All the best,
Martin
|
|
|
|
|
hey yeah its working
thanks dude
Becoming Programmer...
|
|
|
|
|
You are wellcome!
All the best,
Martin
|
|
|
|
|
Hi, I have the following problem:
I have a string of 11 digits.
In my textbox I want to display it like this
###.##.###.###
I tried to set the string.Format("{0:###.##.###.###}", 12345678901)
as result I'd like to see 123.45.678.901, but naturally it doesn't work (probably I've been a little naïve )
Can somebody help me?
|
|
|
|
|
try this
long abc = 12345678901;
textbox1.text = abc.ToString(@"000\.00\.000\.000");
hope it will work
Becoming Programmer...
|
|
|
|
|
You need to use an escape sequence for the '.' characters in the format string so they are treated as literal characters. Otherwise only the first '.' character will be included in the output.
Paul
|
|
|
|
|
yep, i forgot to do that as i wrote codes in codeproject
but i modified it
Becoming Programmer...
|
|
|
|
|
Try this:
long num = 12345678901;
string s = num.ToString(@"###\.##\.###\.###");
Paul
|
|
|
|
|
Another way to do this is with a custom formatter. Try this one:
using System;
using System.Collections.Generic;
using System.Text;
namespace Tester
{
class Program
{
static void Main(string[] args)
{
string item = "012345678901";
Console.WriteLine(string.Format(new CustomStringFormat(), "{0:XD##.####.###.##}", item));
Console.ReadLine();
}
public sealed class CustomStringFormat : IFormatProvider, ICustomFormatter
{
#region IFormatProvider Members
public object GetFormat(Type formatType)
{
if (typeof(ICustomFormatter).Equals(formatType))
return this;
return null;
}
#endregion
#region ICustomFormatter Members
public string Format(string format, object arg, IFormatProvider formatProvider)
{
if (arg == null) throw new ArgumentNullException("arg");
if (format != null && arg is string)
{
string formatSpecifier = format.Trim().ToLower();
if (formatSpecifier.StartsWith("xd"))
{
return FormatWithDot((string)arg, format.Substring(2));
}
}
if (arg is IFormattable)
return ((IFormattable)arg).ToString(format, formatProvider);
return arg.ToString();
}
private string FormatWithDot(string arg, string format)
{
StringBuilder sb = new StringBuilder();
string[] text = format.Split('.');
int lastPos = 0;
foreach (string item in text)
{
string itemtext = arg.Substring(lastPos, item.Length);
if (sb.Length > 0)
sb.Append(".");
sb.AppendFormat("{0}", itemtext);
lastPos += item.Length;
}
return sb.ToString();
}
#endregion
}
}
}
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Why don't you use "MaskedTextBox" standard control?
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you.
|
|
|
|
|
Thank you Michael... This was exactly what I was looking for!
Life is not short... the problem is only how you organize yourself
|
|
|
|
|
Your welcome! Joz.
Dont forget to vote if it's useful for you. thanks.
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you.
|
|
|
|
|
Hi,
I have a form frmA interpreting temp values collected by a second form frmB. Form frmB starts as a thread from frmA. frmB uses a System.Windows.Forms.Timer to collect the data.
If I debug frmA, the timer (and I suppose the whole thread frmB) stops, until frmA continues.
Question: Is there a way to exclude thread frmB from debugging? i.e. if frmA stops due to debugging, frmB collects still data.
Thanks!
Ariadne
|
|
|
|
|
No way to do this, AFAIK.
|
|
|
|
|
Hi,
I would like to use the TreeView control but I would like to modify certain behaviours customized to my app. How do I do it? It would be nice if I can show it up in the "My User Controls" so that I can drag it and dock it appropriately at design time.
TIA!
I am a SysAdmin, I battle my own daemons.
|
|
|
|
|
Basically you need to create a control derived from TreeView .
-- If this is a post that has been helpful to you, please vote for it. Thank you!
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
You can inherit from Treeview control and customize it to make it meet your needs. There are several articles here on codeproject so if you search you'll be able to find them
|
|
|
|
|
Hello!
I want to make a little program that check if a certain port is opened. For example when i run a server that opens the port 234 i want to see if that port is opened. If it is opened then the server is running.
I tryed with some System.net.socket but didn't work...
Thanks in advance
|
|
|
|
|
One way to do it, and I'm not sure if this is the best/most-efficient way, is to try and register a .NET remoting channel on that port. It will throw an exception if the port is in use.
This will work for the local machine.
If you want to see if a port is opened on a remote machine, you'll need to attempt a socket connection to that address and port, or if you're using remoting, attempt connection to a remote object published on that address and port.
|
|
|
|