Showing results 1 to 2 of 2

Thread: Execute VBA macro

  1. #1
    captain Gast

    Default Execute VBA macro

    I need to check a boolean signal then switching another. I use for this purpose VBA macro, but the result while is not present. How to start macro VBA with the function "Execute VBA macro"?

    Public Sub SELECT_ALARM(obElem As Element)
    MsgBox "Hello"
    Set zVAR = thisProject.Variables.Item(obElem.ItemVariable(var 0).Name)
    s_var_close = Left(z_var.Name, InStr(1, z_var.Name, ".") - 1) + ".Close"
    s_cmd = Left(z_var.Name, InStr(1, z_var.Name, ".") - 1) + ".Cmd"
    s_var_open = z_var.Name

    If (thisProject.Variables.Item(s_var_open).Value = 0 And thisProject.Variables.Item(s_var_close).Value = 0) Or (thisProject.Variables.Item(s_var_open).Value = 1 And thisProject.Variables.Item(s_var_close).Value = 1) Then

    thisProject.Variables.Item(s_cmd).Value = 1
    thisProject.Variables.Item(s_cmd).Value = 0
    End If
    End Sub

  2. #2

    Default Re: Execute VBA macro

    I'm not sure what exactly you want to achieve, but I think there may be other ways of sending a value, depending on two other variable values.

    Generally, the zenon function "execute VBA macro" only executes VBA macros, which have no parameters. In zenon 6.50 it will be possible to use VBA macros, and pass parameters to the macro, using the "execute VBA macro" function. Your VBA macro has a parameter (obElem as Element) is most likely to be executed through a VBA event at an element, which passes the Element as an object as a parameter for the VBA macro.

    Please also note, that you are accessing the variable ".Close" and read it's value. If this variable is not advised (not shown in a picture, or defined as alarm, or in an archive, or elsewhere used in a project where it is continually requested from the PLC) your code will fail in versions 6.22 SP0 and higher. It is now no longer possible to do requests in VBA. You should make sure that before accessing e.g. the ".value" property of a variable, the method ".IsOnline" returns true. This is the case, when e.g. this variable is an alarm, or is in an online container in VBA, or has the option "DDE active" set.

    You can find more regarding this topic in this forum and the revision text on the zenon DVD.

Similar Threads

  1. Replies: 1
    Last Post: 11th June 2009, 08:02
  2. How to create a new MACRO?
    By matholton in forum VBA
    Replies: 2
    Last Post: 24th September 2008, 12:14
  3. Start a VBA Macro with PCE
    By mrk in forum VBA
    Replies: 1
    Last Post: 21st March 2008, 17:43

Posting Rules

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