By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,795 Members | 1,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,795 IT Pros & Developers. It's quick & easy.

how to clear the value stored in a temporary variable

100+
P: 103
Want to change the value stored in the bold, it's a code to calculate the payroll.

Expand|Select|Wrap|Line Numbers
  1. If txttr.Text = "" Then
  2.   Form2.txttamt.Text = ""
  3.   MsgBox "enter the tax rate", vbOKOnly, "ERROR"
  4.   'Form2.txttamt.Text = ""
  5.   cbostate.SetFocus
  6. Else
  7.   res1 = txttr.Text / 100
  8. End If
  9. rs.Open "Select  * From empdetail Where name =  '" & ListView1.SelectedItem & "' ", conn, adOpenStatic, adLockOptimistic
  10. a = rs!whours
  11. txtoh.Text = Val(txthrs.Text - a)
  12. txtotamt.Text = Val(Form2.txtoh * Form2.txtotrt)
  13. res = Val(Form2.txthrs.Text * Form2.txtrate.Text)
  14. Form2.txttamt.Text = Val(res * res1)
  15. Form2.txtgros.Text = Val((txthrs.Text * txtrate.Text) - (txttamt.Text))
  16. 'str1 = txttr.Text
  17. Form2.txtnsal.Text = Val(Form2.txtgros.Text - Form2.txttamt)
  18. rs.Close
  19. Set rs = Nothing
Solution to this please, thanks in advance.
Dec 19 '07 #1
Share this Question
Share on Google+
9 Replies


jamesd0142
100+
P: 469
Am i understanding this correctly...

variable = "value"

changes the value stored in the variable.

So what can you just do that?
Dec 19 '07 #2

100+
P: 103
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.
Dec 19 '07 #3

debasisdas
Expert 5K+
P: 8,127
You can assign any other value to the variable you want.

BTW what is a temporary variable ?
Dec 19 '07 #4

Expert 5K+
P: 8,434
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.
Dec 19 '07 #5

100+
P: 103
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
Dec 20 '07 #6

100+
P: 103
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
Dec 20 '07 #7

QVeen72
Expert 100+
P: 1,445
Hi,

Before IF Condition, Assign zero to res1 :

Expand|Select|Wrap|Line Numbers
  1. res1 = 0
  2. If txttr.Text = "" Then
  3.   Form2.txttamt.Text = ""
  4.   MsgBox "enter the tax rate", vbOKOnly, "ERROR"
  5.   'Form2.txttamt.Text = ""
  6.   cbostate.SetFocus
  7. Else
  8.   res1 = txttr.Text / 100
  9. End If
  10.  
By the way, what is "User Created Variable"...?

Regards
Veena
Dec 20 '07 #8

Expert 5K+
P: 8,434
...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.
Dec 20 '07 #9

100+
P: 103
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!!!!
Dec 21 '07 #10

Post your reply

Sign in to post your reply or Sign up for a free account.