|
The value for System.Threading.ThreadState.Running is 0. 0 & anything is zero. Zero always causing a PITA when doing bitwise comparisons causing a special case. In fact, I do not think you can bitwise a 0. In the set of all real numbers the | on 0 will always return a result. Notice in the documentation on the MSDN, however, that running is a exclusivespecial case that is not bitwiseable with any other case.
The proper code would be
if(myThread.ThreadState == System.Threading.ThreadState.Running){
}
else if(myThread.ThreadState & System.Threading.ThreadState.AnyOtherState == AnyOtherState){
}
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
Hi,
I havn't dealt much with floating numbers / calculation since recently.
Let me explain my issue:
I have the following 3 values declared:
float overallTotalAmps = 0;<br />
int voltage = 230;<br />
int overTotalWatt = 126;
on which I do the following calcluation:
overallTotalAmps = float.Parse((overallTotalWatt / voltage).ToString());
The value of overallTotalAmps always returns 0.00 which should be 0.55 (126 / 230).
Am I using the incorect data type here or perhaps if someone could just point out to me what it is I'm doing wrong here?
Thanks.
R
|
|
|
|
|
You need to cast your int values to float values before you divide them.
|
|
|
|
|
float overallTotalAmps = 0;
int voltage = 230;
int overTotalWatt = 126;
overallTotalAmps = (float)overTotalWatt / (float)voltage;
led mike
|
|
|
|
|
Great stuff!!
Thanks to both of you that replied.
It works perfectly!!!
|
|
|
|
|
Hi,
adding to the other replies:
many problem domains are continuous by nature; if so, you should not use integers at all.
The simplest approach is to make overallTotalAmps , voltage, overTotalWatt, ... all float or double.
That way you don't have to cast, and won't have any rounding errors that may go unnoticed.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
I know you've already got an answer, but I was a bit baffled by the use of ToString and float.parse so I thought I'd give you a rundown of what that actually does
overallTotalWatt / voltage
=> (int)126 / (int)230
=> 0 (since we're dividing ints)
0.ToString() => "0"
float.Parse("0") => 0.00
|
|
|
|
|
Anyone that ToString's a number to parse should be dragged outside and shot.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
Hi Guys. I am having problems with writing data to an Access DB. I keep getting error message "Syntax error in INSERT INTO statement". This is when I try and add a new row to the data table. See below code. The section where it stops is highlighted below.
I'm stumped. Have tried a number of things and nothing works.
public partial class logon : Form
{
OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\database.mdb");
OleDbDataAdapter m_daDataAdapter;
DataTable m_dtPassword = new DataTable();
public logon()
{
InitializeComponent();
}
private void btnCreateUser_Click(object sender, EventArgs e)
{
conn.Open();
m_daDataAdapter =
new OleDbDataAdapter("Select * From [Callcentre]", conn);
OleDbCommandBuilder m_cbCommandbuilder =
new OleDbCommandBuilder(m_daDataAdapter);
m_daDataAdapter.Fill(m_dtPassword);
DataRow drNewRow = m_dtPassword.NewRow();
drNewRow["UserName"] = txtboxUserName.Text;
drNewRow["Password"] = cipherText;
m_dtPassword.Rows.Add(drNewRow);
<code>m_daDataAdapter.Update(m_dtPassword);</code>
m_rowPosition = m_dtPassword.Rows.Count - 1;
}
}
|
|
|
|
|
Kwagga wrote: writing data to an Access DB. I keep getting error message "Syntax error in INSERT INTO statement".
This is the C# forum. Try the SQL / ADO / ADO.NET forum
led mike
|
|
|
|
|
led mike wrote: This is the C# forum
Well, I am wrting C#. Thought you might know but clearly not. Thanks anyway.
|
|
|
|
|
Kwagga wrote: "Syntax error in INSERT INTO statement"
Really?
Kwagga wrote: "Syntax error in INSERT INTO statement"
That error message clearly states the error is an a SQL statement. Thought you might know but clearly not. Good luck.
led mike
|
|
|
|
|
Change the Password field name in the table to something that is not a reserved keyword.
Why aren't you using an insert query directly, instead of fetching everything from the table into a data table just so that you can make the data adapter put together the insert query for you?
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Hi Guy
very easy way, if used OleDbCommand to insert qith ExcuterNonQuery().
and u have done a mistake, dont use password in column name directlly.
DataRow drNewRow = m_dtPassword.NewRow();
drNewRow["UserName"] = txtboxUserName.Text;
drNewRow["Password"] = cipherText;-----This is
i have give two suggestion to u.
1.use the index instead of the column name.
2. if any field came like keyword, use like this drNewRow["[Password]"]
Thanks
Cheers
RRave
MCTS,MCPD
|
|
|
|
|
Thanks guys, I changed the column name to something else and it worked fine. Much appreciated.
|
|
|
|
|
I want to make a program that when executed show a splash screen (while searching for specified files in background) and any keyborad or mouse input is not allowed during this process.
How can i do this please help.
|
|
|
|
|
lifeh2o wrote: any keyborad or mouse input is not allowed during this process.
That sounds a bit odd, why would you want to do that? The user might not like having their system locked while your software is looking for files. Anywho, that will require some P/Invoking of some Win32 API's
I'm going to become rich when I create a device that allows me to punch people in the face over the internet.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
|
|
|
|
|
("The user might not like having their system locked while your software is looking for files")
I m not making it for "users". I just want some practice on stopping keyboard or mouse input. For example when we apply a visual style on windows XP no input is allowed while applying.
I need help.
|
|
|
|
|
Hi all,
How to convert a string value in to a decimal value in c#.net.Any one please suggest me. I dnt knw whether this is ideot thing or not..
for eg string "1.888" in to a decimal value 1.888
Please suggest me a solution
Thanks in advance
Know is Drop, Unknown is Ocean
|
|
|
|
|
Decimal.Parse or Decimal.TryParse
|
|
|
|
|
If you (for some very specific reason) really want a Decimal value, you use the Decimal.Parse method:
Decimal num = Decimal.Parse("1.888");
For most numerical purposes the hardware supported floating point data type Double is the better choice:
Double num = Double.Parse("1.888");
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Convert.ToDecimal("0.1337")
Regards,
Thomas Stockwell
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.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
Can listboxes be linked?
I need to create several listboxes on a form that have their scroll bars related.
At present one listbox will contain commands and another listbox will contain responses.
When either the commands or responses listbox is scrolled the other one should scroll an equal amount.
I may be missing out on the obvious here, any help that points me in the right direction would be gratefully received.
You always pass failure on the way to success.
|
|
|
|
|
There is no inherent listbox linking support
led mike
|
|
|
|
|
Thanks,
I will find some way around this.
Regards
Guy
You always pass failure on the way to success.
|
|
|
|