Page 1 of 3 1 2 3 LastLast
Showing results 1 to 10 of 21

Thread: Edit variable in Editor from VBA

  1. #1
    Join Date
    23.11.2012
    Posts
    33

    Default Edit variable in Editor from VBA

    Hello!

    Help me, please!
    How do I edit variable in Editor from VBA?

  2. #2
    Join Date
    18.07.2011
    Posts
    136

    Default AW: Edit variable in Editor from VBA

    Hi Natali.

    Please have a look into our help. In Manual -> Programming interface -> Object model -> Variable / Variables you will find an explanation of the objects as well as example code. I'm pretty sure that you will find the functionality you are looking for in the example code.

    Sub CreateVariable()
    
    Dim zVariables As Variables 'Object from type Variables
    Dim zVariable As Variable 'Child object from type Variables
    Dim zDrivers As Drivers 'Object from type Drivers
    Dim zVarTypes As VarTypes 'Object from type VarTypes
    Dim zEdLimit As EdLimit 'Object from type EdLimit
    
    'Fill the objects
    Set zVariables = MyWorkspace.ActiveDocument.Variables
    Set zDrivers = MyWorkspace.ActiveDocument.Drivers
    Set zVarTypes = MyWorkspace.ActiveDocument.VarTypes
    
    'Create a "intern driver" variable called "TestVariable" with object type "internal variable" and datatype "INT"
    Set zVariable = zVariables.CreateVar("TestVariable", zDrivers.Item(0), 33, zVarTypes.Item("INT"))
    'Create a limit at the "TestVariable"
    zVariable.CreateEdLimit
    
    'Select the first limit of the variable
    Set zEdLimit = zVariable.EDLimitItem(0)
    'Set the limit active
    zEdLimit.Active = True
    'Set limit text
    zEdLimit.Text = "Limit reached"
    'Set limit value to 10
    zEdLimit.LimitValue = 10
    'Set the limit as maximum
    zEdLimit.IsMax = True
    'Set the limit as alarm
    zEdLimit.Alarm = True
    'Limit should be recognized in the CEL
    zEdLimit.Cel = True
    
    Call CreateArrayVariable
    
    End Sub
    
    Sub CreateArrayVariable()
    
    Dim zVariables As Variables 'Object from type Variables
    Dim zVariable As Variable 'Child object from type Variables
    Dim zArrEl As Variable 'Object from type Variables
    Dim zEdLimit As EdLimit 'Object from type EdLimit
    Dim i As Integer
    
    'Fill the objects
    Set zVariables = MyWorkspace.ActiveDocument.Variables
    Set zDrivers = MyWorkspace.ActiveDocument.Drivers
    Set zVarTypes = MyWorkspace.ActiveDocument.VarTypes
    
    'Create a "intern driver" array variable called "ArrayVar" from object type "internal variable", datatype "INT", start at index 1,
    'dimension of 5 and automatic addressing
    Set zVariable = zVariables.CreateArrayVar("ArrayVar", zDrivers.Item(0), 33, zVarTypes.Item("INT"), 1, 5, 0, 0, True, False, False)
    
    'Activate all array elements
    For i = 0 To 4
        zVariable.ActivateSubItem (i)
    Next i
    
    'Read the first array element
    Set zArrEl = zVariable.SubItem(0)
    'Create a limit at the array element
    zArrEl.CreateEdLimit
    
    'Select the first limit of the variable
    Set zEdLimit = zArrEl.EDLimitItem(0)
    'Set the limit active
    zEdLimit.Active = True
    'Set limit text
    zEdLimit.Text = "Limit reached"
    'Set limit value to 10
    zEdLimit.LimitValue = 10
    'Set the limit as maximum
    zEdLimit.IsMax = True
    'Set the limit as alarm
    zEdLimit.Alarm = True
    'Limit should be recognized in the CEL
    zEdLimit.Cel = True
    
    End Sub

  3. #3
    Join Date
    23.11.2012
    Posts
    33

    Default Re: AW: Edit variable in Editor from VBA

    Thank you.
    I saw it. But I have a error in "Set zVariables = MyWorkspace.ActiveDocument.Variables"

    run-time error '91':
    Object variable or With block variable not set

  4. #4
    Join Date
    20.08.2009
    Posts
    293

    Default Re: Edit variable in Editor from VBA

    Hi,

    what exactly do you want to do?
    Are you executing this code in the Runtime?

    Regards,
    Bernhard

  5. #5
    Join Date
    23.11.2012
    Posts
    33

    Default Re: Edit variable in Editor from VBA

    Quote Originally Posted by bernhardf View Post
    Hi,

    what exactly do you want to do?
    Are you executing this code in the Runtime?

    Regards,
    Bernhard
    Yes, in Runtime!
    I want change TagName.
    Thank you.

  6. #6
    josefm Gast

    Default Re: Edit variable in Editor from VBA

    Hi,

    as far as I know you cannot change the TagName during runtime. This is only possible in the editor for the manipulation of variables.


    Best regards

  7. #7
    Join Date
    23.11.2012
    Posts
    33

    Default Re: Edit variable in Editor from VBA

    Quote Originally Posted by josefm View Post
    Hi,

    as far as I know you cannot change the TagName during runtime. This is only possible in the editor for the manipulation of variables.


    Best regards
    If this is true, it is very sad

  8. #8
    Join Date
    18.07.2011
    Posts
    136

    Default AW: Edit variable in Editor from VBA

    You can check if a object is changeable in the runtime using the zenon help. If it says "available" the object can be read and changed. If it says "read only" you cannot change it. Attached you will find the screenshot of the zenon help for the variable tagname, as you see it can only be read from the runtime.
    Attached Thumbnails Attached Thumbnails 2013-01-28_12h57_13.png  

  9. #9
    Join Date
    23.11.2012
    Posts
    33

    Default Re: AW: Edit variable in Editor from VBA

    Quote Originally Posted by johannes.foidl View Post
    You can check if a object is changeable in the runtime using the zenon help. If it says "available" the object can be read and changed. If it says "read only" you cannot change it. Attached you will find the screenshot of the zenon help for the variable tagname, as you see it can only be read from the runtime.
    Thank you. I get it!

    But can you explain to me how to correct the error 91?
    I have seen many posts where people use code like

    mguid = MyWorkspace.ActiveDocument.Guid

    without problems

    Maybe I need to make any adjustments in the project?

  10. #10
    Join Date
    30.05.2007
    Location
    Salzburg
    Posts
    879

    Default Re: Edit variable in Editor from VBA

    for doing stuff in the zenon Editor via VBA you have to insert you VBA Code at ZWorkspace. Either you put your code their into "MyWorkspace" or you define a own module within ZWorkspace.

    For VBA Code which should be executed in the zenon Runtime of a project you put the VBA Code into "ZYourProjectName" -> "thisProject"

    VBA of the zenon Editor and zenon Runtime (Project) are seperated.

    regards,
    herbert

Similar Threads

  1. .arx archive edit
    By bastien in forum zenon Supervisor
    Replies: 1
    Last Post: 13th June 2012, 15:06
  2. Replies: 0
    Last Post: 11th March 2010, 15:59
  3. Edit Variable limit (Delay)
    By rloureiro in forum VBA
    Replies: 5
    Last Post: 12th September 2008, 09:25
  4. Replies: 0
    Last Post: 20th August 2007, 17:04

Posting Rules

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