Laden...

Forenbeiträge von Chipsland Ingesamt 2 Beiträge

13.06.2015 - 12:42 Uhr

Hallo alle zusammen,
heute bin ich bei meinem Währungsrechner wieder einmal auf Kriegsfuß. Ich möchte das, wenn der gleiche Text ausgewählt wurde in den Comboboxen das dann eine MessageBox kommt, und wenn in einem der beiden nichts ausgewählt wurde möchte ich auch das MessageBox kommt. Es wird mir zwar keiner Fehler angezeigt, doch wenn ich probiere ob das nun funktioniert sagt er mir bei :

double Waehrung1 = Convert.ToDouble(textBox1.Text);

"FormatException wurde nicht behandelt. Die Eingabezeichenfolge hat das falsche Format"

Doch ich weiß noch nicht mal was Waerung1 mit den ComboBoxen zu tun hat
Hier mein ganzer Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Währungsrechner
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            
            //Waehrung1 und Ergebnis deklariert
            double Waehrung1 = Convert.ToDouble(textBox1.Text);
            double Ergebnis;



            //Wenn zweimal die selbe Währung ausgewählt wurde zeigt er eine MessageBox
            if (comboBox1.SelectedItem.ToString() == comboBox2.SelectedItem.ToString())
            {
                MessageBox.Show("Sie haben zweimal die gleiche Währung ausgewählt");
            }




            //Wenn ComboBox2 leer ist wird eine MessageBox angezeigt
            if (comboBox2.SelectedItem.ToString() == "")
            {
                MessageBox.Show("Sie haben keine Währung ausgewählt");
            }



            //Wenn ComboBox1 leer ist wird eine MessageBox angezeigt
            if (comboBox1.SelectedItem.ToString() == "")
            {
                MessageBox.Show("Sie haben keine Währung ausgewählt");
            }
            
            //Wenn Euro ausgewählt wurde rechnet er mit dem Wert dem ihm in ComboBox2 zugeteilt wurde
            if (comboBox1.SelectedItem.ToString() == "Euro")
            {
                if (comboBox2.SelectedItem.ToString() == "Dollar")
                {
                    Ergebnis = Waehrung1 * 1.1304;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedItem.ToString() == "Yen")
                {
                    Ergebnis = Waehrung1 * 7.0178;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedItem.ToString() == "JP Yen")
                {
                    Ergebnis = Waehrung1 * 138.8240;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedItem.ToString() == "Russischer Rubel")
                {
                    Ergebnis = Waehrung1 * 61.5894;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedItem.ToString() == "CA Dollar")
                {
                    Ergebnis = Waehrung1 * 1.3870;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
            }


            //Gleicher Vorgang wie vorher (unterschiedlicher Wechselkurs)
            if (comboBox1.SelectedItem.ToString() == "Dollar")
            {
                if (comboBox2.SelectedItem.ToString() == "Euro")
                {
                    Ergebnis = Waehrung1 * 0.8877;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedItem.ToString() == "Yen")
                {
                    Ergebnis = Waehrung1 * 6.2065;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedItem.ToString() == "JP Yen")
                {
                    Ergebnis = Waehrung1 * 123.4111;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedItem.ToString() == "Russischer Rubel")
                {
                    Ergebnis = Waehrung1 * 54.5583502;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedItem.ToString() == "CA Dollar")
                {
                    Ergebnis = Waehrung1 * 1.2279;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
            }


            //Gleicher Vorgang wie vorher (unterschiedlicher Wechselkurs)
            if (comboBox1.SelectedItem.ToString() == "Yen")
            {
                if (comboBox2.SelectedItem.ToString() == "Euro")
                {
                    Ergebnis = Waehrung1 * 0.1430;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedItem.ToString() == "Dollar")
                {
                    Ergebnis = Waehrung1 * 0.1611;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedItem.ToString() == "JP Yen")
                {
                    Ergebnis = Waehrung1 * 19.8841;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedItem.ToString() == "Russischer Rubel")
                {
                    Ergebnis = Waehrung1 * 8.7905;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedItem.ToString() == "CA Dollar")
                {
                    Ergebnis = Waehrung1 * 0.1978;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
            }


            //Gleicher Vorgang wie vorher (unterschiedlicher Wechselkurs)
            if (comboBox1.SelectedItem.ToString() == "JP Yen")
            {
                if (comboBox2.SelectedItem.ToString() == "Euro")
                {
                    Ergebnis = Waehrung1 * 0.0072;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedItem.ToString() == "Dollar")
                {
                    Ergebnis = Waehrung1 * 0.0081;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedItem.ToString() == "Yen")
                {
                    Ergebnis = Waehrung1 * 0.0503;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedItem.ToString() == "Russischer Rubel")
                {
                    Ergebnis = Waehrung1 * 0.4421;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedItem.ToString() == "CA Dollar")
                {
                    Ergebnis = Waehrung1 * 0.0099;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
            }


            //Gleicher Vorgang wie vorher (unterschiedlicher Wechselkurs)
            if (comboBox1.SelectedItem.ToString() == "Russischer Rubel")
            {
                if (comboBox2.SelectedItem.ToString() == "Euro")
                {
                    Ergebnis = Waehrung1 * 0.0163;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedItem.ToString() == "Dollar")
                {
                    Ergebnis = Waehrung1 * 0.0183;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedItem.ToString() == "Yen")
                {
                    Ergebnis = Waehrung1 * 0.1138;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedItem.ToString() == "JP Yen")
                {
                    Ergebnis = Waehrung1 * 2.2620;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedItem.ToString() == "CA Dollar")
                {
                    Ergebnis = Waehrung1 * 0.0225;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
            }


            //Gleicher Vorgang wie vorher (unterschiedlicher Wechselkurs)
            if (comboBox1.SelectedItem.ToString() == "CA Dollar")
            {
                if (comboBox2.SelectedItem.ToString() == "Euro")
                {
                    Ergebnis = Waehrung1 * 0.7229;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedItem.ToString() == "Dollar")
                {
                    Ergebnis = Waehrung1 * 0.8144;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedItem.ToString() == "Yen")
                {
                    Ergebnis = Waehrung1 * 5.0546;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedItem.ToString() == "JP Yen")
                {
                    Ergebnis = Waehrung1 * 100.5071;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedItem.ToString() == "Russischer Rubel")
                {
                    Ergebnis = Waehrung1 * 44.4328;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
            }

        }
    }
}

Würde mich über schnelle Hilfe freuen.

MfG
Chipsland

P.S.: bin noch ziemlich neu beim programmieren mit Windows Forms 😁

10.06.2015 - 22:47 Uhr

Hallo,
ich bin neu hier und hab gleich mal von Anfang an eine Frage 😄.
Ich bin ein blutiger Anfänger und hab derzeit nicht wirklich viel Ahnung. Im Forum hab ich auch nichts passendes gefunden.
Ich arbeite derzeit an einem Währungsrechner in Windows Forms und habe folgendes Problem:
Er will mir einfach nicht das Ergebnis in meine textBox schreiben. Ausserdem wenn ich haben will, dass er mir eine Message gibt wenn ich zum Beispiel in meinen comboBoxen zweimal die gleiche Währung hab sagt er mir:
"Show" ist "Methodengruppe", daher ist die Zuordnung nicht möglich.
Hier mein C#-Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Währungsrechner
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            double Waehrung1 = Convert.ToDouble(textBox2.Text);
            double Ergebnis;

            if (comboBox1.SelectedText == "Euro")
            {
                if (comboBox2.SelectedText == "Euro")
                {
                    MessageBox.Show = "Sie haben zweimal die gleiche Währung ausgewählt";
                }
                else if (comboBox2.SelectedText == "")
                {
                    MessageBox.Show = "Sie haben keine Währung ausgewählt";
                }
            }
            if (comboBox1.SelectedText == "Euro")
            {
                if (comboBox2.SelectedText == "Dollar")
                {
                    Ergebnis = Waehrung1 * 1.1304;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedText == "Yen")
                {
                    Ergebnis = Waehrung1 * 7.0178;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedText == "JP Yen")
                {
                    Ergebnis = Waehrung1 * 138.8240;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedText == "Russischer Rubel")
                {
                    Ergebnis = Waehrung1 * 61.5894;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
                else if (comboBox2.SelectedText == "CA Dollar")
                {
                    Ergebnis = Waehrung1 * 1.3870;
                    textBox2.Text = Convert.ToString(Ergebnis);
                }
            }
        }

        }
    }

hier meine Projektmappe für die die sich das genauer ansehen wollen:

https://www.dropbox.com/s/3bww5lv38gcnepw/W%C3%A4hrungsrechner.rar?dl=0

Ich bedanke mich für jede Hilfe die ich kriegen kann 🙂

MfG
Chipsland