I was wondering the best way to implement a square root button.
Below has everything from 0-9, the four functions, and a decimal and clear function.

    Dim valueOne As Single
    Dim valueTwo As Single
    Dim operation As Integer
    Dim answer As Single






    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.TextBoxDisplay.Text += "1"

    End Sub


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.TextBoxDisplay.Text += "2"
    End Sub


    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Me.TextBoxDisplay.Text += "3"
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Me.TextBoxDisplay.Text += "4"
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Me.TextBoxDisplay.Text += "5"
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Me.TextBoxDisplay.Text += "6"
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        Me.TextBoxDisplay.Text += "7"
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        Me.TextBoxDisplay.Text += "8"
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        Me.TextBoxDisplay.Text += "9"
    End Sub

    Private Sub Button0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button0.Click
        Me.TextBoxDisplay.Text += "0"
    End Sub

    Private Sub ButtonDecimal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDecimal.Click
        Me.TextBoxDisplay.Text += "."
        Me.ButtonDecimal.Enabled = False




    End Sub
    Friend WithEvents ButtonClear As System.Windows.Forms.Button

    Private Sub ButtonClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonClear.Click
        Me.TextBoxDisplay.Text = " "
        Me.ButtonDecimal.Enabled = True

    End Sub

    Private Sub ButtonAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonAdd.Click
        Me.ButtonDecimal.Enabled = True
        operation = 1
        valueOne = Val(TextBoxDisplay.Text)
        Me.TextBoxDisplay.Text = " "

    End Sub

    Private Sub ButtonSubtract_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSubtract.Click
        Me.ButtonDecimal.Enabled = True
        operation = 2
        valueOne = Val(TextBoxDisplay.Text)
        Me.TextBoxDisplay.Text = " "

    End Sub

    Private Sub ButtonMultiply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonMultiply.Click
        Me.ButtonDecimal.Enabled = True
        operation = 3
        valueOne = Val(TextBoxDisplay.Text)
        Me.TextBoxDisplay.Text = " "

    End Sub

    Private Sub ButtonDivide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDivide.Click
        Me.ButtonDecimal.Enabled = True
        operation = 4
        valueOne = Val(TextBoxDisplay.Text)
        Me.TextBoxDisplay.Text = " "

    End Sub

    Private Sub ButtonCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonCalc.Click
        valueTwo = Val(TextBoxDisplay.Text)

        Me.ButtonDecimal.Enabled = False

        Select Case operation
            Case 1
                answer = valueOne + valueTwo
            Case 2
                answer = valueOne - valueTwo
            Case 3
                answer = valueOne * valueTwo
            Case 4
                answer = valueOne / valueTwo
            Case Else
                Me.TextBoxDisplay.Text = "Error"
        End Select

        Me.TextBoxDisplay.Text = answer


    End Sub

Recommended Answers

All 5 Replies

My first thought is do you have to do this serverside? Have you considered client side javascript? Wut are the requirements for this task?

Hello, I am using Visual Studio 2008 to create an ASP.NET application stand alone, to which then I can save an exe of it then distribute it. No web server involved!
Click Here

Ok that is important to know. I assumed asp.net for web because you created this thread in the Web Development category. Looks like, based on the syntax, you need help with vb.net. I'll flad this post for a moderator to move your thread.

Damn, Im sorry... >.<

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.