Showing results 1 to 9 of 9

Thread: Referencing variable on a picture

  1. #1
    madphilly Gast

    Frage Referencing variable on a picture

    I have a link text element called SerialNo on a Picture called ChordWeld. It is linked to a variable also called SerialNo.

    How do I access that particular variable to change its value using a macro?

  2. #2
    robertf Gast

    Default Re: Referencing variable on a picture

    This depends how you want to execute the macro...

    The best may ist to create a "LeftClickUp" event in the editor (Project-Tree - Scripting - VBA Macros) and link it at the linked text element.

    'In VBA you will get a procedure like this:
    
    Public Sub LeftClickUp_Serial(obElem As Element)
    
    End Sub
    
    
    'To read/write the value of the linked variable you can use a code like this:
    
    Public Sub LeftClickUp_Serial(obElem As Element)
        'returns the actual value of the variable
        Debug.Print obElem.ItemVariable(0).Value
        'sets a new value to the variable
        obElem.ItemVariable(0).Value = 123
    End Sub

  3. #3

    Default Re: Referencing variable on a picture

    please note that some variables are read-only by default. Especially variables from the system-driver, like e.g. the serialnumber being displayed. Check the property window for the variable to see if "set value" is active and try setting a value through a link text element in the runtime first. If this works try using the VBA macro.

    Please note, that when using the .value property of the variable in VBA, this variable must be advised (requested from the driver)

    To permanently advise a variable, either set the option "DDE active" in the variable properties or use an online container in VBA.

  4. #4
    madphilly Gast

    Default Re: Referencing variable on a picture

    I'm no VBA expert by any stretch of the imagination so perhaps I ought to explain what I'm trying to achieve. I am creating an input form to collect production data on a touch screen kiosk. The first and most important part of the form is a product serial number that needs to increment after every completed form is submitted. It also needs to check the last serial number it used from a SQL Table when the picture is opened and increment it. I have some code for the serial number generation but haven't used VBA within zenOn before.

  5. #5
    robertf Gast

    Default Re: Referencing variable on a picture

    How do you open the input form?

    If you want to show the form on clicking the linked text element, you can use the code i posted above...

    You only have to add some code:
    '###########################################################
    '## Code to be added to your form:                        ##
    '###########################################################
    Dim obSerialVar As Variable
    
    Public Sub YourInitProcedure(obVariable As Variable)
        Set obSerialVar = obVariable
    End Sub
    
    '... your existing code ...
        'Read Value:
        Debug.Print obSerialVar.Value
        'Write Value:
        obSerialVar.Value = "NewSerial123"
    '... your existing code ...
    
    '###########################################################
    '## Code to be added to the LeftClickUp Event:            ##
    '###########################################################
    'To forward the Variable-Object to your form:
        UserForm.YourInitProcedure (obElement.ItemVariable(0))
    
    'To open/show the form:
        UserForm.Show

  6. #6
    madphilly Gast

    Rotes Gesicht Re: Referencing variable on a picture

    This macro is not to be based upon a userform, I want to change the data contained in a zenOn picture.

    I have a Picture called 'ChordWeld', on it is a link text element called 'ChordSerial'. I want to assign the value of this link text element via a macro.

    The code to generate the serial number is written and works, I want to put a button on the Picture that executes this macro and assigns the value to the 'ChordSerial' link text element.

  7. #7

    Default Re: Referencing variable on a picture

    I'm not sure if I understand you correctly.

    you could create a new zenOn function "execute VBA macro", select your macro, and link this zenOn function with the textbutton.

  8. #8
    madphilly Gast

    Default Re: Referencing variable on a picture

    That is what I'm trying to do! I have attached a jpg of my picture to show you what it is I'm trying to do.

    I saw a piece of code on here that reads...

    thisProject.Variables.Item("variable name"). Where can I see a list of variables that I can reference/use in VBA??
    Attached Thumbnails Attached Thumbnails SerialPicture.JPG  

  9. #9

    Daumen hoch Re: Referencing variable on a picture

    please send a backup of your zenOn project to: support@copadata.at and I will have a look.

Similar Threads

  1. Create a function for a trend picture
    By robertf in forum VBA
    Replies: 8
    Last Post: 4th October 2018, 14:33
  2. Replies: 7
    Last Post: 9th July 2014, 15:39
  3. additional control elements in a keyboard picture
    By markclemens in forum zenon Supervisor
    Replies: 0
    Last Post: 17th October 2007, 16:25

Posting Rules

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