Blue Eye Logo

Blue Eye Macro

Automation is freedom
It is currently Fri Dec 13, 2019 7:32 am

All times are UTC




Post a reply
Username:
Subject:
Message body:
Enter your message here, it may contain no more than 60000 characters. 

Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :| :mrgreen: :geek: :ugeek:
Font size:
Font colour
Options:
BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON
Disable BBCode
Disable smilies
Do not automatically parse URLs
Please click and drag the 2 correct statements to the right hand side.
Please click and drag the 2 correct statements to the right hand side.
Please select the options below to the correct list to avoid automated registrations.
Statements
2 correct statements
Dogs have 4 legs
Elephants can fly
Chickens can talk
Fish can swim
   

Topic review - How to update values in a collection
Author Message
  Post subject:  How to update values in a collection  Reply with quote
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
Post Posted: Mon Nov 04, 2019 5:51 pm

All times are UTC


Jump to:  


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