Showing results 1 to 5 of 5

Thread: Vba set unit dynamic

  1. #1
    Join Date
    10.12.2010
    Posts
    55

    Default Vba set unit dynamic

    Hi
    Im using the new Unit system, but have a problem regarding dynamically changing unit on a variable.

    We have a page with a number of input fields that can be changed to show different variables, but if I change the Unit of the shown value, the unit will not be correct until I have run the unit switch function again.

    As an example:
    I have the displayVar variable connected to a "numerical value control". If I want to show a variable called myVar, I will do something like this:

    displayVar.Unit = myVar.Unit
    displayVar.value = myVar.value

    My units are configured with °C as base unit and °F as conversion unit

    If myVar has the unit °C it will display correctly, but if I have switched unit to °F, it will still display the value as °C until I press the unit switch function again.

    Is it possible to make a variable update its units without running the unitswitch function again? If I assign SecondaryUnitName to Unit, the unit text will update, but the value will not be scaled.

  2. #2
    martins Gast

    Default AW: Vba set unit dynamic

    hi,

    I am not sure if I understood the problem - the value is written correctly but it is shown incorrectly on the element? You would like to have individual units on each elements?

    The standard zenon behaviour (without any programming) is like this: units are always switched for all variables that have the unit linked.

    best regards,
    Martin

  3. #3
    Join Date
    10.12.2010
    Posts
    55

    Default Re: Vba set unit dynamic

    Hi
    I think that the "problem" is because the unit assignment happens dynamically, and after the unit switch function have been executed. The displayVar variable does not have a unit from the start, and is assigned dynamically depending on which variable we need to show.

    When I update the Unit for the displayed variable, it is not updated (scaling and unit text) until I call the unit switch. I was wondering if there is a way to update a single variable so it will update its scale and unit.

    The reason why I would like to avoid to call the unit scale is that our unit switch function does a lot of work. But if its not a possiblity I will figure something out

  4. #4
    Join Date
    28.04.2015
    Posts
    2

    Default AW: Vba set unit dynamic

    Hi,
    I think i have the same problem.
    The dynamic unit change his value (displayVar.Unit = myVar.Unit) until i switch the picture. When I return to this picture the unit will remain unchanged.
    Is there any solution available?

  5. #5
    Join Date
    19.09.2017
    Posts
    6

    Default Re: Vba set unit dynamic

    I was facing the exactly same problem.

    I solved it by refreshing the page after i changed the Unit dynamically.

    targetVar.Unit = sourceVar.Unit;
    var screen = this.DynPictures().Item("ScreenName");
    if (screen != null)
    screen.UpdateAll();

Similar Threads

  1. Unit conversion - Single unit
    By brc in forum zenon Supervisor
    Replies: 5
    Last Post: 21st February 2013, 23:19
  2. VBA set AVALUE
    By boykooo in forum VBA
    Replies: 6
    Last Post: 30th July 2012, 05:23
  3. Metric / English Unit Conversion HMI
    By jkoehler in forum zenon Supervisor
    Replies: 3
    Last Post: 14th July 2011, 16:52
  4. Online set limitation
    By skywalker in forum zenon Supervisor
    Replies: 3
    Last Post: 24th May 2010, 23:09
  5. Set Value via Drag&Drop (VBA)
    By herberto in forum VBA
    Replies: 0
    Last Post: 4th December 2008, 13:51

Posting Rules

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