Showing results 1 to 2 of 2

Thread: determining the name of the variable to trigger the function

  1. #1
    Join Date
    13.02.2020
    Posts
    1

    Default determining the name of the variable to trigger the function

    Hello together,

    I would like to know how I can access the name of a variable that caused a function to be started. I have got several boolean variables (import-variables from some sensors) that can either be true of false. I also created internal variables to count how long these sensors are sending a "true"-signal. When they turn "false" again I want to reset that counter. My problem is that I don't know how to archieve that. All these variables refer to one single matrix. So inside that reaction-matrix I want to link a function for the case that the variable turns "false". I dont want to create one matrix for each variable because there are way too many. My idea was to create a function via vba that automatically determines the name of the variable that triggerd the matrix. Then I could use that name to change the value of the related count-variables (which have similar names). Can somebody here please help me with that?

    Public Sub reset_count(obElem As Element)
    Dim countVar As Variable
    Dim sensorVar As Variable

    '[...Code...]

    Set countVar = thisProject.Variables.Item("[...Name from the Code...]")
    Debug.Print countVar.Value
    countVar.Value = 0
    End Sub

    Best regards
    Leon
    Last edited by Leon : 13th February 2020 at 14:48

  2. #2
    Join Date
    10.12.2007
    Posts
    194

    Default AW: determining the name of the variable to trigger the function

    Hi,
    i dont think this is possible with a macro that is called by a function which is triggered by a reactionmatrix. You won't get the variable (name/object).
    Your code is a sub that gets an element as parameter. But what element will you use to call this sub? This only works with e.g. LeftClickUp Macros that are linked to an element. But you don't want to click on a element to call the function but this should happen automatically in the background. Or am i wrong?

    One way to achieve this could be nonlinear value calculation with VBA. In this kind of macros you get the variable-object on value change and can do something with it e.g. call a function or reset a variable according to the variable that changed its value.
    Have a look on Nonlinear Value Calculation and try. Depending on the amount of variables this macro will be linked to it may be not the best way (performance)

    If the variables that you want to watch have similiar names then it is maybe better to create an onlinecontainer and watch the value changes this way.
    Last edited by mst : 14th February 2020 at 09:20

Similar Threads

  1. trigger the Screen type action by variable
    By sgh66 in forum zenon Supervisor
    Replies: 1
    Last Post: 8th November 2019, 11:10
  2. Replies: 3
    Last Post: 23rd October 2013, 22:21
  3. Execute a Function on changes of a Float Variable
    By mcavdar in forum zenon Supervisor
    Replies: 2
    Last Post: 9th January 2013, 13:43
  4. How to trigger a function when a variable changed?
    By denver in forum zenon Supervisor
    Replies: 1
    Last Post: 16th May 2012, 10:12
  5. Replies: 3
    Last Post: 5th April 2011, 09:16

Tags for this Thread

Posting Rules

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