I'm new at vb.net. i'm making a calculator using only 1 text box and want that my text box show the value( assigned to first variable at run time) along with the operator[+,-,*,/] in upper line and then the value entered in the lower line should be assigned to the second variable and when i press the equal(=) button the required operation should be performed i.e
* add the first variable and the 2nd variable.

I have done a little but it doesn't provide the right answer for example:
* when I enter 3 and click the Add(+) button the cursor goes down in the lower line and
* when i enter 5 and press equal button, text box shows 6 in result instead of 8 and so on. Following is the code

Private Sub ButtonAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonAdd.Click
    Operand1 = Val(TextBox1.Text)
    TextBox1.Text = Operand1 & "+" & Environment.NewLine & Operand2
        TextBox1.Focus()
        [Operator] = "+"
End Sub

Private Sub ButtonEqual_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonEqual.Click
    Dim Result As Double

    Operand2 = Val(TextBox1.Text)
    Select Case [Operator]
        Case "+"
            Result = Operand1 + Operand2
            TextBox1.Text = Result

        Case "-"
            Result = Operand1 - Operand2
            TextBox1.Text = Result
        Case "*"
            Result = Operand1 * Operand2
            TextBox1.Text = Result
        Case "/"
            Result = Operand1 / Operand2
            TextBox1.Text = Result
    End Select
    TextBox1.Text = Result
End Sub

You're assigning the same value to Operand2 as to Operand1. Try this instead: Operand2=Val(TextBox1.Lines(1))

commented: nice +0

Thanxxxxx to tinstaafl!!!
It worked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.