|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Bannato
Iscritto dal: Nov 2002
Città: PV
Messaggi: 1210
|
[C#]Problema con Convertitore
Ho questo cod:
Codice:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace EuroConv
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class FrmPrinc : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtEuro;
private System.Windows.Forms.TextBox txtLire;
private System.Windows.Forms.Button btCalcola;
private System.Windows.Forms.ComboBox select;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public FrmPrinc()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.txtEuro = new System.Windows.Forms.TextBox();
this.txtLire = new System.Windows.Forms.TextBox();
this.btCalcola = new System.Windows.Forms.Button();
this.select = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// txtEuro
//
this.txtEuro.Location = new System.Drawing.Point(296, 8);
this.txtEuro.Name = "txtEuro";
this.txtEuro.Size = new System.Drawing.Size(144, 20);
this.txtEuro.TabIndex = 0;
this.txtEuro.Text = "";
//
// txtLire
//
this.txtLire.Location = new System.Drawing.Point(8, 8);
this.txtLire.Name = "txtLire";
this.txtLire.Size = new System.Drawing.Size(144, 20);
this.txtLire.TabIndex = 2;
this.txtLire.Text = "";
//
// btCalcola
//
this.btCalcola.Location = new System.Drawing.Point(184, 72);
this.btCalcola.Name = "btCalcola";
this.btCalcola.Size = new System.Drawing.Size(88, 24);
this.btCalcola.TabIndex = 1;
this.btCalcola.Text = "Calcola";
this.btCalcola.Click += new System.EventHandler(this.calcola_Click);
//
// select
//
this.select.Items.AddRange(new object[] {
"€ -> &",
"& -> €"});
this.select.Location = new System.Drawing.Point(184, 8);
this.select.Name = "select";
this.select.Size = new System.Drawing.Size(72, 21);
this.select.TabIndex = 3;
//
// FrmPrinc
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(448, 101);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.select,
this.btCalcola,
this.txtLire,
this.txtEuro});
this.Name = "FrmPrinc";
this.Text = "EuroConv";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new FrmPrinc());
}
private void calcola_Click(object sender, System.EventArgs e)
{
double lir = double.Parse(this.txtLire.Text);
double eur = double.Parse(this.txtEuro.Text);
double tot_lire, tot_euro;
int CAMBIO = 1936;
if (this.txtEuro.Text != " " && this.select.Items[0])
{
tot_euro = lir/CAMBIO;
this.txtEuro.Text = tot_euro.ToString();
}
if (this.txtLire.Text != " " && this.select.Items[1])
{
tot_lire = eur*CAMBIO;
this.txtLire.Text = tot_lire.ToString();
}
}
}
}
Come risolvo la clausala dell'if? |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Sep 2000
Messaggi: 886
|
In effetti così a occhio....
this.select.Items[0] questo cos'è?? cosa vuoi dire?
__________________
1986/2008 - 22 anni di rabbia cancellati in un giorno. Adesso passeranno altri 22 anni.. |
|
|
|
|
|
#3 | |
|
Bannato
Iscritto dal: Nov 2002
Città: PV
Messaggi: 1210
|
Quote:
|
|
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Sep 2000
Messaggi: 886
|
Usare una combobox e fare riferimento a SelectedIndex?
__________________
1986/2008 - 22 anni di rabbia cancellati in un giorno. Adesso passeranno altri 22 anni.. |
|
|
|
|
|
#5 | |
|
Bannato
Iscritto dal: Nov 2002
Città: PV
Messaggi: 1210
|
Quote:
P.S: allego il progetto, magari ti serve a capire le cazzate che sto facendo |
|
|
|
|
|
|
#6 |
|
Senior Member
Iscritto dal: Sep 2000
Messaggi: 886
|
Definisci una comboBox e scrivi una istruzione del tipo
if ((this.txtEuro.Text != " ") && (comboBox1.SelectedIndex == 0) ecc...
__________________
1986/2008 - 22 anni di rabbia cancellati in un giorno. Adesso passeranno altri 22 anni.. |
|
|
|
|
|
#7 | |
|
Bannato
Iscritto dal: Nov 2002
Città: PV
Messaggi: 1210
|
ora lo compila ma mi da:
Quote:
|
|
|
|
|
|
|
#8 |
|
Senior Member
Iscritto dal: Sep 2000
Messaggi: 886
|
System.FormatException: Input string was not in a correct format.
E' un problema di cosa gli metti in input...non puoi infilarci dentro, che so io, una 'a' laddove si aspetta un numero, e dal momento che non gestisci le eccezioni, il risultato è un bell'impallamento.
__________________
1986/2008 - 22 anni di rabbia cancellati in un giorno. Adesso passeranno altri 22 anni.. |
|
|
|
|
|
#9 |
|
Bannato
Iscritto dal: Nov 2002
Città: PV
Messaggi: 1210
|
gli do
double tot_lire, tot_euro; in questo modo: this.txtEuro.Text = tot_euro.ToString(); this.txtLire.Text = tot_lire.ToString(); |
|
|
|
|
|
#10 |
|
Senior Member
Iscritto dal: Sep 2000
Messaggi: 886
|
Non è il codice il problema, se compila, è quello che scrivi in input....magari è il separatore dei decimali che è scorretto, oppure metti degli spazi, non lo so, prova prima con degli interi
__________________
1986/2008 - 22 anni di rabbia cancellati in un giorno. Adesso passeranno altri 22 anni.. |
|
|
|
|
|
#11 | |
|
Bannato
Iscritto dal: Nov 2002
Città: PV
Messaggi: 1210
|
Quote:
|
|
|
|
|
|
|
#12 |
|
Senior Member
Iscritto dal: Sep 2000
Messaggi: 886
|
Ragiona: ho visto nel tuo codice
double lir = double.Parse(this.txtLire.Text);// le lire double eur = double.Parse(this.txtEuro.Text);// l\' euro In pratica gli fai parsare i campi textanche se non gli metti nulla in input e il pgm si incavola....infatti se metti un valore significativo in entrambi i campi non ti da + quel problema...come ti ho detto quell'errore è molto chiaro: ti dice che è erata la stringa in input...comprendido?
__________________
1986/2008 - 22 anni di rabbia cancellati in un giorno. Adesso passeranno altri 22 anni.. |
|
|
|
|
|
#13 | |
|
Bannato
Iscritto dal: Nov 2002
Città: PV
Messaggi: 1210
|
Quote:
riempiendo con 0 i campi all'inizio |
|
|
|
|
|
|
#14 |
|
Senior Member
Iscritto dal: Sep 2000
Messaggi: 886
|
Eh, eh, quella può essere una soluzione, o meglio un aggiramento del problema ma sforzati un po' e vedrai che puoi fare di meglio....
__________________
1986/2008 - 22 anni di rabbia cancellati in un giorno. Adesso passeranno altri 22 anni.. |
|
|
|
|
|
#15 | |
|
Bannato
Iscritto dal: Nov 2002
Città: PV
Messaggi: 1210
|
Quote:
Cmq sta settimana ho l'autogestione( |
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 09:57.



















