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.
Disclaimer
This document governs the use of our Community Forum. By registering and using the platform, you accept these conditions.
The COPA-DATA Community Forum serves to encourage the exchange of information and experience about the zenon software between forum users respectively zenon users.
Please mind that any published information on the Community Forum is the subjective opinion and view based on the experience and the level of knowledge of the author. COPA-DATA does not overtake any responsibility for the content and the accuracy of the shared information.
Users of the Community Forum are encouraged to share only well-founded experiences and to point out any risks associated with the implementation of proposed solutions to problems. COPA-DATA at its absolute discretion, reserves the right to moderate the forum. In this connection COPA-DATA may remove any information containing false facts, potentially dangerous solutions, bad language or content that may insult, degrade or discriminate others. COPA-DATA may block a non-complying user from forum access if the user violated this provision.
COPA-DATA reserves the right to change this document from time to time at own discretion.
Ing. Punzenberger COPA-DATA GmbH
Karolingerstraße 7b · 5020 Salzburg · Austria
www.copadata.com