Showing results 1 to 9 of 9

Thread: How to increment a variable on button press

  1. #1
    matholton Gast

    Default How to increment a variable on button press

    Hello,

    Another simple question.

    For testing purposes, I want to be able to toggle a boolean value via a button.
    What are the steps needed to achieve this?

    I have created a variable and a button and a text box that displays the value.

    Cheers,

    mat

  2. #2
    Join Date
    30.05.2007
    Location
    Salzburg
    Posts
    879

    Default Re: How to increment a variable on button press

    For simply toggling a value the best choice would be a "switch" element.

    Dynamic Elements -> Switch


    If you want to use a button you can do this via creating a new function which is linked to the button
    - Functions -> right-click (Function new) -> Variable -> Send value to hardware
    - Select the variable which you want to toggle
    - in the following configuration dialog choose the radio button "TOGGLE"

    Regards,
    Herbert
    Attached Thumbnails Attached Thumbnails SelFunc.jpg  

  3. #3

    Default Re: How to increment a variable on button press

    please note, that the standard textbutton can also function as a switch. Set the appropriate property, and instead of a function, a variable can be linked

    Click image for larger version

Name:	ScreenShot437.jpg
Views:	25
Size:	37.0 KB
ID:	128

  4. #4
    matholton Gast

    Default Re: How to increment a variable on button press

    Thanks fellas,

    I can set a value via a button woot!

    There's still just one thing bugging me: that is the fact that when I click my button a damn dialog appears and I have to 'okay' that before it will carry on!

    thanks,

    mat

  5. #5

    Default Re: How to increment a variable on button press

    you can either use the button as a switch, or set the option "direct to hardware" at the "send value to hardware" function.

  6. #6
    matholton Gast

    Default Re: How to increment a variable on button press

    Excellent, thanks Mark.

    Now, I don't know whether I should start a new thread with this but...

    I now have one button and one text box/display. When I click the button, the text toggles between 1 and 0 - it's linked to a boolean value.

    I want to create 16 of these but I really don't want to copy and paste them. Is there a way to create an array of buttons/textboxes. or can I make a 'usercontrol' containing a button & textbox and then make an array? Or am i stuck with copying and pasting?

    Obviously I want each button/text combo to point to a different boolean.

  7. #7

    Default Re: How to increment a variable on button press

    you can group the two elements to a symbol, and for example put this symbol in the symbol library of the project. From the symbol library you can drag the symbol into your picture, and the variable linked can be replaced, using a replacement string

    (e.g. replace "*1*" with "2")

    The advantage of linked symbols from the symbol library, is that you can centrally modify some properties of the elements, e.g. the color, and this will automatically be taken over in all linked symbols all pictures.

    Additionally, you can exclude single properties from the symbol from this inheritance (e.g. button text or tooltip). This allows for making changes to properties of the linked symbol in the picture itself, without losing the functionality to centrally change other properties.

    The properties can be excluded, when the symbol is opened in the symbol editor.

  8. #8

    Default Re: How to increment a variable on button press

    if you do not want symbols, you can also select both elements, drag them to a new place while holding the ctrl button and drop them to create a copy. Now with the two elements selected, you can right-click and choose "replace links" to replace the variable linked at these elements.

  9. #9
    brandt Gast

    Default Re: How to increment a variable on button press

    You also could take one, give it a name e.g. but_1 and connect it to a variable e.g vab_1. do it a second time with but_2 and vab_2. Export via XML, rename the items in a texteditor, import them back to zenon, place them at the right location, choose all four, export, rename, import and so on an on.

Similar Threads

  1. Replies: 7
    Last Post: 9th July 2014, 15:39
  2. Login/Logout-Button
    By wf-consulting in forum zenon Supervisor
    Replies: 1
    Last Post: 21st September 2008, 10:46
  3. Button Visibility
    By madphilly in forum zenon Supervisor
    Replies: 1
    Last Post: 27th May 2008, 12:23

Posting Rules

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