Showing results 1 to 5 of 5

Thread: Problem with VBA progress bar and RTFunction end sync

  1. #1
    Join Date
    13.02.2019
    Posts
    29

    Default Problem with VBA progress bar and RTFunction end sync

    Hi guys I have a problem with this type of code


    Public Sub ExportAllArchive()
                      
    Dim VarPercentage As Variable 

    Set VarPercentage = thisProject.Variables.Item("VarAuxPercentage")     
    ' VarAuxPercentage is linked to a numeric and is rapresented graphically during the export state '

                      thisProject.RtFunctions.Item("Open_Image_Export_Status").Start
                      ' Open a image with progress bar '
                      
                      VarPercentage.Value = 0
                      thisProject.RtFunctions.Item("ExportArchive0").Start
                     ' Export of an archive from approx 10MB in 5-10second '

                      VarPercentage.Value = 10
                      thisProject.RtFunctions.Item("ExportArchive1").Start
                     ' Export of an archive from approx 10MB in 5-10second '

                      ......

                      VarPercentage.Value = 100
                      thisProject.RtFunctions.Item("ExportArchive10").Start
                     ' Export of an archive from approx 10MB in 5-10second '


                      thisProject.RtFunctions.Item("Funz_Close_Image_Export_Status").Start
                     ' Close a image with progress bar '
                      
    End Sub

    I can't understand why the export is not synchronous with the increase of my variable (percentage of export status)
    How can I write the code so that the percentage variable is incremented at the end of each export function completed?

    With the following code I always have 100 even during the current export

    Thanks!

  2. #2
    Join Date
    13.02.2019
    Posts
    29

    Default Re: Problem with VBA progress bar and RTFunction end sync

    I forgot to mention that I don't use containers to write variable on VBA, 

    but VarAuxPercentage is a variable marked with flag "Permanetly Read Variable"

  3. #3
    Join Date
    25.06.2012
    Posts
    155

    Default Re: Problem with VBA progress bar and RTFunction end sync

    Hello doublem,

    thank you very much for your post.

    Unfortunately, I cannot imagine a solution based on API for what you are trying to achieve as there isn't any API event to react on function closing/end and set the progress bar value accordingly. Nevertheless, why don't you use native zenon scripts and functions to implement your progress bar?

    The ideia is quite simple, I've created 3 scripts where user calls only the "Script 0". Their execution can be easily understand as the figure below shows:



    To play with the project, simply click on the "Start Script" button and compare the progress bar against the evacuated archives folder "\ExportArx" in the runtime.

    Of course, the solution proposed does not test if the archive was successfully exported.

    Please find a sample 8.10 project attached, but I kindly ask you to see it as a guidance only so that I won't take further responsibility for its implementation.

    Let us know if this solution would be fine to you.

    All the best,
    David Cerdeira

    Attached Thumbnails Attached Thumbnails 2019-09-24_11h43_54.png  
    Attached Files Attached Files

  4. #4
    Join Date
    13.02.2019
    Posts
    29

    Default Re: Problem with VBA progress bar and RTFunction end sync

    Thank you!

    If I use Function with "Write Value", instead the assignement of the variable on VBA, all works perfectly!
    I replace VarPercentage.Value = 0 .... 100
    with dedicated function 
    thisProject.RtFunctions.Item("WriteProgress0...100").Start

    Just a question, isn't it possible to know when a function was terminated in vba?

    Could be this a workaround?
    If I use a wait (5000) command at the end of each function, could it be a problem for runtime?


                      VarPercentage.Value = 0
                      thisProject.RtFunctions.Item("ExportArchive0").Start
                      Wait (5000)

                      VarPercentage.Value = 10
                      thisProject.RtFunctions.Item("ExportArchive1").Start
                     Wait (5000)


    Thank you 


  5. #5
    Join Date
    25.06.2012
    Posts
    155

    Default Re: Problem with VBA progress bar and RTFunction end sync

    Hello doublem,

    thank you very much for your feedback.

    1. There is no API event that reacts on functions end so that it is not possible to monitor this sort of actions.

    2. VBA runs in-process with the runtime - to execute code, a context switch is performed which causes zenon to wait for the execution to finish. If the time to execute the VBA macro is too long (for example, by wait, loop instructions or other similar methods), this can result in an unresponsive Runtime (also applicable to the Editor) if the code takes a long time to execute.

    All the best and good luck,
    David Cerdeira

Similar Threads

  1. Problem with VBA and RTFunction
    By doublem in forum VBA
    Replies: 0
    Last Post: 20th September 2019, 14:42
  2. Zenon Time Sync
    By Praveen Kumar Karthikeyan in forum zenon Supervisor
    Replies: 1
    Last Post: 3rd September 2019, 08:38
  3. Replies: 3
    Last Post: 18th October 2012, 00:03
  4. RtFunction - DynProperties - PictSwitch.SubstiVar
    By markus.stetschnig in forum VBA
    Replies: 3
    Last Post: 13th June 2012, 13:02
  5. How to create a rtfunction with vb
    By gozzi in forum VBA
    Replies: 2
    Last Post: 8th March 2011, 11:19

Posting Rules

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