Manipulating Arrays

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
strosfan47
Newbie
Posts: 9
Joined: Tue Feb 15, 2011 2:57 pm

Manipulating Arrays

Post by strosfan47 » Mon Feb 21, 2011 5:01 pm

Hi -- can you do the following with arrays in MacroScheduler 12?

1) Can you assign a NULL value to an item? Or simply populate with a CRLF? Assigning "" doesn't seem to yield the desired behavior.

2) If so, will that muck up the SORT capabilities?

3) Do you have any code that will build up a ListBox from scratch, item by item from an array, sorting and removing any duplicate items? (Here's my code thus far...)

Code: Select all


Separate>prev_selected_list,CRLF,Master_List

    Let>Master_Text=
    Let>c=items_count
    Let>rebuild=1
      Repeat>rebuild
        Let>rebuild_item=Master_List_%rebuild%
        Let>Master_Text=%Master_Text%%rebuild_item%%CRLF%
        Let>rebuild=rebuild+1
      Until>rebuild=c

SetDialogProperty>Dialog1,MSListBox3,Text,Master_Text
Thanks in advance!
-- Bopert in Austin

strosfan47
Newbie
Posts: 9
Joined: Tue Feb 15, 2011 2:57 pm

follow-up question, thank you

Post by strosfan47 » Tue Feb 22, 2011 2:35 pm

Hey Marcus -- just to be clear, there is no expectation to do my heavy lifting when it comes to forming logic re: sorting/removing redundancies as I populate dynamic list boxes from arrays. I was wondering if such code existed, that's all.
(Once I get it figured out, I'll contribute to the community. Thanks.)

On a similar note, I have another question...

When using the below code to create an array from selected items in a list box, is there a handy way to clear out the array so that I can ready it for the next selection? The problem I am having is this: let's say I select five items from the first list, then later select three items, it leaves two items of obsolete "garbage data" in my array.

Code: Select all

// Get the selected items, put results into scr_pad_sel_list
GetDialogProperty>Dialog1,MSListBox2,SelectedItems,scr_pad_sel_list

//separate into array Scratch_Pad_Selected_List
Separate>scr_pad_sel_list,CRLF,Scratch_Pad_Selected_List 
I suppose I could make a loop counting up to the number of items in the array, and blank out each item. But with what? Filling each item with "" or ""%CRLF% won't work. Is there a NULL value I could use?

Any other ideas?

Best! -- Bo
-- Bopert in Austin

strosfan47
Newbie
Posts: 9
Joined: Tue Feb 15, 2011 2:57 pm

sketchy results

Post by strosfan47 » Tue Feb 22, 2011 11:58 pm

PS -- unless you are working with a virgin array or have a handy way to "clean it out", the COMMAND ArrayCount will yield sketchy results. For example, I learned (the hard way) that:

Code: Select all

ArrayCount>Selected_List,y
will often give a different result than:

Code: Select all

Let>y=%Selected_List_count%
FYI...
-- Bopert in Austin

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Feb 23, 2011 8:05 am

If you empty an array element, the array variable names will still exist so ArrayCount and ArraySort will still process them. At present there is no way to "kill" or unassign a variable completely. That is on the wish list.

If you want your own way to sort an array search this forum for BubbleSort.

Once sorted removing duplicates should be a simple process using a loop and comparing each item to the last. But for reasons given in my first point I would create a new array with the results (i.e. if this item NOT equal to last item, put it in a new array) rather than null it out.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts