Showing results 1 to 3 of 3

Thread: Increase value of variables

  1. #1
    Join Date
    22.10.2013
    Posts
    14

    Default 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.
    Last edited by rgv0021 : 20th September 2014 at 07:48

  2. #2
    Join Date
    10.12.2007
    Posts
    235

    Default AW: Increase value of variables

    It seems that the LeftClickUp Events can be fired faster than the macro Needs to run.
    Maybe it would be better to call the macro via zenon function than with LeftClickUp. As you don't Need the clicked element and the element is a button, this would be rather easy to check.

  3. #3
    martins Gast

    Default AW: Increase value of variables

    hi,

    sounds like setting the values (or reading them) is causing a performance problem here somehow.

    You could try to have a dummy recipe where you modify the values according to your rule and then execute the recipe. This would probably improve performance.

    Maybe you could even do it without code - I don't really know what the final goal is going to be so I can't say.

    best regards,
    Martin

Similar Threads

  1. Increase/decrease value
    By tihomir in forum zenon Supervisor
    Replies: 4
    Last Post: 28th May 2013, 08:53
  2. PLC Variables and Internal Variables
    By madphilly in forum Drivers
    Replies: 1
    Last Post: 4th June 2008, 06:59

Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •