Hi,

My code is pretty much complete.

I just need help in 2 things

1) When the program runs the 0 appears, which is fine, but when I type/write a number the Zero would continue next to the number i type/write


2) When i make an operation, such as add/divide/multiplication continuously.
For instance: if i type 1 + 2 and = it will give me 3. However, if i take that 3 and multiply it or divide it at the same time with another operation, the result doesn't appear. the operation gets done, but i cant see the previous answer in the process


PLEASE HELP ME AS SOON AS POSSIBLE

THANK YOU

Public Class frmMain
    'Declare the global variables to be used throughout the form
    Dim mfirst As Single
    Dim msecond As Single
    Dim manswer As Single
    ' Declare the global variables for the operators: Add,Sub,Mul and DIV
    Dim mbutton As Integer
    'Change the sign of the number from + or - or vice versa
    ' Depending on its state now they show in txtNUMBER text box
    Dim Signstate As Boolean

   

    Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        'Put the value 0 into the txtDisplay text box
        txtDisplay.Text = txtDisplay.Text & "0"
    End Sub

    Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
        'Put the value 1 into the txtDisplay text box
        txtDisplay.Text = txtDisplay.Text & "1"
    End Sub

    Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click
        'Put the value 2 into the txtDisplay text box
        txtDisplay.Text = txtDisplay.Text & "2"
    End Sub

    Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click
        'Put the value 3 into the txtDisplay text box
        txtDisplay.Text = txtDisplay.Text & "3"
    End Sub

    Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click
        'Put the value 4 into the txtDisplay text box
        txtDisplay.Text = txtDisplay.Text & "4"
    End Sub

    Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click
        'Put the value 5 into the txtDisplay text box
        txtDisplay.Text = txtDisplay.Text & "5"
    End Sub

    Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click

        txtDisplay.Text = txtDisplay.Text & "6"
    End Sub

    Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click
        txtDisplay.Text = txtDisplay.Text & "7"
    End Sub

    Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click
        txtDisplay.Text = txtDisplay.Text & "8"
    End Sub

    Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click
        txtDisplay.Text = txtDisplay.Text & "9"
    End Sub

    Private Sub btnDot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDot.Click
        txtDisplay.Text = txtDisplay.Text & "."
    End Sub


    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        'User slected the add button
        mbutton = 1
        'Convert into a number and transfer the value from
        'The text box on the form into the first number
        mfirst = Val(txtDisplay.Text)

        txtDisplay.Text = ""
    End Sub

    Private Sub btnSubstract_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubstract.Click

        'User slected the minus button
        mbutton = 2
        'Convert into a number and transfer the value from
        'The text box on the form into the first number
        mfirst = Val(txtDisplay.Text)

        txtDisplay.Text = ""
    End Sub

    Private Sub btnMultiply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMultiply.Click

        'User slected the multiply button
        mbutton = 3
        'Convert into a number and transfer the value from
        'The text box on the form into the first number
        mfirst = Val(txtDisplay.Text)

        txtDisplay.Text = ""
    End Sub

    Private Sub btnDivide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDivide.Click

        'User slected the Divide button
        mbutton = 4
        'Convert into a number and transfer the value from
        'The text box on the form into the first number
        mfirst = Val(txtDisplay.Text)

        txtDisplay.Text = ""
    End Sub

    Private Sub btnEquals_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEquals.Click
        msecond = Val(txtDisplay.Text)

        Select Case mbutton
            Case Is = 1
                manswer = mfirst + msecond
            Case Is = 2
                manswer = mfirst - msecond
            Case Is = 3
                manswer = mfirst * msecond
            Case Is = 4
                manswer = mfirst / msecond
        End Select

        txtDisplay.Text = manswer

    End Sub

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        mbutton = 0
        txtDisplay.Text = "0"

    End Sub

End Class
Member Avatar for Unhnd_Exception

DCYPHER

I ran your code and think it works fine.

You can add this sub to highlight the text in the text box so when you type into it it will reset the previous text.

