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
Parents
  • 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
Reply
  • 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
Children
No Data