Problem z result w WFA

0

Witam,

Jestem początkujący i mam problem z funkcją "return" otóż uczę się w Microsoft Visual C# 2010 Express i chciałem zrobić kalkulator w trybie Windows Forms Application. Za pierwszym razem postępowałem zgodnie z tutorialem . Po dwukliknięciu na przycisk i wpisaniu result program w ogóle nie podaje mi result jako dostępnej opcji, a na dole pojawiają się następujące komentarze:
Error 1 Only assignment, call, increment, decrement, and new object expressions can be used as a statement
Error 2 The name 'resut' does not exist in the current context
Error 3 ; expected

Nie rozumiem skąd taki problem ponieważ jak za pierwszym razem robiłem kalkulator wszystko działało, a teraz zaczął pojawiać się problem.

Wybaczcie prozaiczność problemu, ale tak jak wspominałem dopiero zaczynam.

Pozdrawiam i z gory dziękuję za pomoc

0

Nie masz czegoś takiego jak result. Sprawdź, czy ta kontrolka, zmienna, czy co tam na pewno istnieje. Pokaż swój kod, będziemy mogli cokolwiek wywróżyć; nikomu się nie chce oglądać jakiegoś filmiku aby spróbować się domyślić, gdzie popełniłeś błąd.

0

Dziękuję za odpowiedź!

To co napisałeś wystarczyło żebym znalazł problem natomiast teraz mam problem z działaniami matematyczni. Po kliknięciu przycisku dodawania i wybraniu kolejnych cyfr w polu tekstowym zaczynają się wyświetlać pojedyncze cyfry, a nie tak jak wcześniej ich ciąg i dodatkowo operacja dodawania nie działa tzn. po kliknięciu równa się nic się nie dzieje.

Wklejam cały mój kod.
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
Double value = 0;
String operation = ""; //variable - type String name operation
bool operation_pressed = false; // sets variable bool as false

    public Form1()
    {
        InitializeComponent();
       
    

    }

    private void button_Click(object sender, EventArgs e) ///method - double click on a button in forms generates this line of code
                                                          ///which is responsible for what happens after pressing the button
    {
                              
        // result.Text = result.Text + "1"; ///this line creates Text result in TextBox named "result"
                                         ///assigned value result.Text + "1" generates number 1 after every press of the button 1
        if ((result.Text == "0")||(operation_pressed)) ///instruction if - if in TextBox is only 0 leave it 
            result.Clear(); ///if not remove 0 from the beginning

        Button b = (Button)sender; ///Button represents a Button in forms and "b" is assigned as variable.
                                   ///(Button)sender -
        result.Text = result.Text + b.Text; ///result in TextBox is an assigned number of button
        label1.Text = result.Text; //result in Label1 the same like in the result TextBox
    }

    private void button5_Click(object sender, EventArgs e)
    {
        result.Text = "0"; //button5 is a CE button - after pressing that button it clears TextBox
        label1.Text = result.Text;
    }

    private void operator_click(object sender, EventArgs e)
    {
        Button b = (Button)sender;
        operation = b.Text;
        value = Double.Parse(result.Text);
        operation_pressed = true; //after pressing operation button (+,-,*,/, etc.) it prevents from clearing TextBox
    }

    private void button18_Click(object sender, EventArgs e)
    {
        Double value = 0;
        switch (operation)
        {
            case "+":
                result.Text = (value + Double.Parse(result.Text)).ToString();
                break;
            case "-":
                result.Text = (value - Double.Parse(result.Text)).ToString();
                break;
            case "*":
                result.Text = (value * Double.Parse(result.Text)).ToString();
                break;
            case "/":
                result.Text = (value / Double.Parse(result.Text)).ToString();
                break;
            ///case "^":
                ///result.Text = (value ^ Double.Parse(result.Text)).ToString();
                ///break;
            
            ///case "sqrt":
                ///result.Text = (value sqrt Double.Parse(result.Text)).ToString();
                ///break;
        default:
                break; 
        }//switch end 
        operation_pressed = false;
    }

    private void button10_Click(object sender, EventArgs e)
    {
        result.Clear();
        value = 0;
    }

}

}

1 użytkowników online, w tym zalogowanych: 0, gości: 1