Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Form1 zu Form2

Empfohlene Antworten

Veröffentlicht

Guten morgen,

Hab ein Problem mit meinen Zwei Forms, hab schon alle Artikel durchgeschaut also braucht mir keine links irgendwie hier aus dem Forum schicken. Warscheinlich ein Verständnis Problem oder es fehlt mir was.

Mein Problem, Ich hab zwei Forms einmal Form1 und Ausgabe.

Ich möchte ein BMI Programm schreiben und wenn ich bei Form1 auf Ausrechnen drücke soll er mir das ergebnis in Form Ausgabe im Feld Ergebnis1 anzeigen.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;


namespace BMI

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }


        private void button1_Click(object sender, EventArgs e)

        {


           Ausgabe Ausgabe = new Ausgabe();

           Ausgabe.ShowDialog();


        }


    }

}
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;


namespace BMI

{

    public partial class Ausgabe : Form

    {

        public Ausgabe()

        {

            InitializeComponent();

        }


        private void Ausgabe_Load(object sender, EventArgs e)

        {

            double Gewicht1;

            double Groeße1;

            double Ergebnis1;


            Ergebnis1 = Gewicht1 / (Groeße1 * Groeße1);

        }

    }

}
Fehlermeldung:
Verwendung der nicht zugewiesenen lokalen Variablen "Gewicht1"

Verwendung der nicht zugewiesenen lokalen Variablen "Groeße1"	

Danke im voraus für Antworten.

Hi,

ich weiß zwar nicht woher Du die Werte für Gewicht und Größe nimmst und was genau "Ergebnis1" sein soll, aber ungefähr so sollte das funktionieren:


using eine.ganze.Menge;


 namespace BMI

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }


        private void button1_Click(object sender, EventArgs e)

        {

           double gewicht = double(herkunft.des.gewichts);

           double groesse = double(herkunft.der.groesse);

           Ausgabe Ausgabe = new Ausgabe(gewicht, groesse);

           Ausgabe.ShowDialog();


        }


    }

}
using System;

using eine.ganze.Menge;



namespace BMI

{

    public partial class Ausgabe : Form

    {


        private double Gewicht1;

        private double Groeße1;


        public Ausgabe()

        {

            InitializeComponent();

        }


        public Ausgabe(double gewicht, double groesse)

        {


             InitializeComponent();

             Gewicht1 = gewicht;

             Groeße1 = groesse;

             was.ergebnis1.auch.immer.ist = this.Gewicht1 / (this.Groeße1 * this.Groeße1);


        }


    }

}

Natürlich ist das ungetestet und musst bestimmt noch ne Menge casten und auf gültge Eingaben / Werte prüfen.

Die Fehlermeldung in Deinem Code bekommst Du weil keine der verwendeten Variablen initialisiert wurde.

mfg

realgun

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.