431,795 Members | 1,250 Online
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 If txttr.Text = "" Then   Form2.txttamt.Text = ""   MsgBox "enter the tax rate", vbOKOnly, "ERROR"   'Form2.txttamt.Text = ""   cbostate.SetFocus Else   res1 = txttr.Text / 100 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. Dec 19 '07 #1
9 Replies

 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

 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

 Expert 100+ P: 1,445 Hi, Before IF Condition, Assign zero to res1 : Expand|Select|Wrap|Line Numbers res1 = 0 If txttr.Text = "" Then   Form2.txttamt.Text = ""   MsgBox "enter the tax rate", vbOKOnly, "ERROR"   'Form2.txttamt.Text = ""   cbostate.SetFocus Else   res1 = txttr.Text / 100 End If   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