Increase value of variables

Increase value of variables

Hello, I would like to do the next: I have 15 variables (var1...var15) with different values and later I have 2 buttons (but1, but2) to modify all the values according to another variable (var_mod). Not all the time the 15 variables are activated. Depend on the number of other variable: var_active Besides the value of variables from var1 to var15 must be between 0 - 100 and, if we are in 98 and we increase 3, the value should be 1. And if we are in 1 and we decrease 3, the value should be 98. If I introduce in var_mod = 2, in var_active=10 and I press but1: all the variables from var1 to var10 will increase 2; and if I press but2: all the variables from var1 to var10 will decrease 2. If I change var_mod to 3, var_active to 12 and I press but1: all the variables from var1 to var12 will increase 2; and if I press but2: all the variables from var1 to var12 will decrease 2. What I have done is: Create two lefclick. –ne per button. With the next code: --------------------------------------------------------------------------------------------------------------------- Public Sub LeftClickUp_example_pos(obElem As Element) Dim a As Variant Dim i As Variant a = thisProject.Variables.Item("var_mod").value b = thisProject.Variables.Item("var_active").value For i = 1 To b thisProject.Variables.Item("var" & i).value = thisProject.Variables.Item("var" & i).value + a Next End Sub --------------------------------------------------------------------------------------------------------------------- Public Sub LeftClickUp_example_neg(obElem As Element) Dim a As Variant Dim i As Variant a = thisProject.Variables.Item("var_mod").value b = thisProject.Variables.Item("var_active").value For i = 1 To b thisProject.Variables.Item("var" & i).value = thisProject.Variables.Item("var" & i).value - a Next End Sub --------------------------------------------------------------------------------------------------------------------- It works if I do it slow but... if I press very fast the buttons the variables from var1 to var15 do not increase at the same time and, it happens that after 10 fast clicks, some variables have increased one value, another variables another value... What should I do?? Are there another better options??? Thanks a lot R.

This is a migrated post! Originally posted on 20.09.2014 by user rgv0021. Please be aware that information can be outdated.