Showing results 1 to 4 of 4

Thread: Accessing Variable property from VBA function call

  1. #1
    Join Date
    21.02.2019
    Posts
    3

    Frage Accessing Variable property from VBA function call

    [Zenon Editor 6.51]

    I'd like to achieve the following, but I'm at a loss;

    When a variable reaches boolean value '1' (via a PLC), I need to execute a VBA macro that will handle a further process. Alas that process needs to know the name of that particular variable.

    A sollution would be to create a seperate function for each variable, and hardcode the string (name) in VBA. But seeing as I need to do this for roughly 1200 variables across different projects I think there could be an easier way. I'd like to have 1 universal VBA macro that could handle it for each variable.

    I could tie in the limit of the variable, a function that executes a VBA macro but somehow I need to parse on the information of the variable name.
    In the latter case I need to access information about the parent object, which is the function caller. I do not know how to do that, or if it's even possible.

    In short: Is it possible to access information of a object caller (in this case a variable) in this way?

    Looking through the forum I don't see a thread about this issue, so I hope someone would be able to elaborate this conundrum for me.


    Many thanks in advance,
    Mitchel
     

  2. #2
    Join Date
    10.12.2007
    Posts
    176

    Default AW: Accessing Variable property from VBA function call

    Have a look at nonlinear value adjusting with vba macro. I think that would be the easiest way to do what you want. You only need to create one macro for all variables (ok you need 2 macros, as it is necessary to define macros for both ways, so you also need a AdjustHardwareValue but there you only have to move the value to the variable). It's signature looks like:
    Public Function AdjustZenonValue_(obVar as Variant, vValue as Variant) As Double

    obVar would be the Variable that triggers the execution
    Last edited by mst : 22nd February 2019 at 08:55 Reason: forgot the second macro

  3. #3
    Join Date
    02.02.2012
    Posts
    10

    Default Re: Accessing Variable property from VBA function call

    Using the nonlinear value adjustment could be a solution, but it is not
    intended to be used this way. The Macro will always be called, if the
    variable is about to get visible in a screen or dialog. If the variable
    is not advised, the macro will not be executed. And as you never should
    start long running operations in VBA, this is even truer for the
    nonlinear value adjustment, because it is executed during rendering your
    screens.

    Instead you should use the class OnlineVariable. It
    contains 2 events, VariableChange and VariableBulkChange, which you
    should use. As you talk about a lot of variables, the VariableBulkChange
    Event is the way to go.

    If you use OnlineVariables, you should
    know how zenon and its object model is working. So if you didn't have
    attended an API training, you should do so first.

    In the Online
    Help of the zenon editor and here in the forum, you could find basic
    examples.
    (Have a look at these: https://forum.copadata.com/search.php?searchid=2068131)

  4. #4
    Join Date
    21.02.2019
    Posts
    3

    Default Re: Accessing Variable property from VBA function call

    Many thanks for your replies and input,

    The nonlinear value adjustment was indeed not applicable in this situation (anyway gratefull for mentioning it).
    I've tried the OnlineVariable class and it works perfectly for my needs (I'd appreciate it), but I have one problem with it.

    The function I'm calling executed a CMD prompt to start a f.t.p. download. This process takes a few seconds to complete.
    And thus the function has to wait (while loop) for it's result to show back to the runtime.

    Calling this function via an object element (e.g. button) allows the runtime to continue running properly.
    But when this function is called via the VariableChange the runtime freezes for that duration.

    It seems like functions executed via an element run like background tasks and function executed via VariableChange run like forground tasks.

    Is there a way for the VariableChange event to be run like a background task, in other words not impede the runtime while executing?


    Many thanks again in advance,
    Mitchel

Similar Threads

  1. Replies: 0
    Last Post: 21st January 2016, 17:25
  2. Call VBA function from another project
    By abcd1234 in forum VBA
    Replies: 1
    Last Post: 6th November 2013, 23:31
  3. Replies: 1
    Last Post: 19th May 2011, 07:51
  4. Changing Iamge BackgroundImage property
    By davide.galigani in forum VBA
    Replies: 1
    Last Post: 1st June 2010, 01:13
  5. Accessing response variable using VBA
    By gz0000 in forum zenon Energy Edition
    Replies: 7
    Last Post: 2nd October 2009, 00:15

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
  •