|
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.
|
|
|
|
|
I am updating an excel spreadsheet using OleDbConnection and OleDbDataAdapter.
This seems to be very quick if the excel file is closed.
Now, I would like to make sure that is the case.
i.e:
if the file is open, then save and then close.
go through the update as it is doing now
open the excel file again.
Question.
How can I check if the file is open?
save and close
and then re-open.
Thanks
|
|
|
|
|
not sure if this will help you or not, but what the hell . . .
If you use the MS Office Interop classes (MSDN 1[^] MSDN 2[^]) there's a property in the Workbook class that might help you. The simplest way of opening an Excel file is
ApplicationClass excelApp = new ApplicationClass();
_Workbook myWorkbook = excelApp.Workbooks.Open(@"C:\test.xls", Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
and then you'll have available the myWorkbook.ReadOnly property that tests several different conditions, one of which is if the file is already open in Excel. If the file is already open or otherwise un-editable then this property will return true and you'll know you have to yell at your user and tell him/her to close it before you can modify it.
|
|
|
|
|
hi i want to set size of form according to system resolution ... how to do that in windows application
Thanks & Regards,
Prashant B. Lavate
Software Engineer
Mobile : +919423872257
Pune(India)
|
|
|
|