Changing Arrays and Scheduling

Hello all,

I searched the help and searched this forum but can't find an answer to my question. I'm taking over a project from an employee who moved on and am trying to simplify a lot of the code but am stuck and hope someone here can help.

Setup:
I have an integer array that tracks users actions called UserEvents and it is large enough to accommodate up to 20 users. User0's button presses modify UserEvents[0], User1's button presses modify UserEvents[1], etc. The value that the UserEvents[X] is set to is based on which button on the interface is being pressed. For example: If User0 presses the RUN button UserEvents[[0] is set to 1 ("UserEvents[0]=1").
Whenever UserEvents[X] changes currently, a scheduler sees this change and calls an appropriate script but that means that there are 20 lines in the scheduler to support 20 users and in order to accommodate more users I have to add more lines to the scheduler.

Questions:
1: Can a script be called on the change of an array or only on the change of a member of the array? The same procedures get run whether User1 or User19 activates it, they just need to be tracked separately. This would allow my scheduler to change from 20+ lines to just 1 line that sees a change in the array as a whole.
2: Does Indusoft have a way of tracking which member of an array changed (i.e. UserEvents[].changed = 1 if UserEvents[1] just changed from 1 to 0)

Thanks for your help
  • Unfortunately, there is not a simple way to monitor the change of any value inside of an array.

    Is this a distributed application? i.e. can there be more than one user logged in at a time?

    If not, then you could add a single tag that you would set anytime a UserEvent occurred. Then you would just monitor that one tag for a change (not equal 0, I assume the register gets set back to 0 when it is processed).

    Another option is to bypass the UserEvents tags all together and just call a function to process the event directly.
  • Thanks for your quick response Norman.
    Yes more than one user can be logged in at a time. I would skip the scheduler altogether but when I did that in a previous version of Indusoft it caused memory leaks and crashes due to the multiple users. The memory leaks and crashes were fixed by using the scheduler and while 20 rows for this one thing might not be bad, I was just trying to simplify things for future expansion. If this one thing has to be repeated then so be it.
  • Hi
    you mind if you use 2 arrays with the same capacity (the original and its past shadow)?
    I mean if you dont have trouble killing another set of tags for the past shadow array.
    If not, create the shadow, run a background script that compares the 2 arrays like this:
    First create a global procedure:

    Function ArrayCompare(arr1, arr2)
    Dim counter
    For counter = LBound(arr1) To UBound(arr1)
    If arr1(counter) <> arr2(counter) Then
    ArrayCompare = counter 'function returns the index that the array has the diference
    Exit For
    Else
    ArrayCompare = -1 'function returns -1 that means that arrays are mached
    End If
    Next
    End Function

    Second create a background script with execution 1:

    $YourEventNo = ArrayCompare($YourArray, $YourShadowArray) 'call the comparison function
    $YourShadowArray = $YourArray 'equalize the shadow with the original array


    At last write a schedule on tag Change [YourEventNo], do your stuff and return it to -1 again .

    Of course there are ways not to use shadow tags but its more complicated

    I hope I have helped
  • Sorry, execution must be: $YourEventNo=-1