1 Replies - 7147 Views - Last Post: 19 July 2012 - 08:42 PM

#1 nsyamimi90  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 18-July 12

web calculator does not function

Posted 18 July 2012 - 08:07 PM

hye,, i want to ask you all the experts here about my program. Currently im doing a web calculator by using visual studio 2010 with asp.net and im using vb.net. I write my program in asp.net web application. For your information, i am a beginner.

below is my code:


Public Class WebForm1
    Inherits System.Web.UI.Page



    Dim a As Single
    Dim b As Single
    Dim c As String


    Dim mbutton As Integer





   
    Protected Sub btn0_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn0.Click
        txtvalue.Text = txtvalue.Text & "0"
    End Sub

    Protected Sub btn1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn1.Click
        txtvalue.Text = txtvalue.Text & "1"
    End Sub

    Protected Sub btn2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn2.Click
        txtvalue.Text = txtvalue.Text & "2"
    End Sub

    Protected Sub btn3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn3.Click
        txtvalue.Text = txtvalue.Text & "3"
    End Sub

    Protected Sub btn4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn4.Click
        txtvalue.Text = txtvalue.Text & "4"
    End Sub

    Protected Sub btn5_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn5.Click
        txtvalue.Text = txtvalue.Text & "5"
    End Sub

    Protected Sub btn6_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn6.Click
        txtvalue.Text = txtvalue.Text & "6"
    End Sub

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

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

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

    Protected Sub btnplus_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnplus.Click
        mbutton = 1

        lbl3.Text = mbutton

        a = Val(txtvalue.Text)
        lbl1.Text = a

        txtvalue.Text = ""





    End Sub

    Protected Sub btnminus_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnminus.Click
        mbutton = 2
        lbl3.Text = mbutton
        a = Val(txtvalue.Text)
        txtvalue.Text = a


        lbl1.Text = a


        txtvalue.Text = ""
    End Sub

    Protected Sub btnmultiply_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnmultiply.Click
        mbutton = 3
        lbl3.Text = mbutton
        a= Val(txtvalue.Text)
        txtvalue.Text = a

        lbl1.Text = a

        txtvalue.Text = ""

    End Sub

    Protected Sub btndivide_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btndivide.Click
        mbutton = 4
        lbl3.Text = mbutton
        a = Val(txtvalue.Text)
        txtvalue.Text = a


        lbl1.Text = a
        txtvalue.Text = ""

    End Sub

    Protected Sub btnequal_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnequal.Click
        lbl3.Text = mbutton



        b = Val(txtvalue.Text)


        lbl2.Text = b

        Select Case mbutton

            Case "1"


                c = a + b
            Case "2"
                c = a - b
            Case "3"
                c = a * b
            Case "4"
                c = a / b
        End Select

        txtvalue.Text = c







    End Sub

    Protected Sub btnclear_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnclear.Click
        txtvalue.Text = ""
    End Sub

    Protected Sub btndot_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btndot.Click
        txtvalue.Text = "."

    End Sub
End Class




When i run this program, the of mbutton is not saving, so when its happen, it cannot do the select case statement.It seems like the page is refreshing and all the values gone. I hope someone can help me,I have been looking for this problem for about 4 days and i had not found any clue on how to resolve it.

Is This A Good Question/Topic? 0
  • +

Replies To: web calculator does not function

#2 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 444
  • View blog
  • Posts: 1,492
  • Joined: 28-April 09

Re: web calculator does not function

Posted 19 July 2012 - 08:42 PM

One thing to remember about the web is that it is a stateless environment. In general, server variables will not be remembered from one postback to another unless you are storing those values using a persistent method such as ViewState, Session, or Cache. One option would be to store the value in a control on the web page. You could use something like a label, or whatever.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1