Cette erreur devrait être simple, mais je ne peux pas sembler le faire fonctionner. Le problème réside dans le fait que ce même code fonctionne plus tôt dans le programme. Je ne vois aucune raison pour que cela envoie une erreur sur cette instance et pas les quatre précédentes. Référence le code ci-dessous, et n'hésitez pas à fournir toute critique que vous pourriez avoir comme elle devrait me rendre meilleur. Si c'est important, j'utilise Sharp Develop 2.2.C#, Opérateur '*' ne peut pas être appliqué à des opérandes de type 'double' et 'décimal'
Voici un exemple du code qui fonctionne:
void calc2Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(tb2_fla.Text) & String.IsNullOrEmpty(tb2_e.Text) | String.IsNullOrEmpty(tb2_fla.Text) & String.IsNullOrEmpty(tb2_e.Text) | String.IsNullOrEmpty(tb2_e.Text))
{
MessageBox.Show("Enter either kVA and Voltage or FLA and Voltage", "Invalid Data Entry", MessageBoxButtons.OK);
}
if (!String.IsNullOrEmpty(tb2_kva.Text) & !String.IsNullOrEmpty(tb2_e.Text))
{
decimal x, y, z;
x = decimal.Parse(tb2_kva.Text);
y = decimal.Parse(tb2_e.Text);
z = (x * 1000)/(1.732050808m * y); //the m at the end of the decimal allows for the multiplication of decimals
tb2_fla.Text = z.ToString();
tb2_fla.Text = Math.Round(z,2).ToString();
}
else
{
if (!String.IsNullOrEmpty(tb2_fla.Text) & !String.IsNullOrEmpty(tb2_e.Text))
{
decimal x, y, z;
x = decimal.Parse(tb2_fla.Text);
y = decimal.Parse(tb2_e.Text);
z = (x * y * 1.732050808m)/1000; //the m at the end of the decimal allows for the multiplication of decimals
tb2_kva.Text = Math.Round(z,2).ToString();
}
Voici l'exemple du code qui envoie l'erreur dans la ligne objet de ce post:
void Calc4Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(tb4_fla.Text) && String.IsNullOrEmpty(tb4_e.Text) || String.IsNullOrEmpty(tb4_kw.Text) & String.IsNullOrEmpty(tb4_e.Text) || String.IsNullOrEmpty(tb4_e.Text))
{ //If values are entered improperly, the following message box will appear
MessageBox.Show("Enter either FLA and Voltage or kW and Voltage", "Invalid Data Entry", MessageBoxButtons.OK);
}
if (!String.IsNullOrEmpty(tb4_fla.Text)&& !String.IsNullOrEmpty(tb4_e.Text)&& String.IsNullOrEmpty(tb4_kw.Text))
{//If the user eneters FLA and Voltage calculate for kW
decimal x, y, z;
x = decimal.Parse(tb4_fla.Text);
y = decimal.Parse(tb4_e.Text);
z = (x*y)*(.8 * 1.732050808m);
tb4_kw.Text = Math.Round(z,0).ToString();
}
if (!String.IsNullOrEmpty(tb4_kw.Text) && !String.IsNullOrEmpty(tb4_e.Text) && String.IsNullOrEmpty(tb4_fla.Text))
{;//If the user enters kW and Voltage calculate for FLA
decimal x, y, z;
x = decimal.Parse(tb4_kw.Text);
y = decimal.Parse(tb4_e.Text);
z = (1000 * x)/(y * 1.732050808m)* .8;
tb4_fla.Text = Math.Round(z,0).ToString();
}
}
Je vous remercie de tout aide que je peux obtenir. Merci.
Merci d'avoir signalé cela. J'espérais secrètement que ce n'était pas si simple. :) –
Que signifie m? – Alex
m oblige le littéral à être interprété comme un nombre décimal. – Broam