how to clear the value stored in a temporary variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vbbeginner07
    New Member
    • Dec 2007
    • 103

    how to clear the value stored in a temporary variable

    Want to change the value stored in the bold, it's a code to calculate the payroll.

    Code:
    If txttr.Text = "" Then
      Form2.txttamt.Text = ""
      MsgBox "enter the tax rate", vbOKOnly, "ERROR"
      'Form2.txttamt.Text = ""
      cbostate.SetFocus
    Else
      [B]res1 = txttr.Text / 100[/B]
    End If
    rs.Open "Select  * From empdetail Where name =  '" & ListView1.SelectedItem & "' ", conn, adOpenStatic, adLockOptimistic
    a = rs!whours
    txtoh.Text = Val(txthrs.Text - a)
    txtotamt.Text = Val(Form2.txtoh * Form2.txtotrt)
    res = Val(Form2.txthrs.Text * Form2.txtrate.Text)
    Form2.txttamt.Text = Val(res * res1)
    Form2.txtgros.Text = Val((txthrs.Text * txtrate.Text) - (txttamt.Text))
    'str1 = txttr.Text
    Form2.txtnsal.Text = Val(Form2.txtgros.Text - Form2.txttamt)
    rs.Close
    Set rs = Nothing
    Solution to this please, thanks in advance.
    Last edited by Killer42; Dec 19 '07, 09:06 PM. Reason: Added CODE tag
  • jamesd0142
    Contributor
    • Sep 2007
    • 471

    #2
    Am i understanding this correctly...

    variable = "value"

    changes the value stored in the variable.

    So what can you just do that?

    Comment

    • Vbbeginner07
      New Member
      • Dec 2007
      • 103

      #3
      Originally posted by jamesd0142
      Am i understanding this correctly...

      variable = "value"

      changes the value stored in the variable.

      So what can you just do that?
      It stores a value at the first computation then we are going in for another computation of emp. salary.

      In the meanwhile, res1 stores the value of the first computation. I have to change the res1 to zero for next computation.

      I think you understood it.
      Last edited by Killer42; Dec 19 '07, 09:07 PM.

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        You can assign any other value to the variable you want.

        BTW what is a temporary variable ?
        Last edited by Killer42; Dec 19 '07, 09:08 PM.

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Probably the best thing to do would be to set it to zero when you don't want the value. In other words...

          If textbox not valid
          Set to zero
          Else
          Do calculation
          End If

          Any value you place in the variable will replace what's already there, so you don't need to clear it before using it again.

          Comment

          • Vbbeginner07
            New Member
            • Dec 2007
            • 103

            #6
            Originally posted by Killer42
            Probably the best thing to do would be to set it to zero when you don't want the value. In other words...

            If textbox not valid
            Set to zero
            Else
            Do calculation
            End If

            Any value you place in the variable will replace what's already there, so you don't need to clear it before using it again.
            no actually the value for previous calculation is stored in "res1"

            i have done the same code
            If textbox not valid
            Set to zero
            Else
            Do calculation
            End If


            but that is not working bcos res1 is not a built in variable but a user created so it cant be assigned to 0

            Do check my code In #1

            Comment

            • Vbbeginner07
              New Member
              • Dec 2007
              • 103

              #7
              Originally posted by debasisdas
              You can assign any other value to the variable you want.

              BTW what is a temporary variable ?
              i meant that as a variable that store the mid level calculations.
              hope u have gone thru my code,if not please go thru and suggEST A soln.

              thanks in advance

              Comment

              • QVeen72
                Recognized Expert Top Contributor
                • Oct 2006
                • 1445

                #8
                Hi,

                Before IF Condition, Assign zero to res1 :

                [code=vb]
                res1 = 0
                If txttr.Text = "" Then
                Form2.txttamt.T ext = ""
                MsgBox "enter the tax rate", vbOKOnly, "ERROR"
                'Form2.txttamt. Text = ""
                cbostate.SetFoc us
                Else
                res1 = txttr.Text / 100
                End If
                [/code]

                By the way, what is "User Created Variable"...?

                Regards
                Veena

                Comment

                • Killer42
                  Recognized Expert Expert
                  • Oct 2006
                  • 8429

                  #9
                  Originally posted by Vbbeginner07
                  ...but that is not working bcos res1 is not a built in variable but a user created so it cant be assigned to 0
                  That sentence simply does not make any sense. I think we need to have a bit of a discussion about variable scope and so on.

                  Comment

                  • Vbbeginner07
                    New Member
                    • Dec 2007
                    • 103

                    #10
                    Originally posted by Killer42
                    That sentence simply does not make any sense. I think we need to have a bit of a discussion about variable scope and so on.
                    yeah,let'z start killer!!!!

                    Comment

                    Working...