Results 1 to 2 of 2

Thread: Calculator problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    4

    Calculator problem

    I'm having a small problem with my calculator. I can't seem to find the answer for my question. Somebody help
    When I press add,sub, mul, div, button the number disappears.
    I want to be able to get the number to stay there when I press the + button but it disappears.

    Another problem is when I press equals, I get the right number. But when I put in another number it continues with my previous answer. I have a clear button but I don't want them to have to press. I want to be able to clear the answer and put another number without having to press the clear button.

    --------------------
    Here's my code:

    Public Class Calculator
    Inherits System.Windows.Forms.Form

    Private Calc As Boolean = False
    Private num1, num2 As Double
    Private number As String
    Private answer As Double

    'Number Buttons from 0-9
    Private Sub num1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click, btn2.Click, btn3.Click, btn4.Click, btn5.Click, btn6.Click, btn7.Click, btn8.Click, btn9.Click, btn10.Click
    If (Calc Or (txt1.Text = "0")) Then
    txt1.Text = ""
    End If
    txt1.Text = txt1.Text + CType(sender, Button).Text
    Calc = False
    End Sub

    'The Math Functions (+, -, *, /)
    Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
    num1 = Val(txt1.Text)
    number = "+"
    txt1.Text = ""

    End Sub

    Private Sub btnsub_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsub.Click
    num1 = Val(txt1.Text)
    number = "-"
    txt1.Text = ""

    End Sub

    Private Sub btnast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnast.Click
    num1 = Val(txt1.Text)
    number = "*"
    txt1.Text = " "
    End Sub

    Private Sub btndiv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndiv.Click
    num1 = Val(txt1.Text)
    number = "/"
    txt1.Text = " "
    End Sub

    'The Equal Function (=)
    Private Overloads Sub btnequal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnequal.Click
    num2 = Val(txt1.Text)
    If number = "+" Then answer = num1 + num2
    If number = "-" Then answer = num1 - num2
    If number = "*" Then answer = num1 * num2
    If number = "/" Then answer = num1 / num2
    txt1.Text = answer 'Displays the answer in the TextBox


    End Sub

    Private Sub btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclear.Click
    txt1.Clear() 'Clears the numbers in the TextBox
    End Sub


    End Class
    I know nothing that's why I need your help

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    I dont understand. are you asking for someone to write the code for you, or are you looking for a bug?

    as for the text clearing, you're doing it yourself with txt1.Text = " "
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width