Blue Eye Logo

Blue Eye Macro

Automation is freedom
It is currently Wed Nov 20, 2019 1:48 am

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: How to update values in a collection
Thanked: 0 time(s)  Unread post Posted: Mon Nov 04, 2019 5:51 pm 
New User
New User



Joined: Tue Oct 01, 2019 5:44 pm
Posts: 6
Been thanked: 0 time(s)
Has thanked: 1 time(s)
Contribution Points: 116
The following contains a method for updating a numeric collection being used to count the occurrences of generated random numbers between 1 and 10. Adapting the code for other purposes is fairly simple. The core method makes use of a second collection and maintains the original - see function("Update Counter Collection"). The macro updates the collection 1000 times and displays the resulting collection on completion. The code is a complete and runnable macro:
Code:
 
 begin
     // example of how to update a collection of counters with the count of the individual
     // numbers selected by a random number statement
     Function.Execute("Setup Collection")
     Function.Execute("Main Process")
 end

function("Main Process")
     begin
          Variable.Set("Iterations", "1000")
          Begin loop("{Iterations}")
               // get a random number between 1 and 10 to indicate the counter to be updated
               Variable.Set random number("RN", "1", "10")
               // get the current value of the relevant counter & increment it
               Variable.Get from collection("Counter", "{RN}", "CurrentValue")
               Variable.Increment (Math)("CurrentValue")
               Variable.Copy("CurrentValue", "NewValue")
               // update the counter collection at item RN with the incremented current value (NewValue)
               Function.Execute setting 2 variables("Update Counter Collection", "Index", "{RN}", "NewValue", "{NewValue}")
          end
          // Display Counter Collection
          Variable.Set("strText", "Counter Collection Values")
          Variable.Evaluate (Text)("Iterations = {Iterations}", "displayInfo")
          Variable.Append line("strText", "{displayInfo}")
          Variable.Append line("strText", " ")
          Variable.Set("Sum", "0")
          begin loop("{CollectionCount}")
               Macro.Get parent loop iteration("LoopCount")
               Variable.Get from collection("Counter", "{LoopCount}", "CurrentValue")
               Variable.Evaluate (Text)("{LoopCount}. {CurrentValue}", "displayInfo")
               Variable.Append line("strText", "{displayInfo}")
               Variable.Add (Math)("Sum", "{CurrentValue}")
          end
          Variable.Append line("strText", " ")
          Variable.Evaluate (Text)("Total = {Sum}", "displayInfo")
          Variable.Append line("strText", "{displayInfo}")
          Window.Display message box("{strText}", "Yes")
     end
function

function("Update Counter Collection")
     begin
          Variable.Clear collection("Work")
          Variable.Count collection("Counter", "CollectionCount")
          // loop through collection
          begin loop("{CollectionCount}")
               Macro.Get parent loop iteration("LoopCount")
               // update Work collection with new value if iteration = passed index
               if  Variable.Is equal to("LoopCount", "{Index}")
                    begin
                         Variable.Add to collection("Work", "{NewValue}")
                    end
               // just add Counter entry to Work collection if iteration <> passed index
               if  Variable.Is not equal to("LoopCount", "{Index}")
                    begin
                         Variable.Get from collection("Counter", "{LoopCount}", "CurrentValue")
                         Variable.Add to collection("Work", "{CurrentValue}")
                    end
          end
          // copy Work collection back to Counter collection
          Variable.Clear collection("Counter")
          begin loop("{CollectionCount}")
               Macro.Get parent loop iteration("LoopCount")
               Variable.Get from collection("Work", "{LoopCount}", "CurrentValue")
               Variable.Add to collection("Counter", "{CurrentValue}")
          end
     end
function

function("Setup Collection")
     begin
          // Count Collection
          Variable.Add to collection("Counter", "0")
          Variable.Add to collection("Counter", "0")
          Variable.Add to collection("Counter", "0")
          Variable.Add to collection("Counter", "0")
          Variable.Add to collection("Counter", "0")
          Variable.Add to collection("Counter", "0")
          Variable.Add to collection("Counter", "0")
          Variable.Add to collection("Counter", "0")
          Variable.Add to collection("Counter", "0")
          Variable.Add to collection("Counter", "0")
     end
function


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


You cannot post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group