Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    [C#]Problema con Convertitore

    Ho sto Cod:
    codice:
    private void calcola_Click(object sender, System.EventArgs e) 
    		{	
    			int lir = int.Parse(this.txtLire.Text);
    			int eur = int.Parse(this.txtEuro.Text);
    			int tot_lire, tot_euro;
    			int CAMBIO = 1936;
    			if (this.txtEuro.Text != " " && this.txtLire.Text != " ")
    			{
    				try
    				{
    					tot_lire = lir*CAMBIO;
    					tot_euro = eur/CAMBIO;
    					this.txtEuro.Text = tot_euro.ToString();
    					this.txtLire.Text = tot_lire.ToString();
    				}catch(System.OverflowException err){
    				this.lbError.Text = err.ToString();
    				}
    	
    			}
    Ma mi da errore;
    La stupidità umana e l'universo sono infinite.
    Della seconda non sono certo(Einstein)

    Gnu/Linux User

  2. #2
    ekko l'errore
    La stupidità umana e l'universo sono infinite.
    Della seconda non sono certo(Einstein)

    Gnu/Linux User

  3. #3
    Utente di HTML.it
    Registrato dal
    Dec 2002
    Messaggi
    173
    Ciao Luc@s, questa volta credo e spero che ti sia di aiuto.
    In pratica te mettevi un evento legato al button calcola che era praticamente globale, nel senso che influiva sia sul txtLire sia sul txtEuro, e quindi se te provavi a mettere un valore in txtLire e lasciavi null il valore di txtEuro il prg voleva eseguire l'operazione con il valore null, che è impossibile e questo genera l'errore.

    Ho modificato un attimo il tuo codice, e così funziona:
    Codice PHP:
    private void btnCalcola_Click(object senderSystem.EventArgs e)
    {
        
    float lir float.Parse(this.txtLire.Text);
                
        
    float tot_lire;
        
    float CAMBIO 1936;

        if (
    this.txtEuro.Text != " ")
        {
            try
            {
                
    tot_lire lir/CAMBIO;
                        
                        
                
    this.txtLire.Text tot_lire.ToString();
          
            }
                
            catch(
    System.OverflowException err)
            {
                
    lbError.Visible=true;
                
    this.lbError.Text err.ToString();
            }
        }
            
    }


    private 
    void btnCalcola2_Click(object senderSystem.EventArgs e)
    {
        
        
    float eur float.Parse(this.txtEuro.Text);
        
    float tot_euro;
        
    float CAMBIO;
        
    CAMBIO 1936;

        if(
    this.txtLire.Text != " ")
        {
            try
            {
                
    tot_euro eur*CAMBIO;
                
    this.txtEuro.Text=tot_euro.ToString();
                    
            }

            catch(
    System.OverflowException err)
            {
                
    lbError.Visible=true;
                
    this.lbError.Text err.ToString();
                
            }
                
        }
            

    Spero che t sia stato effettivamente di aiuto!!!

    CIAO

  4. #4
    tnk!
    La stupidità umana e l'universo sono infinite.
    Della seconda non sono certo(Einstein)

    Gnu/Linux User

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.