Autor Beitrag
Stratego
Hält's aus hier
Beiträge: 13



BeitragVerfasst: Do 18.08.11 06:26 
Hallo, ich habe ein sehr einfaches Problem das Programm lässt sich zwar ausführen aber gibt beim berechnen(Taschenrechner) eine Ausnahme weil der Formattyp falsch ist.

Wo ist das Problem?

Vielen Dank schonmal.

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
 private void button2_Click(object sender, EventArgs e)
        {

            int zahl1 = Int32.Parse(button1.Text);
            int zahl2 = Int32.Parse(button2.Text);

            int ergebnis = zahl1 - zahl2;

            label4.Text = Convert.ToString(ergebnis);

        }
Christoph1972
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 690
Erhaltene Danke: 16


VS2015 Pro / C# & VB.Net
BeitragVerfasst: Do 18.08.11 07:08 
Guten Morgen,

wie ist den Text des button1 & button2, da muss dann schon eine Ganzzahl stehen.

_________________
Gruß
Christoph
bakachan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 503
Erhaltene Danke: 34

W7 (x64) Ultimate
C# / VB.NET (VS2010 Ultimate)
BeitragVerfasst: Do 18.08.11 08:09 
Wie mein Vorredner schon sagte wird button1.Text und/oder button2.Text keine gültige Ganzzahl sein.
Verwende am besten int.TryParse statt int.Parse (Programm stürzt nicht ab, der Rückgabewert zeigt dir an ob die Umwandlung erfolgreich war).