Page 1 of 2 1 2 LastLast
Showing results 1 to 10 of 13

Thread: RGM - VBA - ".Save" / ".Read" - change recipe status

  1. #1

    Default RGM - VBA - ".Save" / ".Read" - change recipe status

    Quote Originally Posted by fels_gro View Post
    - New RGM: How is it possible to change the status of a recipe via VBA? (RGMRecipe.Status and the Dynprop are ReadOnly).
    The status can be changed for a recipe version using the dynproperty:

    Sub chng_status()
    
    Dim myRGMGrps As RGMRecipeGroups
    Dim myGrp As RGMRecipeGroup
    Dim myRec As RGMRecipe
    
    Set myRGMGrps = thisProject.RGMGroups
    If Not myRGMGrps Is Nothing Then
        Set myGrp = myRGMGrps.Item("simul_vars")
        If Not myGrp Is Nothing Then
            'address the recipe with version "2"
            Set myRec = myGrp.RecipeItemVersion("set_0", 2)
            If Not myRec Is Nothing Then
                myRec.DynProperties("Status") = 2
                'after modyfying the status, save the recipe
                myRec.Save
                Debug.Print myRec.Status
            End If
        End If
    End If
    End Sub

    please let us know how you go with this, and if this also works for you

  2. #2

    Default Re: second beta

    Quote Originally Posted by fels_gro View Post
    - New RGM: RGMRecipe.Save (via VBA) does not work!?
    Generally, the method "Save" works for me here.

    The "Save" method permanently saves changes, made to the copy of recipe object handled in VBA.

    Like with the "save" button in the RGM MDI screen, changes are made in a copy of the recipe shown in the screen, but are only saved (locally or on the server) when explicitely saving the changes.


    Sub set_comment()
    Dim saveOK As Boolean
    Dim myRec As RGMRecipe
    Set myRec = thisProject.RGMGroups.Item("Fail7_Intern").RecipeItem("synch_default")
    If Not myRec Is Nothing Then
        Debug.Print myRec.DynProperties("Comment8")
        myRec.DynProperties("Comment8") = "write synchronously - 0 ms timeout (default)"
        Debug.Print myRec.DynProperties("Comment8")
        
    End If
    
    'only the copy in memory is modified, the change has not been saved! Setting the object to nothing, rejects the changes
    Set myRec = Nothing
    Set myRec = thisProject.RGMGroups.Item("Fail7_Intern").RecipeItem("synch_default")
    If Not myRec Is Nothing Then
        Debug.Print myRec.DynProperties("Comment8")
        myRec.DynProperties("Comment8") = "some other comment"
        saveOK = myRec.Save
        'now the change has been saved.
    End If
    
    End Sub

    Please let us know when you are still having issues using "Save", ideally with a short description and a sample project.

  3. #3

    Default Re: second beta

    Quote Originally Posted by fels_gro View Post
    - New RGM: Runtime crashes on RGMRecipe.Read (via VBA)
    Is there something specific that I need to consider when trying to reproduce this?

    The "Read" method in VBA reads the values from the PLC, for the current RGMRecipe Object for which this method is called.

    The result is OK, as long as the values are within the Min / Max limits, and no value has an INVALID bit.

    The "Read" method, like with reading the recipe in the RGM screen, does not automatically save the recipe. This must be done afterwards, when reading is OK.

    Sub readRec2()
    Dim myRecGrp As RGMRecipeGroup
    Dim myRecipe As RGMRecipe
    Dim readOK As Boolean
    Set myRecGrp = thisProject.RGMGroups.Item("Fail7_single")
    If Not myRecGrp Is Nothing Then
        'get the lowest version (90000) (get the highest version with 90001)
        Set myRecipe = myRecGrp.RecipeItemVersion("non_synch", 90000)
        If Not myRecipe Is Nothing Then
            readOK = myRecipe.Read
            If readOK Then myRecipe.Save
        End If
    End If

  4. #4
    fels_gro Gast

    Default Re: second beta

    Hi Clemens,

    thanks for all the information. I think i could found the issue for all the problems.

    Your solution for the initialisation of the RGMRecipe object (that works):
    Dim myRGMGrps As RGMRecipeGroups
    Dim myGrp As RGMRecipeGroup
    Dim myRec As RGMRecipe
     
    Set myRGMGrps = thisProject.RGMGroups
    Set myGrp = myRGMGrps.Item("simul_vars")
    Set myRec = myGrp.RecipeItemVersion("set_0", 2)

    Solution that does not work:
    Dim myRec As RGMRecipe
    
    Set myRec = thisProject.RGMGroups.Item("simul_vars").RecipeItemVersion("set_0", 2)

    chng_status example:
    'Your solution - that works!
    Sub chng_status()
    Dim myRGMGrps As RGMRecipeGroups
    Dim myGrp As RGMRecipeGroup
    Dim myRec As RGMRecipe
     
    Set myRGMGrps = thisProject.RGMGroups
    If Not myRGMGrps Is Nothing Then
        Set myGrp = myRGMGrps.Item("Production")
        If Not myGrp Is Nothing Then
            'address the recipe with version "2"
            Set myRec = myGrp.RecipeItemVersion("Recipe 2", 3)
            If Not myRec Is Nothing Then
                myRec.DynProperties("Status") = 3
                'after modyfying the status, save the recipe
                myRec.Save
                Debug.Print myRec.Status
            End If
        End If
    End If
    End Sub
    
    'Solution that does not work!
    Sub chng_status1()
    Dim myRec As RGMRecipe
     
    Set myRec = thisProject.RGMGroups.Item("Production").RecipeItemVersion("Recipe 2", 3)
    If Not myRec Is Nothing Then
        myRec.DynProperties("Status") = 1
        'after modyfying the status, save the recipe
        myRec.Save
        Debug.Print myRec.Status
    End If
    End Sub

    Any ideas?
    Regards

  5. #5

    Default Re: second beta

    Hi,

    I came to that same conclusion yesterday myself. I dont' know why, and I have yet to receive a feedback from the developer, who is currently out of office.

    When I know more, I will post a feedback here.

    In the meantime, if you discover any other issues, please post them here, so we can take a look.

    Regards,
    Mark

  6. #6

    Default Re: RGM - VBA - ".Save" / ".Read" - change recipe status

    I suspect that this may have something to do with my VBA code, and how I named the objects in each procedure, and used that same names in different procedures, in different ways. I'm not sure whether I have done something illegal in terms of VBA coding, or if this is an issue in zenon.

    This needs further investigation.

  7. #7
    Join Date
    21.05.2014
    Posts
    32

    Default Re: RGM - VBA - ".Save" / ".Read" - change recipe status

    Hallo,

    Is there a appropriate VBA code to save the recipe in runtime similar to "Save Recipe" function in Zenon.

    What I am trying to do is, I change the value of variables of a recipe in runtime and save it and export it as a txt file.

    I was able to do it with the screen type specific function "Save Recipe" (which is in the same screen). But now, I want to give a generate a Popup screen for the confirmation from user to save the recipea and then to save it. I save button in the popup call on a VBA macro, whích as follows

    Recipe.Read
    Recipe.save
    RecipeGroup.save

    But, When I export the file. I can't see the changes made in the recipe in the exported file.

    Could you please help

    Regards,
    Jyo

  8. #8

    Default Re: RGM - VBA - ".Save" / ".Read" - change recipe status

    Hi jyo,

    This will not work this way as the screen and VBA both work with their own instance of the recipe. When you change something in the recipe via in the screen, it is only saved when you save this instance via the screen. When you access the RGM recipe via VBA it retrieves the last saved copy from the database.

    Perhaps you could use the RGM specific functions for the keyboard and create a user defined keyboard screen that is opened when clicking on a specific value in the recipe.

    These functions allow you to save the recipe through the popup keyboard screen.

    Best regards,
    Mark

  9. #9
    Join Date
    21.05.2014
    Posts
    32

    Default Re: RGM - VBA - ".Save" / ".Read" - change recipe status

    Hi Mark,

    I got it about the instances of recipes in runtime and vba. I have a keyboard screen to enter the values. For example, I enter 3 variable values and press save button, which popups a confirmation screen. I changed this confirmation screen to a RecipeGroupManager screen. Sothat, I can use the screen type specific function "Save Recipe". Still, it doesn't work. "Save Recipe" works only when it is in the same screen of the recipe.

    Regards.
    Jyo


    Quote Originally Posted by markclemens View Post
    Hi jyo,

    This will not work this way as the screen and VBA both work with their own instance of the recipe. When you change something in the recipe via in the screen, it is only saved when you save this instance via the screen. When you access the RGM recipe via VBA it retrieves the last saved copy from the database.

    Perhaps you could use the RGM specific functions for the keyboard and create a user defined keyboard screen that is opened when clicking on a specific value in the recipe.

    These functions allow you to save the recipe through the popup keyboard screen.

    Best regards,
    Mark

  10. #10

    Default Re: RGM - VBA - ".Save" / ".Read" - change recipe status

    Hi jyo,

    Also each screen instance uses its own instance of the recipe. You can open the same recipe in two screens, on either the same or different computers and change values, the last recipe screen that calls the save button, has the priority.

    What you could do is use a little trick in the keyboard window. Instead of the real "save" button, create a save button that is a switch for an internal Boolean variable.

    Use this variable to make the real save button in the keyboard screen visible and invisible. Once you click the fake save button, you could make the fake save button invisible and the real save button visible. You could label it differently and add a "no" button, that closes the frame of the keyboard window.

    I hope this information and these suggestions are helpful

    Best regards,
    Mark

Similar Threads

  1. Replies: 1
    Last Post: 11th December 2013, 07:15
  2. "WriteSync" und "PWLevel"
    By rln in forum VBA
    Replies: 4
    Last Post: 28th July 2011, 07:42
  3. how can certain recipe groups be "hidden" in the runtime?
    By markclemens in forum zenon Supervisor
    Replies: 0
    Last Post: 15th February 2010, 05:57
  4. Replies: 2
    Last Post: 9th June 2009, 12:53
  5. Replies: 5
    Last Post: 28th November 2008, 10:49

Posting Rules

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