Private Sub txtDisplay_MouseEnter(ByVal sender As System.Object, ByVal e  as   System.EventArgs) Handles txtDisplay.MouseEnter
        txtDisplay.Focus()
        txtDisplay.SelectAll()
    End Sub

For your second question: I can't get the results your talking of. I can keep addind, subtracting, multiplying, and dividing and it displays the results.

DCYPHER

I ran your code and think it works fine.

You can add this sub to highlight the text in the text box so when you type into it it will reset the previous text.

Private Sub txtDisplay_MouseEnter(ByVal sender As System.Object, ByVal e  as   System.EventArgs) Handles txtDisplay.MouseEnter
        txtDisplay.Focus()
        txtDisplay.SelectAll()
    End Sub

For your second question: I can't get the results your talking of. I can keep addind, subtracting, multiplying, and dividing and it displays the results.

Thanks for replying. I tried what you say, but it doesn't address any of my problems

a)The Zero still appears even when i put the new numbers
b)Perhaps i didn't explain myself better. The problem is that when I type a number and then a sign (either to add or multiply. etc) whatever its on the GUI disappears. The operation still gets solved, but it should not dissapear every time im trying to put a new number to the operation

Member Avatar for Unhnd_Exception

DCYPHER

I changed a couple of things

Combined all your number button functions to 1 function. Set each number buttons tag to the number it represents.

Added a global variable reset.

Removed your txtDisplay.text = "" in your add,subtract,.. function to reset = true

See if this helps

Dim Reset As Boolean

    Private Sub btnX_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn0.Click, btn1.Click, btn2.Click, btn3.Click, btn4.Click, btn5.Click, btn6.Click, btn7.Click, btn8.Click, btn9.Click
        If Reset Then txtDisplay.Text = String.Empty
        If txtDisplay.Text.Length = 1 And txtDisplay.Text = "0" Then txtDisplay.Text = String.Empty

        txtDisplay.Text = txtDisplay.Text & sender.tag

        Reset = False
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        'User slected the add button
        mbutton = 1
        'Convert into a number and transfer the value from
        'The text box on the form into the first number
        mfirst = Val(txtDisplay.Text)
        Reset = True

        ' txtDisplay.Text = ""
    End Sub

    Private Sub btnSubstract_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubtract.Click

        'User slected the minus button
        mbutton = 2
        'Convert into a number and transfer the value from
        'The text box on the form into the first number
        mfirst = Val(txtDisplay.Text)
        Reset = True

        'txtDisplay.Text = ""
    End Sub

    Private Sub btnMultiply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMultiply.Click

        'User slected the multiply button
        mbutton = 3
        'Convert into a number and transfer the value from
        'The text box on the form into the first number
        mfirst = Val(txtDisplay.Text)
        Reset = True

        ' txtDisplay.Text = ""
    End Sub

    Private Sub btnDivide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDivide.Click

        'User slected the Divide button
        mbutton = 4
        'Convert into a number and transfer the value from
        'The text box on the form into the first number
        mfirst = Val(txtDisplay.Text)
        Reset = True

        ' txtDisplay.Text = ""
    End Sub

    Private Sub btnEquals_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEquals.Click
        msecond = Val(txtDisplay.Text)

        Select Case mbutton
            Case Is = 1
                manswer = mfirst + msecond
            Case Is = 2
                manswer = mfirst - msecond
            Case Is = 3
                manswer = mfirst * msecond
            Case Is = 4
                manswer = mfirst / msecond
        End Select

        txtDisplay.Text = manswer

        Reset = True

    End Sub
commented: Always helpful! +11

Thanks again for your time.

I tried what you recommend, but still doesn't work

Now it doesn't appear any number, when i type theres nothing

It does not do the operations, it doesnt work at all, it only gives me zero

Help us to help you.

Members.

Please use feature "Flag Bad Post" to inform the team of moderators about violation of any rule; for example, posting in wrong forum, program code without code-tags, copyright-infringing, fake signatures etc. Read Daniweb Member Rules.

Thanks.

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.