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.

Empfohlene Antworten

Veröffentlicht

Hi,

bin seit Gestern von VB auf C# umgestiegen, allerdings mit relativ mäßigem Erfolg (bin auch in VB Anfänger ;)) ...

Im Moment scheitert es an der Umsetzung einer einfachen Funktion:

Der VB-Quellcode:


Private Sub txtBis_Exit()

   Dim a As Single, b As Single

   a=txtZahl1

   b=txtZahl2

   txtErgebnis = Berechne(a, 

End Sub

Function Berechne(x As Single, y As Single) As Single

   Berechne = x - y

End Function

[/code]




Mein C# [b]Versuch [/b]war:

[code] private void txtBis1_Leave(object sender, EventArgs e) { Single a = txtZahl1.Text; Single b = txtZahl2.Text; txtErgebnis.Text = Berechne(a, B); } private Single Berechne(String x, String y) { Berechne = x - y }

Kann mir da jemand beim C#-Code helfen? Danke! :)

private void txtBis1_Leave(object sender, EventArgs e)

{

try

{

int a = Convert.ToInt32(txtZahl1.Text);

}

catch

{

MessageBox.Show("Der Text in txtZahl1 ist keine Zahl!");

}

try {

int b = Convert.ToInt32(txtZahl2.Text);

}

catch

{

MessageBox.Show("Der Text in txtZahl2 ist keine Zahl!");

}

txtErgebnis.Text = Berechne(a, B).ToString();

}

private int Berechne(int x, int y)

{

return x - y;

}

Der Text einer Textbox ist vom Typ string. Als erstes wandle ich diesen in eine Zahl (int) um. Sollte dies nicht möglich sein wird eine Meldung ausgegeben. Nachdem die Funktion Berechne die berrechnung durchgeführt hat wird das ergebniss zurückgegeben. Und da der Text der Textbox string sein muss wandlen wir die Zahl nun zurück nach string (mit ToString).

Code Ungetestet.

Möchtest du dem Nutzer noch die Möglichkeit geben, andere Zahlen als Ganzzahlen eingeben zu können?

Ok, vielen Dank damit komm ich schon mal weiter. ;)

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

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.